mirror of
https://github.com/nmap/nmap.git
synced 2025-12-14 19:59:02 +00:00
Replace ipOps.hex_to_bin with a simpler implementation.
This commit is contained in:
@@ -9,8 +9,7 @@ local stdnse = require "stdnse"
|
|||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
local type = type
|
local type = type
|
||||||
local table = table
|
local select = select
|
||||||
local string = string
|
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local unittest = require "unittest"
|
local unittest = require "unittest"
|
||||||
@@ -635,8 +634,7 @@ end
|
|||||||
-- Converts a string of hexadecimal digits into the corresponding string of
|
-- Converts a string of hexadecimal digits into the corresponding string of
|
||||||
-- binary digits.
|
-- binary digits.
|
||||||
--
|
--
|
||||||
-- Each hex digit results in four bits. This function is really just a wrapper
|
-- Each hex digit results in four bits.
|
||||||
-- around <code>stdnse.tobinary</code>.
|
|
||||||
-- @param hex String representing a hexadecimal number.
|
-- @param hex String representing a hexadecimal number.
|
||||||
-- @usage
|
-- @usage
|
||||||
-- bin_string = ipOps.hex_to_bin( "F00D" )
|
-- bin_string = ipOps.hex_to_bin( "F00D" )
|
||||||
@@ -649,13 +647,8 @@ hex_to_bin = function( hex )
|
|||||||
return nil, "Error in ipOps.hex_to_bin: Expected string representing a hexadecimal number."
|
return nil, "Error in ipOps.hex_to_bin: Expected string representing a hexadecimal number."
|
||||||
end
|
end
|
||||||
|
|
||||||
local t, mask, binchar = {}, "0000"
|
local d = bin.pack("H", hex)
|
||||||
for hexchar in string.gmatch( hex, "%x" ) do
|
return select(2, bin.unpack("B" .. #d, d))
|
||||||
binchar = stdnse.tobinary( tonumber( hexchar, 16 ) )
|
|
||||||
t[#t+1] = mask:sub( 1, # mask - # binchar ) .. binchar
|
|
||||||
end
|
|
||||||
return table.concat( t )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Ignore the rest if we are not testing.
|
--Ignore the rest if we are not testing.
|
||||||
|
|||||||
Reference in New Issue
Block a user