1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Removed packet.hextobin and packet.bintohex. Both are unnecessary

with the struct (bin) library available:

function hextobin(str) return bin.pack("H", str) end
function bintohex(str) return bin.unpack("H", str) end

Also removed a commented copy that was in the sniffer-detect.nse script.
This commit is contained in:
batrick
2009-05-28 03:59:02 +00:00
parent d337e05f7f
commit 3eba69f9f8
2 changed files with 0 additions and 50 deletions

View File

@@ -580,43 +580,3 @@ function Packet:tcp_lookup_link()
end
return string.format("unknown-%i", self.tcp_opt_mtu)
end
----------------------------------------------------------------------------------------------------------------
-- UTILS
--- Convert a byte string to a hex string.
-- @param str Byte string.
-- @return Hex string.
function bintohex(str)
local b = ""
if not str then -- nil
return ""
end
for c in string.gmatch(str, ".") do
b = string.format('%s%02x',b, string.byte(c))
end
return b
end
--- Convert a hex string to a byte string.
--
-- Only bytes <code>[a-f0-9A-F]</code> from input are interpreted. The rest is
-- ignored. The number of interpreted bytes must be even.
-- @param str Hex string.
-- @return Byte string.
-- @usage
-- hextobin("20 20 20") --> " "
-- hextobin("414243") --> "ABC"
-- hextobin("\\41\\42\\43") --> "ABC"
-- hextobin(" 41 42 43 ") --> "ABC"
function hextobin(str)
return (string.gsub(str, "%X*(%x%x)%X*", function(a)
return string.char(tonumber(a, 16));
end));
end

View File

@@ -24,16 +24,6 @@ hostrule = function(host, port)
nmap.get_interface_link(host.interface) == 'ethernet'
end
--[[
function bintohex(str)
local b = ""
for c in string.gmatch(str, ".") do
b = string.format('%s%02x',b, string.byte(c))
end
return b
end
--]]
callback = function(packetsz, layer2, layer3)
return string.sub(layer2, 0, 12)
end