mirror of
https://github.com/nmap/nmap.git
synced 2026-01-05 22:19:03 +00:00
Debugging changes to jdwp-* scripts, better error output
This commit is contained in:
@@ -46,13 +46,13 @@ action = function(host, port)
|
||||
local status,socket = jdwp.connect(host,port) -- initialize the connection
|
||||
if not status then
|
||||
stdnse.print_debug("error, %s",socket)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- read .class file
|
||||
local filename = stdnse.get_script_args(SCRIPT_NAME .. '.filename')
|
||||
if filename == nil then
|
||||
stdnse.print_debug("This script requires a .class file to inject.")
|
||||
return false
|
||||
return stdnse.format_output(false, "This script requires a .class file to inject.")
|
||||
end
|
||||
local file = io.open(nmap.fetchfile(filename), "rb")
|
||||
local class_bytes = file:read("*all")
|
||||
@@ -60,21 +60,29 @@ action = function(host, port)
|
||||
-- inject the class
|
||||
local injectedClass
|
||||
status,injectedClass = jdwp.injectClass(socket,class_bytes)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Failed to inject class", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Failed to inject class")
|
||||
end
|
||||
-- find injected class method
|
||||
local runMethodID = jdwp.findMethod(socket,injectedClass.id,"run",false)
|
||||
|
||||
|
||||
if runMethodID == nil then
|
||||
stdnse.print_debug("Couldn't find run method.")
|
||||
return false
|
||||
stdnse.print_debug(1, "%s: Couldn't find run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Couldn't find run method.")
|
||||
end
|
||||
|
||||
-- invoke run method
|
||||
local result
|
||||
status, result = jdwp.invokeObjectMethod(socket,0,injectedClass.instance,injectedClass.thread,injectedClass.id,runMethodID,0,nil)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Couldn't invoke run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, result)
|
||||
end
|
||||
-- get the result string
|
||||
local _,_,stringID = bin.unpack(">CL",result)
|
||||
status,result = jdwp.readString(socket,0,stringID)
|
||||
-- parse results
|
||||
return stdnse.format_output(true,result)
|
||||
return stdnse.format_output(status,result)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user