1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-05 22:19:03 +00:00

Remove some more creative ways of building a literal byte

This commit is contained in:
dmiller
2015-03-02 13:47:45 +00:00
parent ea58c6bebb
commit c1b2429efd
5 changed files with 11 additions and 11 deletions

View File

@@ -401,7 +401,7 @@ ASN1Encoder = {
val = math.floor(val/256)
end
if lsb > 127 then -- two's complement collision
valStr = valStr .. bin.pack("H", "00")
valStr = valStr .. "\0"
end
return string.reverse(valStr)

View File

@@ -108,7 +108,7 @@ tagEncoder['table'] = function(self, val)
for _, v in ipairs(val) do
encVal = encVal .. encode(v) -- todo: buffer?
end
local tableType = bin.pack("H", "30")
local tableType = "\x30"
if (val["_snmp"]) then
tableType = bin.pack("H", val["_snmp"])
end

View File

@@ -88,16 +88,16 @@ local function _element_to_bson(key, value)
if type(value) == 'string' then
local cstring = bin.pack("z",value) -- null-terminated string
local length = bin.pack("<i", cstring:len())
local op = bin.pack('H','02')
local op = "\x02"
return true, op .. name .. length .. cstring
elseif type(value) =='table' then
return true, bin.pack('H','02') .. name .. toBson(value)
return true, "\x02" .. name .. toBson(value)
elseif type(value)== 'boolean' then
return true, bin.pack('H','08') + name + bin.pack('H',value and '01' or '00')
return true, "\x08" .. name .. (value and '\x01' or '\0')
elseif type(value) == 'number' then
--return bin.pack('H','10').. name .. bin.pack("<i", value)
--return "\x10" .. name .. bin.pack("<i", value)
-- Use 01 - double for - works better than 10
return true, bin.pack('H','01') .. name .. bin.pack("<d", value)
return true, '\x01' .. name .. bin.pack("<d", value)
end
local _ = ("cannot convert value of type %s to bson"):format(type(value))
@@ -140,7 +140,7 @@ function toBson(dict)
end
dbg("Packet length is %d",length)
--Final pack
return true, bin.pack("I", length) .. elements .. bin.pack('H',"00")
return true, bin.pack("I", length) .. elements .. "\0"
end
-- Reads a null-terminated string. If length is supplied, it is just cut

View File

@@ -1110,7 +1110,7 @@ function spoolss_write_printer(smbstate,printer_handle,data)
local padding_len = 4 - math.fmod(#data,4)
local data_padding = nil
if not (padding_len == 4) then
data_padding = string.rep(bin.pack("H","00"),padding_len)
data_padding = string.rep('\0', padding_len)
end
local arguments = printer_handle .. msrpctypes.marshall_int32(#data)
--.. msrpctypes.marshall_int32(#data)
@@ -1189,7 +1189,7 @@ end
--@return (status,lookup_result) If status is false, lookup_result contains an error string, otherwise it's a lookup response table.
function epmapper_lookup(smbstate,handle)
if handle == nil then -- if it's a first request, send a null handle
handle = bin.pack("H","0000000000000000000000000000000000000000")
handle = string.rep('\0', 20)
end
-- void ept_lookup(
-- [in] handle_t h,

View File

@@ -46,7 +46,7 @@ tagEncoder['table'] = function(self, val)
encVal = encVal .. self:encode(v) -- todo: buffer?
end
local tableType = bin.pack("H", "30")
local tableType = "\x30"
if (val["_snmp"]) then
tableType = bin.pack("H", val["_snmp"])
end