![]() | 1 | initial version |
Hi nwb.
It may be surprising, but the ...
syntax is actually valid Lua code for handling variable arguments!
For example, here is the code from https://www.lua.org/pil/5.2.html :
printResult = ""
function print (...)
for i,v in ipairs(arg) do
printResult = printResult .. tostring(v) .. "\t"
end
printResult = printResult .. "\n"
end
In my example, the code you can copy and paste into the lua console would be:
local function search_google(...)
local fields = {...}
for i, field in ipairs( fields ) do
if (field.name == 'http.host') then
browser_open_url("https://www.google.com/search?q=" .. field.value)
break
end
end
end
register_packet_menu("HTTP/Search host in Google", search_google, "http.host")
![]() | 2 | No.2 Revision |
Hi nwb.
It may be surprising, but the ...
syntax is actually valid Lua code for handling variable arguments!
For example, here is the code from https://www.lua.org/pil/5.2.html :- 5.2 – Variable Number of Arguments:
printResult = ""
function print (...)
for i,v in ipairs(arg) do
printResult = printResult .. tostring(v) .. "\t"
end
printResult = printResult .. "\n"
end
In my example, the code you can copy and paste into the lua console would be:
local function search_google(...)
local fields = {...}
for i, field in ipairs( fields ) do
if (field.name == 'http.host') then
browser_open_url("https://www.google.com/search?q=" .. field.value)
break
end
end
end
register_packet_menu("HTTP/Search host in Google", search_google, "http.host")
![]() | 3 | No.3 Revision |
Hi nwb.
It may be surprising, but the ...
syntax is actually valid Lua code for handling variable arguments!
For example, here is the code from https://www.lua.org/pil/5.2.html - 5.2 – Variable Number of Arguments:
printResult = ""
function print (...)
for i,v in ipairs(arg) do
printResult = printResult .. tostring(v) .. "\t"
end
printResult = printResult .. "\n"
end
In my example, the code you can copy and paste into the lua console would be:
local function search_google(...)
local fields = {...}
for i, field in ipairs( fields ) do
if (field.name == 'http.host') then
browser_open_url("https://www.google.com/search?q=" .. field.value)
break
end
end
end
register_packet_menu("HTTP/Search host in Google", search_google, "http.host")
In your case, if you want to operate on the usb.src
field, you'd likely want to do something similar:
local function usb_src_action(...)
local fields = {...}
for i, field in ipairs( fields ) do
if (field.name == 'usb.src') then
-- Do something special
break
end
end
end
register_packet_menu("USB SRC action", usb_src_action, "usb.src")
For multiple fields, as long as it's a single 'packet', you might choose to loop over the fields and extract both variables, then do your operation. However, at this time, the custom packet menu code does not support operating on multiple Wireshark packets at once.