1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 05:31:31 +00:00

Remove bit library from a few more libs

This commit is contained in:
dmiller
2018-08-28 03:52:55 +00:00
parent 7c3b9b40d2
commit d84ddbe3fd
16 changed files with 51 additions and 67 deletions

View File

@@ -114,7 +114,6 @@
-- scripts -- scripts
-- --
local bit = require "bit"
local coroutine = require "coroutine" local coroutine = require "coroutine"
local io = require "io" local io = require "io"
local ipOps = require "ipOps" local ipOps = require "ipOps"
@@ -248,7 +247,7 @@ RegStorage = {
coroutine.yield(v) coroutine.yield(v)
end end
elseif ( ( host and ( h == host or h == host.ip ) ) and port.number == v.port ) then elseif ( ( host and ( h == host or h == host.ip ) ) and port.number == v.port ) then
if ( not(self.filter.state) or ( v.state == bit.band(self.filter.state, v.state) ) ) then if ( not(self.filter.state) or ( v.state == (self.filter.state & v.state) ) ) then
coroutine.yield(v) coroutine.yield(v)
end end
end end
@@ -395,7 +394,7 @@ Credentials = {
end end
end end
if ( state and State.PARAM == bit.band(state, State.PARAM) ) then if ( state and State.PARAM == (state & State.PARAM) ) then
local creds_global = stdnse.get_script_args('creds.global') local creds_global = stdnse.get_script_args('creds.global')
local creds_service local creds_service
local creds_params local creds_params

View File

@@ -22,7 +22,6 @@
-- --
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local datetime = require "datetime" local datetime = require "datetime"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local math = require "math" local math = require "math"
@@ -453,7 +452,7 @@ DHCP6.Request = {
-- Converts option to a string -- Converts option to a string
-- @return str string containing the class instance as string -- @return str string containing the class instance as string
__tostring = function(self) __tostring = function(self)
local tmp = bit.lshift(self.type, 24) + self.xid local tmp = (self.type << 24) + self.xid
local data = "" local data = ""
for _, opt in ipairs(self.opts) do for _, opt in ipairs(self.opts) do
@@ -488,9 +487,9 @@ DHCP6.Response = {
local resp = DHCP6.Response:new() local resp = DHCP6.Response:new()
local pos, tmp = bin.unpack(">I", data) local pos, tmp = bin.unpack(">I", data)
resp.msgtype = bit.band(tmp, 0xFF000000) resp.msgtype = (tmp & 0xFF000000)
resp.msgtype = bit.rshift(resp.msgtype, 24) resp.msgtype = (resp.msgtype >> 24)
resp.xid = bit.band(tmp, 0x00FFFFFF) resp.xid = (tmp & 0x00FFFFFF)
while( pos < #data ) do while( pos < #data ) do
local opt = {} local opt = {}
pos, opt.type, opt.data = bin.unpack(">SP", data, pos) pos, opt.type, opt.data = bin.unpack(">SP", data, pos)

View File

@@ -31,7 +31,6 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local coroutine = require "coroutine" local coroutine = require "coroutine"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local nmap = require "nmap" local nmap = require "nmap"
@@ -1053,11 +1052,11 @@ local function bit_iter(bits)
local mask = 0x80 local mask = 0x80
while mask > 0 do while mask > 0 do
if bit.band(n, mask) ~= 0 then if (n & mask) ~= 0 then
coroutine.yield((i - 1) * 8 + j) coroutine.yield((i - 1) * 8 + j)
end end
j = j + 1 j = j + 1
mask = bit.rshift(mask, 1) mask = (mask >> 1)
end end
end end
end) end)

View File

@@ -18,7 +18,6 @@
-- @author Patrik Karlsson <patrik@cqure.net> -- @author Patrik Karlsson <patrik@cqure.net>
-- --
local bit = require "bit"
local coroutine = require "coroutine" local coroutine = require "coroutine"
local dns = require "dns" local dns = require "dns"
local ipOps = require "ipOps" local ipOps = require "ipOps"
@@ -214,7 +213,7 @@ SERVICES = {
local result = {} local result = {}
for k, v in pairs(responses) do for k, v in pairs(responses) do
if ( bit.band( code, k ) == k ) then if ( ( code & k ) == k ) then
table.insert(result, v) table.insert(result, v)
end end
end end
@@ -397,17 +396,17 @@ SERVICES = {
local activity = {} local activity = {}
activity['name'] = "Activity" activity['name'] = "Activity"
-- Suspicious activity -- Suspicious activity
if ( bit.band(octet4, 1) == 1) then if ( (octet4 & 1) == 1) then
table.insert(activity, "Suspicious") table.insert(activity, "Suspicious")
end end
-- Harvester -- Harvester
if ( bit.band(octet4, 2) == 2) then if ( (octet4 & 2) == 2) then
table.insert(activity, "Harvester") table.insert(activity, "Harvester")
end end
-- Comment spammer -- Comment spammer
if ( bit.band(octet4, 4) == 4) then if ( (octet4 & 4) == 4) then
table.insert(activity, "Comment spammer") table.insert(activity, "Comment spammer")
end end

View File

@@ -59,7 +59,6 @@
-- x IBM Informix Dynamic Server -- x IBM Informix Dynamic Server
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -404,7 +403,7 @@ DDM = {
-- --
-- @return true if the DRDA is to be chained, false if it's the last one -- @return true if the DRDA is to be chained, false if it's the last one
isChained = function( self ) isChained = function( self )
if ( bit.band( self.Format, DDM.Formats.CHAINED ) == DDM.Formats.CHAINED ) then if ( (self.Format & DDM.Formats.CHAINED) == DDM.Formats.CHAINED ) then
return true return true
end end
return false return false
@@ -415,9 +414,9 @@ DDM = {
-- @param chained boolean true if more DRDA's are following -- @param chained boolean true if more DRDA's are following
setChained = function( self, chained ) setChained = function( self, chained )
if ( self:isChained() ) then if ( self:isChained() ) then
self.Format = bit.bxor( self.Format, self.Formats.CHAINED ) self.Format = ( self.Format ~ self.Formats.CHAINED )
else else
self.Format = bit.bor( self.Format, self.Formats.CHAINED ) self.Format = ( self.Format | self.Formats.CHAINED )
end end
end, end,

View File

@@ -113,7 +113,6 @@
local base64 = require "base64" local base64 = require "base64"
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local comm = require "comm" local comm = require "comm"
local coroutine = require "coroutine" local coroutine = require "coroutine"
local nmap = require "nmap" local nmap = require "nmap"
@@ -1375,8 +1374,8 @@ function generic_request(host, port, method, path, options)
return return
end end
local is_unicode = (bit.band(flags_received, 0x00000001) == 0x00000001) -- 0x00000001 UNICODE Flag local is_unicode = ((flags_received & 0x00000001) == 0x00000001) -- 0x00000001 UNICODE Flag
local is_extended = (bit.band(flags_received, 0x00080000) == 0x00080000) -- 0x00080000 Extended Security Flag local is_extended = ((flags_received & 0x00080000) == 0x00080000) -- 0x00080000 Extended Security Flag
local type_3_flags = 0xa2888206 -- flags 56, 128, Version, Target Info, Extended Security, Always Sign, NTLM Key, OEM local type_3_flags = 0xa2888206 -- flags 56, 128, Version, Target Info, Extended Security, Always Sign, NTLM Key, OEM
local lanman, ntlm local lanman, ntlm

View File

@@ -6,7 +6,6 @@
-- --
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local math = require "math" local math = require "math"
local nmap = require "nmap" local nmap = require "nmap"
local os = require "os" local os = require "os"
@@ -74,22 +73,22 @@ IAX2 = {
parse = function(data) parse = function(data)
local header = IAX2.Header:new() local header = IAX2.Header:new()
local pos, frame_type = bin.unpack("C", data) local pos, frame_type = bin.unpack("C", data)
if ( bit.band(frame_type, 0x80) == 0 ) then if ( (frame_type & 0x80) == 0 ) then
print("frame_type", stdnse.tohex(frame_type)) print("frame_type", stdnse.tohex(frame_type))
stdnse.debug2("Frametype not supported") stdnse.debug2("Frametype not supported")
return return
end end
header.type = IAX2.PacketType.FULL header.type = IAX2.PacketType.FULL
pos, header.src_call = bin.unpack(">S", data) pos, header.src_call = bin.unpack(">S", data)
header.src_call = bit.band(header.src_call, 0x7FFF) header.src_call = (header.src_call & 0x7FFF)
local retrans local retrans
pos, retrans = bin.unpack("C", data, pos) pos, retrans = bin.unpack("C", data, pos)
if ( bit.band(retrans, 0x80) == 8 ) then if ( (retrans & 0x80) == 8 ) then
header.retrans = true header.retrans = true
end end
pos, header.dst_call = bin.unpack(">S", data, pos - 1) pos, header.dst_call = bin.unpack(">S", data, pos - 1)
header.dst_call = bit.band(header.dst_call, 0x7FFF) header.dst_call = (header.dst_call & 0x7FFF)
pos, header.timestamp, header.oseqno, pos, header.timestamp, header.oseqno,
header.iseqno, header.frametype, header.subclass = bin.unpack(">ICCCC", data, pos) header.iseqno, header.frametype, header.subclass = bin.unpack(">ICCCC", data, pos)

View File

@@ -18,7 +18,6 @@
----------------------------------------------------------------------- -----------------------------------------------------------------------
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local msrpc = require "msrpc" local msrpc = require "msrpc"
local msrpctypes = require "msrpctypes" local msrpctypes = require "msrpctypes"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -536,7 +535,7 @@ function get_performance_data(host, objects)
pos = object_start + object_type['DefinitionLength'] pos = object_start + object_type['DefinitionLength']
-- Check if we have any instances (sometimes we don't -- if we don't, the value returned is a negative) -- Check if we have any instances (sometimes we don't -- if we don't, the value returned is a negative)
if(bit.band(object_type['NumInstances'], 0x80000000) == 0) then if (object_type['NumInstances'] & 0x80000000) == 0 then
-- Parse the object instances and counters -- Parse the object instances and counters
for j = 1, object_type['NumInstances'], 1 do for j = 1, object_type['NumInstances'], 1 do
local instance_start = pos local instance_start = pos

View File

@@ -104,7 +104,6 @@
-- * GUIDs are stored as tables of values; however, I might change this to a string representation at some point -- * GUIDs are stored as tables of values; however, I might change this to a string representation at some point
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local os = require "os" local os = require "os"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string" local string = require "string"
@@ -1294,7 +1293,7 @@ local function marshall_Enum32(val, table)
local i local i
for i = 1, #vals, 1 do for i = 1, #vals, 1 do
result = bit.bor(result, table[vals[i]]) result = result | table[vals[i]]
end end
result = marshall_int32(result) result = marshall_int32(result)
@@ -1380,7 +1379,7 @@ local function marshall_Enum8(val, table, pad)
local i local i
for i = 1, #vals, 1 do for i = 1, #vals, 1 do
result = bit.bor(result, table[vals[i]]) result = result | table[vals[i]]
end end
result = marshall_int8(result, pad) result = marshall_int8(result, pad)
@@ -1407,7 +1406,7 @@ local function unmarshall_Enum32_array(data, pos, table)
pos, val = unmarshall_int32(data, pos) pos, val = unmarshall_int32(data, pos)
for i, v in pairs(table) do for i, v in pairs(table) do
if(bit.band(v, val) ~= 0) then if (v & val) ~= 0 then
array[#array + 1] = i array[#array + 1] = i
end end
end end
@@ -1552,7 +1551,7 @@ function unmarshall_dom_sid2(data, pos)
if(sid['authority_low'] == nil) then if(sid['authority_low'] == nil) then
stdnse.debug1("MSRPC: ERROR: Ran off the end of a packet in unmarshall_dom_sid2(). Please report!") stdnse.debug1("MSRPC: ERROR: Ran off the end of a packet in unmarshall_dom_sid2(). Please report!")
end end
sid['authority'] = bit.bor(bit.lshift(sid['authority_high'], 32), sid['authority_low']) sid['authority'] = (sid['authority_high'] << 32) | sid['authority_low']
sid['sub_auths'] = {} sid['sub_auths'] = {}
for i = 1, sid['num_auths'], 1 do for i = 1, sid['num_auths'], 1 do
@@ -1614,8 +1613,8 @@ function marshall_dom_sid2(sid)
pos = pos_next + 1 pos = pos_next + 1
pos_next = string.find(sid, "-", pos) pos_next = string.find(sid, "-", pos)
sid_array['authority_high'] = bit.rshift(string.sub(sid, pos, pos_next - 1), 32) sid_array['authority_high'] = string.sub(sid, pos, pos_next - 1) >> 32
sid_array['authority_low'] = bit.band(string.sub(sid, pos, pos_next - 1), 0xFFFFFFFF) sid_array['authority_low'] = string.sub(sid, pos, pos_next - 1) & 0xFFFFFFFF
sid_array['sub_auths'] = {} sid_array['sub_auths'] = {}
i = 1 i = 1

View File

@@ -104,7 +104,6 @@
-- will not be stored for use by other ms-sql-* scripts. -- will not be stored for use by other ms-sql-* scripts.
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local math = require "math" local math = require "math"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
@@ -2280,7 +2279,7 @@ TDSStream = {
-- Check the status flags in the TDS packet to see if the message is -- Check the status flags in the TDS packet to see if the message is
-- continued in another TDS packet. -- continued in another TDS packet.
tdsPacketAvailable = (bit.band( messageStatus, TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) ~= tdsPacketAvailable = (( messageStatus & TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) ~=
TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage)
end end
@@ -3111,10 +3110,10 @@ Auth = {
local xormask = 0x5a5a local xormask = 0x5a5a
return password:gsub(".", function(i) return password:gsub(".", function(i)
local c = bit.bxor( string.byte( i ), xormask ) local c = string.byte( i ) ~ xormask
local m1= bit.band( bit.rshift( c, 4 ), 0x0F0F ) local m1= ( c >> 4 ) & 0x0F0F
local m2= bit.band( bit.lshift( c, 4 ), 0xF0F0 ) local m2= ( c << 4 ) & 0xF0F0
return bin.pack("<S", bit.bor( m1, m2 ) ) return bin.pack("<S", m1 | m2 )
end) end)
end, end,

View File

@@ -8,7 +8,6 @@
-- @author Patrik Karlsson <patrik@cqure.net> -- @author Patrik Karlsson <patrik@cqure.net>
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string" local string = require "string"
@@ -93,8 +92,8 @@ local function decodeHeader( data, pos )
local pos, tmp = pos or 1, 0 local pos, tmp = pos or 1, 0
pos, tmp = bin.unpack( "I", data, pos ) pos, tmp = bin.unpack( "I", data, pos )
response.len = bit.band( tmp,255 ) response.len = ( tmp & 255 )
response.number = bit.rshift( tmp, 24 ) response.number = ( tmp >> 24 )
return pos, response return pos, response
end end
@@ -193,7 +192,7 @@ local function createLoginHash(pass, salt)
_, b1 = bin.unpack( "C", hash_stage1, pos ) _, b1 = bin.unpack( "C", hash_stage1, pos )
_, b2 = bin.unpack( "C", hash_stage3, pos ) _, b2 = bin.unpack( "C", hash_stage3, pos )
reply[pos] = string.char( bit.bxor( b2, b1 ) ) reply[pos] = string.char( b2 ~ b1 )
end end
return table.concat(reply) return table.concat(reply)
@@ -255,7 +254,7 @@ function loginRequest( socket, params, username, password, salt )
hash hash
) )
local tmp = packet:len() + bit.lshift( packetno, 24 ) local tmp = packet:len() + ( packetno << 24 )
packet = bin.pack( "I", tmp ) .. packet packet = bin.pack( "I", tmp ) .. packet

View File

@@ -51,7 +51,6 @@
-- Created 24/04/2011 - v0.1 - created by Patrik Karlsson <patrik@cqure.net> -- Created 24/04/2011 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
@@ -473,7 +472,7 @@ ResponseParser = {
"RelDN", "DN" } "RelDN", "DN" }
local bits = 1 local bits = 1
for _, field in ipairs(fields) do for _, field in ipairs(fields) do
self[field] = ( bit.band(self.val, bits) == bits ) self[field] = ((self.val & bits) == bits)
bits = bits * 2 bits = bits * 2
end end
end end

View File

@@ -5,7 +5,6 @@
-- --
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
local os = require "os" local os = require "os"
@@ -52,8 +51,8 @@ NDMP = {
parse = function(data) parse = function(data)
local fh = NDMP.FragmentHeader:new() local fh = NDMP.FragmentHeader:new()
local _, tmp = bin.unpack(">I", data) local _, tmp = bin.unpack(">I", data)
fh.length = bit.band(tmp, 0x7fffffff) fh.length = (tmp & 0x7fffffff)
fh.last= bit.rshift(tmp, 31) fh.last= (tmp >> 31)
return fh return fh
end, end,

View File

@@ -22,7 +22,6 @@
-- --
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local math = require "math" local math = require "math"
local nmap = require "nmap" local nmap = require "nmap"
local packet = require "packet" local packet = require "packet"
@@ -396,15 +395,15 @@ PPPoE = {
local pos, vertyp local pos, vertyp
local header = PPPoE.Header:new() local header = PPPoE.Header:new()
pos, vertyp, header.code, header.session, header.length = bin.unpack(">CCSS", data) pos, vertyp, header.code, header.session, header.length = bin.unpack(">CCSS", data)
header.version = bit.rshift(vertyp,4) header.version = (vertyp >> 4)
header.type = bit.band(vertyp, 0x0F) header.type = (vertyp & 0x0F)
return header return header
end, end,
-- Converts the instance to string -- Converts the instance to string
-- @return string containing the raw config option -- @return string containing the raw config option
__tostring = function(self) __tostring = function(self)
local vertype = bit.lshift(self.version, 4) + self.type local vertype = (self.version << 4) + self.type
return bin.pack(">CCSS", vertype, self.code, self.session, self.length) return bin.pack(">CCSS", vertype, self.code, self.session, self.length)
end, end,

View File

@@ -43,7 +43,6 @@
-- Fixed more documentation - v0.2 Martin Holst Swende <martin@swende.se> -- Fixed more documentation - v0.2 Martin Holst Swende <martin@swende.se>
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string" local string = require "string"
@@ -419,7 +418,7 @@ JavaClass = {
isExternalizable = function(self) isExternalizable = function(self)
if self._binaryFlags == nil then return false end if self._binaryFlags == nil then return false end
return bit.band(self._binaryflags, RMIUtils.SC_EXTERNALIZABLE) return (self._binaryflags & RMIUtils.SC_EXTERNALIZABLE)
end, end,
addField = function( self, field ) addField = function( self, field )
@@ -1510,19 +1509,19 @@ RMIUtils = {
flagsToString = function(flags) flagsToString = function(flags)
local retval = '' local retval = ''
if ( bit.band(flags, RMIUtils.SC_WRITE_METHOD) ~= 0) then if ( (flags & RMIUtils.SC_WRITE_METHOD) ~= 0) then
retval = retval .. " WRITE_METHOD" retval = retval .. " WRITE_METHOD"
end end
if ( bit.band(flags, RMIUtils.SC_BLOCK_DATA) ~= 0) then if ( (flags & RMIUtils.SC_BLOCK_DATA) ~= 0) then
retval = retval .. " BLOCK_DATA" retval = retval .. " BLOCK_DATA"
end end
if ( bit.band(flags, RMIUtils.SC_EXTERNALIZABLE) ~= 0) then if ( (flags & RMIUtils.SC_EXTERNALIZABLE) ~= 0) then
retval = retval .. " EXTERNALIZABLE" retval = retval .. " EXTERNALIZABLE"
end end
if ( bit.band(flags, RMIUtils.SC_SERIALIZABLE) ~= 0) then if ( (flags & RMIUtils.SC_SERIALIZABLE) ~= 0) then
retval = retval .. " SC_SERIALIZABLE" retval = retval .. " SC_SERIALIZABLE"
end end
if ( bit.band(flags, RMIUtils.SC_ENUM) ~= 0) then if ( (flags & RMIUtils.SC_ENUM) ~= 0) then
retval = retval .. " SC_ENUM" retval = retval .. " SC_ENUM"
end end
return retval return retval

View File

@@ -42,7 +42,6 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local smbauth = require "smbauth" local smbauth = require "smbauth"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string" local string = require "string"
@@ -206,8 +205,8 @@ if HAVE_SSL then
error("NTLM parseChallenge expected message type: 0x02") error("NTLM parseChallenge expected message type: 0x02")
end end
self.is_extended = ( bit.band(self.flags, NTLM_NegotiateExtendedSecurity) == NTLM_NegotiateExtendedSecurity ) self.is_extended = ( (self.flags & NTLM_NegotiateExtendedSecurity) == NTLM_NegotiateExtendedSecurity )
local is_unicode = ( bit.band(self.flags, NTLM_NegotiateUnicode) == NTLM_NegotiateUnicode ) local is_unicode = ( (self.flags & NTLM_NegotiateUnicode) == NTLM_NegotiateUnicode )
self.workstation = "NMAP-HOST" self.workstation = "NMAP-HOST"
self.domain = self.username:match("^(.-)\\(.*)$") or "DOMAIN" self.domain = self.username:match("^(.-)\\(.*)$") or "DOMAIN"