mirror of
https://github.com/nmap/nmap.git
synced 2026-02-07 05:56:34 +00:00
Remove bin.lua packings from some more libs
This commit is contained in:
@@ -53,7 +53,6 @@
|
||||
-- Created 08/07/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
|
||||
--
|
||||
|
||||
local bin = require "bin"
|
||||
local match = require "match"
|
||||
local nmap = require "nmap"
|
||||
local stdnse = require "stdnse"
|
||||
@@ -112,7 +111,7 @@ Packet.GIOP = {
|
||||
--
|
||||
-- @return string containing the instance data
|
||||
__tostring = function( self )
|
||||
return bin.pack("<ASCC>IA", self.magic, self.version, self.byte_order, self.type, self.size, self.data )
|
||||
return self.magic .. string.pack("<I2BB>I4", self.version, self.byte_order, self.type, self.size) .. self.data
|
||||
end,
|
||||
|
||||
--- Sets the packet version
|
||||
@@ -131,10 +130,10 @@ Packet.GIOP = {
|
||||
|
||||
if ( not(status) ) then return false, "Failed to read Packet.GIOP" end
|
||||
|
||||
pos, self.magic, self.version, self.byte_order,
|
||||
self.type = bin.unpack("<A4SCC", data )
|
||||
self.magic, self.version, self.byte_order,
|
||||
self.type, pos = string.unpack("<c4I2BB", data )
|
||||
|
||||
pos, self.size = bin.unpack( ( self.byte_order == 0 and ">" or "<") .. "I", data, pos )
|
||||
self.size, pos = string.unpack( ( self.byte_order == 0 and ">" or "<") .. "I4", data, pos )
|
||||
|
||||
status, data = socket:receive_buf(match.numbytes(self.size), true)
|
||||
if ( not(status) ) then return false, "Failed to read Packet.GIOP" end
|
||||
@@ -167,9 +166,9 @@ ServiceContext = {
|
||||
-- @return string containing the instance data
|
||||
__tostring = function( self )
|
||||
if ( self.pad ) then
|
||||
return bin.pack(">IIAS", self.id, #self.data, self.data, self.pad)
|
||||
return string.pack(">I4s4I2", self.id, self.data, self.pad)
|
||||
else
|
||||
return bin.pack(">IIA", self.id, #self.data, self.data)
|
||||
return string.pack(">I4s4", self.id, self.data)
|
||||
end
|
||||
end,
|
||||
}
|
||||
@@ -235,10 +234,10 @@ Packet.GIOP.reply = {
|
||||
if( not(status) ) then return false, err end
|
||||
|
||||
if ( self.GIOP.version == Constants.VERSION_1_2 ) then
|
||||
pos, self.request_id, self.reply_status = bin.unpack(bo .. "II", self.GIOP.data, pos )
|
||||
pos, tmp = bin.unpack( bo .. "I", self.GIOP.data, pos )
|
||||
self.request_id, self.reply_status, pos = string.unpack(bo .. "I4I4", self.GIOP.data, pos )
|
||||
tmp, pos = string.unpack( bo .. "I4", self.GIOP.data, pos )
|
||||
elseif ( self.GIOP.version == Constants.VERSION_1_0 ) then
|
||||
pos, tmp = bin.unpack( bo .. "I", self.GIOP.data )
|
||||
tmp, pos = string.unpack( bo .. "I4", self.GIOP.data )
|
||||
else
|
||||
local err = ("Unknown GIOP version: %s"):format(self.GIOP.version)
|
||||
stdnse.debug2("recv: %s", err)
|
||||
@@ -246,17 +245,18 @@ Packet.GIOP.reply = {
|
||||
end
|
||||
|
||||
for i=1, tmp do
|
||||
local ctx_id, ctx_len, ctx_data
|
||||
pos, ctx_id, ctx_len = bin.unpack( bo .. "II", self.GIOP.data, pos )
|
||||
pos, ctx_data = bin.unpack("A" .. ctx_len, self.GIOP.data, pos )
|
||||
local ctx_id, ctx_data
|
||||
ctx_id, ctx_data, pos = string.unpack( bo .. "I4s4", self.GIOP.data, pos )
|
||||
if ( i ~= tmp ) then pos = pos + 2 end
|
||||
table.insert( self.sc, ServiceContext:new( ctx_id, ctx_data ) )
|
||||
end
|
||||
|
||||
if ( self.GIOP.version == Constants.VERSION_1_0 ) then
|
||||
pos, self.request_id, self.reply_status, self.stub_data = bin.unpack( bo .. "IIA" .. ( #self.GIOP.data - pos - 8 ), self.GIOP.data, pos )
|
||||
self.request_id, self.reply_status, self.stub_data, pos = string.unpack( bo .. "I4I4c" .. ( #self.GIOP.data - pos - 8 ), self.GIOP.data, pos )
|
||||
elseif ( pos < #self.GIOP.data ) then
|
||||
pos, self.data = bin.unpack("A" .. (#self.GIOP.data - pos), self.GIOP.data, pos )
|
||||
-- TODO: Is this off-by-one? Unpacks (#data - pos) bytes, but there are (#data - pos + 1) bytes available.
|
||||
-- If so, can replace with: self.data = self.GIOP.data:sub(pos)
|
||||
self.data, pos = string.unpack("c" .. (#self.GIOP.data - pos), self.GIOP.data, pos )
|
||||
end
|
||||
|
||||
return true
|
||||
@@ -299,17 +299,17 @@ Packet.GIOP.get = {
|
||||
--
|
||||
-- @return string containing the packet data
|
||||
__tostring = function( self )
|
||||
local data = bin.pack(">I", #self.sc)
|
||||
local pad = 0
|
||||
local data = { string.pack(">I4", #self.sc) }
|
||||
|
||||
for i=1, #self.sc do
|
||||
data = data .. tostring( self.sc[i])
|
||||
data[#data+1] = tostring( self.sc[i])
|
||||
end
|
||||
|
||||
data = data .. bin.pack( ">ICCCCIIIAIA", self.id, self.resp_expected, pad, pad, pad,
|
||||
self.key_length, self.key, #self.op, self.op, self.princ_len, self.data )
|
||||
data[#data+1] = string.pack( ">I4BxxxI4I4s4I4", self.id, self.resp_expected,
|
||||
self.key_length, self.key, self.op, self.princ_len)
|
||||
data[#data+1] = self.data
|
||||
|
||||
return tostring( Packet.GIOP:new( 0, data ) )
|
||||
return tostring( Packet.GIOP:new( 0, table.concat(data) ) )
|
||||
end,
|
||||
|
||||
}
|
||||
@@ -348,18 +348,19 @@ Packet.GIOP._is_a =
|
||||
-- @return string containing the packet data
|
||||
__tostring = function( self )
|
||||
local TYPE_ID = "IDL:omg.org/CosNaming/NamingContextExt:1.0\0"
|
||||
local RESERVED = 0
|
||||
local UNKNOWN, UNKNOWN2, UNKNOWN3 = 2, 1, 0
|
||||
local data = bin.pack(">ICCCCSSIAIASI", self.id, self.flags, RESERVED, RESERVED, RESERVED, self.target_addr,
|
||||
UNKNOWN, #self.key_addr, self.key_addr, #self.op, self.op, UNKNOWN2, #self.sc )
|
||||
local data = {
|
||||
string.pack(">I4BxxxI2I2s4s4I2I4", self.id, self.flags, self.target_addr,
|
||||
UNKNOWN, self.key_addr, self.op, UNKNOWN2, #self.sc )
|
||||
}
|
||||
|
||||
for i=1, #self.sc do
|
||||
data = data .. tostring( self.sc[i])
|
||||
data[#data+1] = tostring( self.sc[i])
|
||||
end
|
||||
|
||||
data = data .. bin.pack(">IA", #TYPE_ID, TYPE_ID)
|
||||
data[#data+1] = string.pack(">s4", TYPE_ID)
|
||||
|
||||
local packet = Packet.GIOP:new( 0, data )
|
||||
local packet = Packet.GIOP:new( 0, table.concat(data))
|
||||
packet:setVersion( Constants.VERSION_1_2 )
|
||||
|
||||
return tostring( packet )
|
||||
@@ -401,19 +402,20 @@ Packet.GIOP.list =
|
||||
--
|
||||
-- @return string containing the packet data
|
||||
__tostring = function( self )
|
||||
local RESERVED = 0
|
||||
local UNKNOWN, UNKNOWN2, UNKNOWN3 = 2, 1, 6
|
||||
|
||||
local data = bin.pack(">ICCCCSSIAIACCCI", self.id, self.flags, RESERVED, RESERVED,
|
||||
RESERVED, self.target_addr, UNKNOWN, #self.key_addr, self.key_addr,
|
||||
#self.op, self.op, RESERVED, RESERVED, UNKNOWN2, #self.sc )
|
||||
local data = {
|
||||
string.pack(">I4BxxxI2I2s4s4xxCI", self.id, self.flags,
|
||||
self.target_addr, UNKNOWN, self.key_addr,
|
||||
self.op, UNKNOWN2, #self.sc )
|
||||
}
|
||||
|
||||
for i=1, #self.sc do
|
||||
data = data .. tostring( self.sc[i])
|
||||
data[#data+1] = tostring( self.sc[i])
|
||||
end
|
||||
|
||||
data = data .. bin.pack(">II", UNKNOWN3, self.how_many )
|
||||
local packet = Packet.GIOP:new( 0, data )
|
||||
data[#data+1] = string.pack(">I4I4", UNKNOWN3, self.how_many )
|
||||
local packet = Packet.GIOP:new( 0, table.concat(data))
|
||||
packet:setVersion( Constants.VERSION_1_2 )
|
||||
|
||||
return tostring( packet )
|
||||
@@ -432,17 +434,15 @@ MessageDecoder = {
|
||||
-- @return table containing <code>ip</code> and <code>ctx</code>
|
||||
["get"] = function( packet )
|
||||
local bo = ( packet.GIOP.byte_order == 0 and ">" or "<")
|
||||
local pos, len = bin.unpack(bo .. "I", packet.stub_data)
|
||||
local len, pos = string.unpack(bo .. "I4", packet.stub_data)
|
||||
local ip, ctx
|
||||
|
||||
pos = pos + len + 16
|
||||
|
||||
pos, len = bin.unpack(bo .. "I", packet.stub_data, pos)
|
||||
pos, ip = bin.unpack( bo .. "A" .. len, packet.stub_data, pos)
|
||||
ip, pos = string.unpack(bo .. "s4", packet.stub_data, pos)
|
||||
|
||||
pos = pos + 3
|
||||
pos, len = bin.unpack(bo .. "I", packet.stub_data, pos)
|
||||
pos, ctx = bin.unpack( bo .. "A" .. len, packet.stub_data, pos)
|
||||
ctx, pos = string.unpack(bo .. "s4", packet.stub_data, pos)
|
||||
|
||||
return true, { ip = ip, ctx = ctx}
|
||||
end,
|
||||
@@ -465,7 +465,7 @@ MessageDecoder = {
|
||||
-- <code>enum</code> or error message if status is false
|
||||
["list"] = function( packet )
|
||||
local bo = ( packet.GIOP.byte_order == 0 and ">" or "<")
|
||||
local pos, seq_len = bin.unpack( bo .. "I", packet.data, 7)
|
||||
local seq_len, pos = string.unpack( bo .. "I4", packet.data, 7)
|
||||
local objs = {}
|
||||
|
||||
for i=1, seq_len do
|
||||
@@ -473,11 +473,11 @@ MessageDecoder = {
|
||||
local len, name
|
||||
local obj = {}
|
||||
|
||||
pos, seq_len_of_bind_name = bin.unpack( bo .. "I", packet.data, pos)
|
||||
seq_len_of_bind_name, pos = string.unpack( bo .. "I4", packet.data, pos)
|
||||
if ( seq_len_of_bind_name ~= 1 ) then return false, "Sequence length of Binding_binding_name was greater than 1" end
|
||||
|
||||
pos, len = bin.unpack( bo .. "I", packet.data, pos )
|
||||
pos, obj.id = bin.unpack( "A" .. len - 1, packet.data, pos )
|
||||
len, pos = string.unpack( bo .. "I4", packet.data, pos )
|
||||
obj.id, pos = string.unpack( "c" .. len - 1, packet.data, pos )
|
||||
|
||||
-- Account for terminating zero
|
||||
pos = pos + 1
|
||||
@@ -486,11 +486,11 @@ MessageDecoder = {
|
||||
pos = pos + ( ( len % 4 > 0 ) and ( 4 - ( len % 4 ) ) or 0 )
|
||||
pos = pos + 3
|
||||
|
||||
pos, obj.kind = bin.unpack("C", packet.data, pos)
|
||||
obj.kind, pos = string.unpack("B", packet.data, pos)
|
||||
|
||||
-- Account for undecoded data
|
||||
pos = pos + 4
|
||||
pos, obj.enum = bin.unpack( bo .. "I", packet.data, pos )
|
||||
obj.enum, pos = string.unpack( bo .. "I4", packet.data, pos )
|
||||
table.insert( objs, obj )
|
||||
end
|
||||
|
||||
@@ -556,7 +556,7 @@ Helper = {
|
||||
end,
|
||||
|
||||
GetNamingContext = function( self )
|
||||
local packet = Packet.GIOP.get:new( 5, 0x494e4954, bin.pack(">IA", #Constants.NAMESERVICE, Constants.NAMESERVICE) )
|
||||
local packet = Packet.GIOP.get:new( 5, 0x494e4954, string.pack(">s4", Constants.NAMESERVICE) )
|
||||
local status, ctx, lhost, pos, len, bo, tmp
|
||||
|
||||
packet:addServiceContext( 17, "\0\x02", 0)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local bin = require "bin"
|
||||
local datetime = require "datetime"
|
||||
local http = require "http"
|
||||
local nmap = require "nmap"
|
||||
local stdnse = require "stdnse"
|
||||
local string = require "string"
|
||||
local tab = require "tab"
|
||||
local table = require "table"
|
||||
_ENV = stdnse.module("ipp", stdnse.seeall)
|
||||
@@ -79,7 +79,7 @@ IPP = {
|
||||
parse = function(data, pos)
|
||||
local attrib = IPP.Attribute:new()
|
||||
local val
|
||||
pos, attrib.tag, attrib.name, val = bin.unpack(">CPP", data, pos)
|
||||
attrib.tag, attrib.name, val, pos = string.unpack(">Bs2s2", data, pos)
|
||||
-- print(attrib.name, stdnse.tohex(val))
|
||||
attrib.value = {}
|
||||
table.insert(attrib.value, { tag = attrib.tag, val = val })
|
||||
@@ -91,9 +91,9 @@ IPP = {
|
||||
break
|
||||
end
|
||||
|
||||
pos, tag, name_len = bin.unpack(">CS", data, pos)
|
||||
tag, name_len, pos = string.unpack(">BI2", data, pos)
|
||||
if ( name_len == 0 ) then
|
||||
pos, val = bin.unpack(">P", data, pos)
|
||||
val, pos = string.unpack(">s2", data, pos)
|
||||
table.insert(attrib.value, { tag = tag, val = val })
|
||||
else
|
||||
pos = pos - 3
|
||||
@@ -103,9 +103,9 @@ IPP = {
|
||||
-- do minimal decoding
|
||||
for i=1, #attrib.value do
|
||||
if ( attrib.value[i].tag == IPP.Attribute.IPP_TAG_INTEGER ) then
|
||||
attrib.value[i].val = select(2, bin.unpack(">I", attrib.value[i].val))
|
||||
attrib.value[i].val = string.unpack(">I4", attrib.value[i].val)
|
||||
elseif ( attrib.value[i].tag == IPP.Attribute.IPP_TAG_ENUM ) then
|
||||
attrib.value[i].val = select(2, bin.unpack(">I", attrib.value[i].val))
|
||||
attrib.value[i].val = string.unpack(">I4", attrib.value[i].val)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,13 +119,13 @@ IPP = {
|
||||
|
||||
__tostring = function(self)
|
||||
if ( "string" == type(self.value) ) then
|
||||
return bin.pack(">CSASA", self.tag, #self.name, self.name, #self.value, self.value)
|
||||
return string.pack(">Bs2s2", self.tag, self.name, self.value)
|
||||
else
|
||||
local data = bin.pack(">CSASA", self.tag, #self.name, self.name, #self.value[1].val, self.value[1].val)
|
||||
local data = {string.pack(">Bs2s2", self.tag, self.name, self.value[1].val)}
|
||||
for i=2, #self.value do
|
||||
data = data .. bin.pack(">CSP", self.value[i].tag, 0, self.value[i].val)
|
||||
data[#data+1] = string.pack(">BI2s2", self.value[i].tag, 0, self.value[i].val)
|
||||
end
|
||||
return data
|
||||
return table.concat(data)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,12 +176,12 @@ IPP = {
|
||||
end,
|
||||
|
||||
__tostring = function(self)
|
||||
local data = bin.pack("C", self.tag)
|
||||
local data = {string.pack("B", self.tag)}
|
||||
|
||||
for _, attrib in ipairs(self.attribs) do
|
||||
data = data .. tostring(attrib)
|
||||
data[#data+1] = tostring(attrib)
|
||||
end
|
||||
return data
|
||||
return table.concat(data)
|
||||
end
|
||||
|
||||
},
|
||||
@@ -206,12 +206,12 @@ IPP = {
|
||||
end,
|
||||
|
||||
__tostring = function(self)
|
||||
local data = bin.pack(">SSI", self.version, self.opid, self.reqid )
|
||||
local data = {string.pack(">I2I2I4", self.version, self.opid, self.reqid )}
|
||||
|
||||
for _, group in ipairs(self.attrib_groups) do
|
||||
data = data .. tostring(group)
|
||||
data[#data+1] = tostring(group)
|
||||
end
|
||||
data = data .. bin.pack("C", IPP.Attribute.IPP_TAG_END)
|
||||
data[#data+1] = string.pack("B", IPP.Attribute.IPP_TAG_END)
|
||||
return data
|
||||
end,
|
||||
|
||||
@@ -242,13 +242,13 @@ IPP = {
|
||||
local resp = IPP.Response:new()
|
||||
local pos
|
||||
|
||||
pos, resp.version, resp.status, resp.reqid = bin.unpack(">SSI", data)
|
||||
resp.version, resp.status, resp.reqid, pos = string.unpack(">I2I2I4", data)
|
||||
|
||||
resp.attrib_groups = {}
|
||||
local group
|
||||
repeat
|
||||
local tag, attrib
|
||||
pos, tag = bin.unpack(">C", data, pos)
|
||||
tag, pos = string.unpack(">B", data, pos)
|
||||
|
||||
if ( tag == IPP.Attribute.IPP_TAG_OPERATION or
|
||||
tag == IPP.Attribute.IPP_TAG_JOB or
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
-- Version 0.1
|
||||
-- Created 24/04/2011 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
|
||||
|
||||
local bin = require "bin"
|
||||
local ipOps = require "ipOps"
|
||||
local match = require "match"
|
||||
local nmap = require "nmap"
|
||||
@@ -173,12 +172,13 @@ Packet = {
|
||||
--- "Serializes" the packet to a string
|
||||
__tostring = function(self)
|
||||
local UNKNOWN = 0
|
||||
local data = bin.pack(">AIIISCCCCC", self.ncp_ip.signature,
|
||||
local data = self.ncp_ip.signature
|
||||
.. string.pack(">I4I4I4I2BBBBB",
|
||||
self.ncp_ip.length or 0, self.ncp_ip.version,
|
||||
self.ncp_ip.replybuf, self.type, self.seqno,
|
||||
self.conn, self.task, UNKNOWN, self.func )
|
||||
.. (self.length and bin.pack(">S", self.length) or "")
|
||||
.. (self.subfunc and bin.pack("C", self.subfunc) or "")
|
||||
.. (self.length and string.pack(">I2", self.length) or "")
|
||||
.. (self.subfunc and string.pack("B", self.subfunc) or "")
|
||||
.. (self.data or "")
|
||||
|
||||
return data
|
||||
@@ -209,7 +209,7 @@ ResponseParser = {
|
||||
if ( #data < 21 ) then
|
||||
return false, "Invalid NCP request, could not parse"
|
||||
end
|
||||
local pos, verb = bin.unpack("<I", data, 17)
|
||||
local verb, pos = string.unpack("<I4", data, 17)
|
||||
|
||||
if ( NCPVerb.Resolve == verb ) then
|
||||
return ResponseParser.Resolve(resp)
|
||||
@@ -263,7 +263,7 @@ ResponseParser = {
|
||||
local result = {}
|
||||
local pos
|
||||
|
||||
pos, result.srvname, result.os_major, result.os_minor,
|
||||
result.srvname, result.os_major, result.os_minor,
|
||||
result.conns_supported, result.conns_inuse,
|
||||
result.vols_supported, result.os_rev, result.sft_support,
|
||||
result.tts_level, result.conns_max_use, result.acct_version,
|
||||
@@ -272,7 +272,7 @@ ResponseParser = {
|
||||
result.internet_bridge_ver, result.mixed_mode_path,
|
||||
result.local_login_info, result.product_major,
|
||||
result.product_minor, result.product_rev, result.os_lang_id,
|
||||
result.support_64_bit = bin.unpack(">A48CCSSSCCCSCCCCCCCCCSSSCC", data)
|
||||
result.support_64_bit, pos = string.unpack(">c48BBI2I2I2BBBI2BBBBBBBBBI2I2I2BB", data)
|
||||
|
||||
return true, result
|
||||
end,
|
||||
@@ -288,11 +288,11 @@ ResponseParser = {
|
||||
local data = resp:getData()
|
||||
local len = #data
|
||||
|
||||
local pos, items, next_vol_no = bin.unpack("<II", data)
|
||||
local items, next_vol_no, pos = string.unpack("<I4I4", data)
|
||||
local vols = {}
|
||||
for i=1, items do
|
||||
local vol = {}
|
||||
pos, vol.vol_no, vol.vol_name = bin.unpack("<Ip", data, pos)
|
||||
vol.vol_no, vol.vol_name, pos = string.unpack("<I4s1", data, pos)
|
||||
table.insert(vols, vol)
|
||||
end
|
||||
return true, vols
|
||||
@@ -312,10 +312,10 @@ ResponseParser = {
|
||||
|
||||
if ( len < 40 ) then return false, "NCP Ping result too short" end
|
||||
|
||||
pos, result.nds_version = bin.unpack("C", data)
|
||||
result.nds_version, pos = string.unpack("B", data)
|
||||
-- move to the offset of the
|
||||
pos = pos + 7
|
||||
pos, result.tree_name = bin.unpack("A32", data, pos)
|
||||
result.tree_name, pos = string.unpack("c32", data, pos)
|
||||
|
||||
result.tree_name = (result.tree_name:match("^([^_]*)_*$"))
|
||||
|
||||
@@ -334,14 +334,14 @@ ResponseParser = {
|
||||
local data = resp:getData()
|
||||
local len = #data
|
||||
|
||||
pos, result.time_since_boot, result.console_version, result.console_revision,
|
||||
result.time_since_boot, result.console_version, result.console_revision,
|
||||
result.srvinfo_flags, result.guid, result.next_search,
|
||||
items = bin.unpack("<ICCSA16II", data)
|
||||
items, pos = string.unpack("<I4 BBI2 c16 I4I4", data)
|
||||
|
||||
local function DecodeAddress(data, pos)
|
||||
local COMM_TYPES = { [5] = "udp", [6] = "tcp" }
|
||||
local comm_type, port, ip, _
|
||||
pos, comm_type, _, _, _, port, ip = bin.unpack(">CCISSI", data, pos)
|
||||
comm_type, _, _, _, port, ip, pos = string.unpack(">BBI4I2I2I4", data, pos)
|
||||
|
||||
return pos, { port = port, ip = ipOps.fromdword(ip),
|
||||
proto = COMM_TYPES[comm_type] or "unknown" }
|
||||
@@ -375,7 +375,7 @@ ResponseParser = {
|
||||
return false, "ResponseParser: NCP Resolve, packet too short"
|
||||
end
|
||||
|
||||
local pos, frag_size, frag_handle, comp_code = bin.unpack("<III", data)
|
||||
local frag_size, frag_handle, comp_code, pos = string.unpack("<I4I4I4", data)
|
||||
|
||||
if ( len < 38 ) then
|
||||
return false, "ResponseParser: message too short"
|
||||
@@ -386,7 +386,7 @@ ResponseParser = {
|
||||
" non-zero value (%d)"):format(comp_code)
|
||||
end
|
||||
|
||||
local pos, tag, entry = bin.unpack("<II", data, pos)
|
||||
local tag, entry, pos = string.unpack("<I4I4", data, pos)
|
||||
|
||||
return true, { tag = tag, id = entry }
|
||||
end,
|
||||
@@ -407,7 +407,7 @@ ResponseParser = {
|
||||
return false, "ResponseParser: NCP Resolve, packet too short"
|
||||
end
|
||||
|
||||
local pos, frag_size, frag_handle, comp_code, iter_handle = bin.unpack("<IIII", data)
|
||||
local frag_size, frag_handle, comp_code, iter_handle, pos = string.unpack("<I4I4I4I4", data)
|
||||
|
||||
if ( comp_code ~= 0 ) then
|
||||
return false, ("ResponseParser: Completion code returned" ..
|
||||
@@ -416,7 +416,7 @@ ResponseParser = {
|
||||
|
||||
pos = pos + 12
|
||||
local entry_count
|
||||
pos, entry_count = bin.unpack("<I", data, pos)
|
||||
entry_count, pos = string.unpack("<I4", data, pos)
|
||||
|
||||
for i=1, entry_count do
|
||||
local entry
|
||||
@@ -481,36 +481,36 @@ ResponseParser = {
|
||||
|
||||
local entry = {}
|
||||
local f, len
|
||||
pos, f = bin.unpack("<I", data, pos)
|
||||
f, pos = string.unpack("<I4", data, pos)
|
||||
local iflags = InfoFlags:new(f)
|
||||
|
||||
if ( iflags.Entry ) then
|
||||
pos, entry.flags, entry.sub_count = bin.unpack("<II", data, pos)
|
||||
entry.flags, entry.sub_count, pos = string.unpack("<I4I4", data, pos)
|
||||
end
|
||||
|
||||
if ( iflags.ModTime ) then
|
||||
pos, entry.mod_time = bin.unpack("<I", data, pos)
|
||||
entry.mod_time, pos = string.unpack("<I4", data, pos)
|
||||
end
|
||||
|
||||
if ( iflags.BaseClass ) then
|
||||
pos, len = bin.unpack("<I", data, pos)
|
||||
pos, entry.baseclass = bin.unpack("A" .. len, data, pos)
|
||||
len, pos = string.unpack("<I4", data, pos)
|
||||
entry.baseclass, pos = string.unpack("c" .. len, data, pos)
|
||||
entry.baseclass = unicode.utf16to8(entry.baseclass)
|
||||
entry.baseclass = Util.CToLuaString(entry.baseclass)
|
||||
pos = ( len % 4 == 0 ) and pos or pos + ( 4 - ( len % 4 ) )
|
||||
end
|
||||
|
||||
if ( iflags.RelDN ) then
|
||||
pos, len = bin.unpack("<I", data, pos)
|
||||
pos, entry.rdn = bin.unpack("A" .. len, data, pos)
|
||||
len, pos = string.unpack("<I4", data, pos)
|
||||
entry.rdn, pos = string.unpack("c" .. len, data, pos)
|
||||
entry.rdn = unicode.utf16to8(entry.rdn)
|
||||
entry.rdn = Util.CToLuaString(entry.rdn)
|
||||
pos = ( len % 4 == 0 ) and pos or pos + ( 4 - ( len % 4 ) )
|
||||
end
|
||||
|
||||
if ( iflags.DN ) then
|
||||
pos, len = bin.unpack("<I", data, pos)
|
||||
pos, entry.name = bin.unpack("A" .. len, data, pos)
|
||||
len, pos = string.unpack("<I4", data, pos)
|
||||
entry.name, pos = string.unpack("c" .. len, data, pos)
|
||||
entry.name = unicode.utf16to8(entry.name)
|
||||
entry.name = Util.CToLuaString(entry.name)
|
||||
pos = ( len % 4 == 0 ) and pos or pos + ( 4 - ( len % 4 ) )
|
||||
@@ -534,7 +534,7 @@ ResponseParser = {
|
||||
return false, "ResponseParser: NCP Resolve, packet too short"
|
||||
end
|
||||
|
||||
local pos, frag_size, frag_handle, comp_code, iter_handle = bin.unpack("<IIII", data)
|
||||
local frag_size, frag_handle, comp_code, iter_handle, pos = string.unpack("<I4I4I4I4", data)
|
||||
|
||||
if ( comp_code ~= 0 ) then
|
||||
return false, ("ResponseParser: Completion code returned" ..
|
||||
@@ -542,7 +542,7 @@ ResponseParser = {
|
||||
end
|
||||
|
||||
local entry_count
|
||||
pos, entry_count = bin.unpack("<I", data, pos)
|
||||
entry_count, pos = string.unpack("<I4", data, pos)
|
||||
|
||||
local entries = {}
|
||||
|
||||
@@ -579,9 +579,9 @@ Response = {
|
||||
parse = function(self)
|
||||
local pos, _
|
||||
|
||||
pos, self.signature, self.length, self.type,
|
||||
self.signature, self.length, self.type,
|
||||
self.seqno, self.conn, _, self.compl_code,
|
||||
self.status_code = bin.unpack(">IISCCSCC", self.header)
|
||||
self.status_code, pos = string.unpack(">I4 I4 I2BBI2BB", self.header)
|
||||
|
||||
if ( self.data ) then
|
||||
local len = #self.data - pos
|
||||
@@ -622,7 +622,7 @@ Response = {
|
||||
local status, header = socket:receive_buf(match.numbytes(16), true)
|
||||
if ( not(status) ) then return false, "Failed to receive data" end
|
||||
|
||||
local pos, sig, len = bin.unpack(">II", header)
|
||||
local sig, len, pos = string.unpack(">I4I4", header)
|
||||
if ( len < 8 ) then return false, "NCP packet too short" end
|
||||
|
||||
local data
|
||||
@@ -636,7 +636,7 @@ Response = {
|
||||
|
||||
--- "Serializes" the Response instance to a string
|
||||
__tostring = function(self)
|
||||
return bin.pack("AA", self.header, self.data)
|
||||
return self.header .. self.data
|
||||
end,
|
||||
|
||||
}
|
||||
@@ -765,7 +765,7 @@ NCP = {
|
||||
-- p:setSubFunc(28)
|
||||
-- p:setTask(4)
|
||||
--
|
||||
-- local data = bin.pack("<I", conn_no)
|
||||
-- local data = string.pack("<I4", conn_no)
|
||||
-- p:setData(data)
|
||||
-- return self:Exch( p )
|
||||
-- end,
|
||||
@@ -822,28 +822,30 @@ NCP = {
|
||||
local frag_handle, frag_size = 0xffffffff, 64176
|
||||
local msg_size, unknown, proto_flags, nds_verb = 44 + #w_name, 0, 0, 1
|
||||
local nds_reply_buf, version, flags, scope = 4096, 1, 0x2062, 0
|
||||
-- TODO: unknown2 is not used. Should it be?
|
||||
local unknown2 = 0x0e
|
||||
local ZERO = 0
|
||||
|
||||
local data = bin.pack("<IIISSIIISSIIA", frag_handle, frag_size, msg_size,
|
||||
unknown, proto_flags, nds_verb, nds_reply_buf, version, flags,
|
||||
unknown, scope, #w_name, w_name, ZERO)
|
||||
local data = {
|
||||
string.pack("<I4I4I4 I2I2I4I4I4I2 I2I4 s4", frag_handle, frag_size, msg_size,
|
||||
unknown, proto_flags, nds_verb, nds_reply_buf, version, flags,
|
||||
unknown, scope, w_name)
|
||||
}
|
||||
|
||||
local comms = { { transport = "TCP" } }
|
||||
local walkers= { { transport = "TCP" } }
|
||||
local PROTOCOLS = { ["TCP"] = 9 }
|
||||
|
||||
data = data .. bin.pack("<I", #comms)
|
||||
data[#data+1] = string.pack("<I4", #comms)
|
||||
for _, comm in ipairs(comms) do
|
||||
data = data .. bin.pack("<I", PROTOCOLS[comm.transport])
|
||||
data[#data+1] = string.pack("<I4", PROTOCOLS[comm.transport])
|
||||
end
|
||||
|
||||
data = data .. bin.pack("<I", #walkers)
|
||||
data[#data+1] = string.pack("<I4", #walkers)
|
||||
for _, walker in ipairs(walkers) do
|
||||
data = data .. bin.pack("<I", PROTOCOLS[walker.transport])
|
||||
data[#data+1] = string.pack("<I4", PROTOCOLS[walker.transport])
|
||||
end
|
||||
|
||||
p:setData(data)
|
||||
p:setData(table.concat(data))
|
||||
return self:Exch( p )
|
||||
end,
|
||||
|
||||
@@ -866,7 +868,7 @@ NCP = {
|
||||
local vol_req_flags = 1
|
||||
local src_name_space = 0
|
||||
|
||||
local data = bin.pack("<III", start_vol, vol_req_flags, src_name_space )
|
||||
local data = string.pack("<I4I4I4", start_vol, vol_req_flags, src_name_space )
|
||||
p:setData(data)
|
||||
return self:Exch( p )
|
||||
end,
|
||||
@@ -907,7 +909,7 @@ NCP = {
|
||||
-- a bunch of unknowns
|
||||
local u2, u3, u4, u5, u6, u7, u8, u9 = 0, 0, 2, 2, 0, 0x10, 0, 0x11
|
||||
|
||||
local data = bin.pack("<IIISSIIIIIIIIIIIIIIIIIAIIIA",
|
||||
local data = string.pack("<I4I4I4 I2I2I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 I4 AI4 I4 I4 A",
|
||||
frag_handle, frag_size, msg_size, unknown, proto_flags,
|
||||
nds_verb, nds_reply_buf, version, flags, iter_handle,
|
||||
base.id, repl_type, numobjs, info_types, info_flags, u2, u3, u4,
|
||||
@@ -934,11 +936,11 @@ NCP = {
|
||||
local msg_size, unknown, proto_flags, nds_verb = 40, 0, 0, 5
|
||||
local nds_reply_buf, version, flags = 4100, 1, 0x0001
|
||||
local iter_handle = 0xffffffff
|
||||
-- TODO: unknown2 is not used. Should it be?
|
||||
local unknown2 = 0x0e
|
||||
local ZERO = 0
|
||||
local info_flags = 0x0000381d
|
||||
|
||||
local data = bin.pack("<IIISSIIISSIII", frag_handle, frag_size, msg_size,
|
||||
local data = string.pack("<I4I4I4I2I2I4I4I4I2I2I4I4I4", frag_handle, frag_size, msg_size,
|
||||
unknown, proto_flags, nds_verb, nds_reply_buf, version, flags,
|
||||
unknown, iter_handle, entry.id, info_flags )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user