mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Remove bin.lua from rpc.lua
This commit is contained in:
142
nselib/rpc.lua
142
nselib/rpc.lua
@@ -75,7 +75,6 @@
|
|||||||
-- @args rpc.protocol table If set overrides the preferred order in which
|
-- @args rpc.protocol table If set overrides the preferred order in which
|
||||||
-- protocols are tested. (ie. "tcp", "udp")
|
-- protocols are tested. (ie. "tcp", "udp")
|
||||||
|
|
||||||
local bin = require "bin"
|
|
||||||
local datafiles = require "datafiles"
|
local datafiles = require "datafiles"
|
||||||
local datetime = require "datetime"
|
local datetime = require "datetime"
|
||||||
local math = require "math"
|
local math = require "math"
|
||||||
@@ -332,10 +331,10 @@ Comm = {
|
|||||||
local xid = xid or math.random(1234567890)
|
local xid = xid or math.random(1234567890)
|
||||||
local procedure = procedure or 0
|
local procedure = procedure or 0
|
||||||
|
|
||||||
packet = bin.pack( ">IIIIII", xid, Portmap.MessageType.CALL, RPC_VERSION,
|
packet = string.pack( ">I4 I4 I4 I4 I4 I4", xid, Portmap.MessageType.CALL, RPC_VERSION,
|
||||||
self.program_id, self.version, procedure )
|
self.program_id, self.version, procedure )
|
||||||
if auth.type == Portmap.AuthType.NULL then
|
if auth.type == Portmap.AuthType.NULL then
|
||||||
packet = packet .. bin.pack( "IIII", 0, 0, 0, 0 )
|
packet = packet .. string.pack( ">I4 I4 I4 I4", 0, 0, 0, 0 )
|
||||||
elseif auth.type == Portmap.AuthType.UNIX then
|
elseif auth.type == Portmap.AuthType.UNIX then
|
||||||
packet = packet .. Util.marshall_int32(auth.type)
|
packet = packet .. Util.marshall_int32(auth.type)
|
||||||
local blob = (
|
local blob = (
|
||||||
@@ -353,7 +352,7 @@ Comm = {
|
|||||||
blob = blob .. Util.marshall_int32(0)
|
blob = blob .. Util.marshall_int32(0)
|
||||||
end
|
end
|
||||||
packet = (packet .. Util.marshall_vopaque(blob)
|
packet = (packet .. Util.marshall_vopaque(blob)
|
||||||
.. bin.pack( "II", 0, 0 ) --AUTH_NULL verf
|
.. string.pack( ">I4 I4", 0, 0 ) --AUTH_NULL verf
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
return false, "Comm.CreateHeader: invalid authentication type specified"
|
return false, "Comm.CreateHeader: invalid authentication type specified"
|
||||||
@@ -376,7 +375,8 @@ Comm = {
|
|||||||
|
|
||||||
header.verifier = {}
|
header.verifier = {}
|
||||||
|
|
||||||
if ( data:len() - pos < HEADER_LEN ) then
|
pos = pos or 1
|
||||||
|
if ( data:len() - pos + 1 < HEADER_LEN ) then
|
||||||
local tmp
|
local tmp
|
||||||
status, tmp = self:GetAdditionalBytes( data, pos, HEADER_LEN - ( data:len() - pos ) )
|
status, tmp = self:GetAdditionalBytes( data, pos, HEADER_LEN - ( data:len() - pos ) )
|
||||||
if not status then
|
if not status then
|
||||||
@@ -386,15 +386,15 @@ Comm = {
|
|||||||
data = data .. tmp
|
data = data .. tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, header.xid, header.type, header.state = bin.unpack(">III", data, pos)
|
header.xid, header.type, header.state, pos = string.unpack(">I4 I4 I4", data, pos)
|
||||||
|
|
||||||
if ( header.state == Portmap.State.MSG_DENIED ) then
|
if ( header.state == Portmap.State.MSG_DENIED ) then
|
||||||
pos, header.denied_state = bin.unpack(">I", data, pos )
|
header.denied_state, pos = string.unpack(">I4", data, pos )
|
||||||
return pos, header
|
return pos, header
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, header.verifier.flavor = bin.unpack(">I", data, pos)
|
header.verifier.flavor, pos = string.unpack(">I4", data, pos)
|
||||||
pos, header.verifier.length = bin.unpack(">I", data, pos)
|
header.verifier.length, pos = string.unpack(">I4", data, pos)
|
||||||
|
|
||||||
if header.verifier.length - 8 > 0 then
|
if header.verifier.length - 8 > 0 then
|
||||||
status, data = self:GetAdditionalBytes( data, pos, header.verifier.length - 8 )
|
status, data = self:GetAdditionalBytes( data, pos, header.verifier.length - 8 )
|
||||||
@@ -402,9 +402,9 @@ Comm = {
|
|||||||
stdnse.debug4("Comm.DecodeHeader: failed to call GetAdditionalBytes")
|
stdnse.debug4("Comm.DecodeHeader: failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, header.verifier.data = bin.unpack("A" .. header.verifier.length - 8, data, pos )
|
header.verifier.data, pos = string.unpack("c" .. header.verifier.length - 8, data, pos )
|
||||||
end
|
end
|
||||||
pos, header.accept_state = bin.unpack(">I", data, pos )
|
header.accept_state, pos = string.unpack(">I4", data, pos )
|
||||||
|
|
||||||
return pos, header
|
return pos, header
|
||||||
end,
|
end,
|
||||||
@@ -437,7 +437,7 @@ Comm = {
|
|||||||
return false, "Comm.ReceivePacket: failed to call GetAdditionalBytes"
|
return false, "Comm.ReceivePacket: failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, tmp = bin.unpack(">i", data, pos )
|
tmp, pos = string.unpack(">I4", data, pos )
|
||||||
length = tmp & 0x7FFFFFFF
|
length = tmp & 0x7FFFFFFF
|
||||||
|
|
||||||
if (tmp & 0x80000000) == 0x80000000 then
|
if (tmp & 0x80000000) == 0x80000000 then
|
||||||
@@ -504,7 +504,7 @@ Comm = {
|
|||||||
else
|
else
|
||||||
-- set the high bit as this is our last fragment
|
-- set the high bit as this is our last fragment
|
||||||
len = 0x80000000 + packet:len()
|
len = 0x80000000 + packet:len()
|
||||||
return bin.pack(">I", len) .. packet
|
return string.pack(">I4", len) .. packet
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -696,12 +696,12 @@ Portmap =
|
|||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
return false, "Portmap.Dump: Failed to call GetAdditionalBytes"
|
return false, "Portmap.Dump: Failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
pos, vfollows = bin.unpack( ">I", data, pos )
|
vfollows, pos = string.unpack(">I4", data, pos)
|
||||||
if ( vfollows == 0 ) then
|
if ( vfollows == 0 ) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, program, version, protocol, port = bin.unpack(">IIII", data, pos)
|
program, version, protocol, port, pos = string.unpack(">I4 I4 I4 I4", data, pos)
|
||||||
if ( protocol == Portmap.PROTOCOLS.tcp ) then
|
if ( protocol == Portmap.PROTOCOLS.tcp ) then
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
elseif ( protocol == Portmap.PROTOCOLS.udp ) then
|
elseif ( protocol == Portmap.PROTOCOLS.udp ) then
|
||||||
@@ -740,7 +740,7 @@ Portmap =
|
|||||||
return false, ("Portmap.Callit: Unknown program name: %s"):format(program)
|
return false, ("Portmap.Callit: Unknown program name: %s"):format(program)
|
||||||
end
|
end
|
||||||
|
|
||||||
local data = bin.pack(">IIII", Util.ProgNameToNumber(program), version, 0, 0 )
|
local data = string.pack(">I4 I4 I4 I4", Util.ProgNameToNumber(program), version, 0, 0 )
|
||||||
local packet = comm:EncodePacket(nil, Portmap.Procedure[comm.version].CALLIT,
|
local packet = comm:EncodePacket(nil, Portmap.Procedure[comm.version].CALLIT,
|
||||||
{ type=Portmap.AuthType.NULL }, data )
|
{ type=Portmap.AuthType.NULL }, data )
|
||||||
|
|
||||||
@@ -788,7 +788,7 @@ Portmap =
|
|||||||
return false, ("Portmap.GetPort: Unknown program name: %s"):format(program)
|
return false, ("Portmap.GetPort: Unknown program name: %s"):format(program)
|
||||||
end
|
end
|
||||||
|
|
||||||
data = bin.pack(">I>I>I>I", Util.ProgNameToNumber(program), version,
|
data = string.pack(">I4 I4 I4 I4", Util.ProgNameToNumber(program), version,
|
||||||
Portmap.PROTOCOLS[protocol], 0 )
|
Portmap.PROTOCOLS[protocol], 0 )
|
||||||
packet = comm:EncodePacket(xid, Portmap.Procedure[comm.version].GETPORT,
|
packet = comm:EncodePacket(xid, Portmap.Procedure[comm.version].GETPORT,
|
||||||
{ type=Portmap.AuthType.NULL }, data )
|
{ type=Portmap.AuthType.NULL }, data )
|
||||||
@@ -839,7 +839,7 @@ Portmap =
|
|||||||
return false, "Portmap.GetPort: Failed to call GetAdditionalBytes"
|
return false, "Portmap.GetPort: Failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, select(2, bin.unpack(">I", data, pos ) )
|
return true, string.unpack(">I4", data, pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1042,10 +1042,9 @@ Mount = {
|
|||||||
-- @return fhandle string containing the filehandle of the remote export
|
-- @return fhandle string containing the filehandle of the remote export
|
||||||
Mount = function(self, comm, path)
|
Mount = function(self, comm, path)
|
||||||
local packet, mount_status
|
local packet, mount_status
|
||||||
local _, pos, data, header, fhandle = "", 1, "", "", {}
|
|
||||||
local status, len
|
local status, len
|
||||||
|
|
||||||
data = Util.marshall_vopaque(path)
|
local data = Util.marshall_vopaque(path)
|
||||||
|
|
||||||
packet = comm:EncodePacket( nil, Mount.Procedure.MOUNT, { type=Portmap.AuthType.UNIX }, data )
|
packet = comm:EncodePacket( nil, Mount.Procedure.MOUNT, { type=Portmap.AuthType.UNIX }, data )
|
||||||
if (not(comm:SendPacket(packet))) then
|
if (not(comm:SendPacket(packet))) then
|
||||||
@@ -1057,7 +1056,7 @@ Mount = {
|
|||||||
return false, "Mount: Failed to read data from socket"
|
return false, "Mount: Failed to read data from socket"
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, header = comm:DecodeHeader( data, pos )
|
local pos, header = comm:DecodeHeader(data)
|
||||||
if not header then
|
if not header then
|
||||||
return false, "Mount: Failed to decode header"
|
return false, "Mount: Failed to decode header"
|
||||||
end
|
end
|
||||||
@@ -1100,23 +1099,24 @@ Mount = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local fhandle
|
||||||
if ( comm.version == 3 ) then
|
if ( comm.version == 3 ) then
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, 4 )
|
status, data = comm:GetAdditionalBytes( data, pos, 4 )
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
return false, "Mount: Failed to call GetAdditionalBytes"
|
return false, "Mount: Failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
_, len = bin.unpack(">I", data, pos )
|
len = string.unpack(">I4", data, pos)
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, len + 4 )
|
status, data = comm:GetAdditionalBytes( data, pos, len + 4 )
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
return false, "Mount: Failed to call GetAdditionalBytes"
|
return false, "Mount: Failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
pos, fhandle = bin.unpack( "A" .. len + 4, data, pos )
|
fhandle, pos = string.unpack( "c" .. len + 4, data, pos )
|
||||||
elseif ( comm.version < 3 ) then
|
elseif ( comm.version < 3 ) then
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, 32 )
|
status, data = comm:GetAdditionalBytes( data, pos, 32 )
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
return false, "Mount: Failed to call GetAdditionalBytes"
|
return false, "Mount: Failed to call GetAdditionalBytes"
|
||||||
end
|
end
|
||||||
pos, fhandle = bin.unpack( "A32", data, pos )
|
fhandle, pos = string.unpack( "c32", data, pos )
|
||||||
else
|
else
|
||||||
return false, "Mount failed"
|
return false, "Mount failed"
|
||||||
end
|
end
|
||||||
@@ -1484,7 +1484,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.ReadDirDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, _ = bin.unpack(">L", data, pos)
|
_, pos = string.unpack(">I8", data, pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
response.entries = {}
|
response.entries = {}
|
||||||
@@ -1570,9 +1570,9 @@ NFS = {
|
|||||||
|
|
||||||
if ( comm.version == 3 ) then
|
if ( comm.version == 3 ) then
|
||||||
local opaque_data = 0
|
local opaque_data = 0
|
||||||
data = bin.pack("A>L>L>I", file_handle, cookie, opaque_data, count)
|
data = file_handle .. string.pack("I8 I8 I4", cookie, opaque_data, count)
|
||||||
else
|
else
|
||||||
data = bin.pack("A>I>I", file_handle, cookie, count)
|
data = file_handle .. string.pack(">I4 I4", cookie, count)
|
||||||
end
|
end
|
||||||
packet = comm:EncodePacket( nil, NFS.Procedure[comm.version].READDIR,
|
packet = comm:EncodePacket( nil, NFS.Procedure[comm.version].READDIR,
|
||||||
{ type=Portmap.AuthType.UNIX }, data )
|
{ type=Portmap.AuthType.UNIX }, data )
|
||||||
@@ -1622,7 +1622,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, lookup.fhandle = bin.unpack( "A" .. len + 4, data, pos)
|
lookup.fhandle, pos = string.unpack( "c" .. len + 4, data, pos)
|
||||||
|
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, 4)
|
status, data = comm:GetAdditionalBytes( data, pos, 4)
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
@@ -1668,7 +1668,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, lookup.fhandle = bin.unpack("A32", data, pos)
|
lookup.fhandle, pos = string.unpack("c32", data, pos)
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, 64 )
|
status, data = comm:GetAdditionalBytes( data, pos, 64 )
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.LookUpDecode: Failed to call GetAdditionalBytes")
|
||||||
@@ -1737,7 +1737,7 @@ NFS = {
|
|||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, value_follows = bin.unpack(">I", data, pos)
|
value_follows, pos = string.unpack(">I4", data, pos)
|
||||||
if value_follows == 0 then
|
if value_follows == 0 then
|
||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Attributes follow failed")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Attributes follow failed")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
@@ -1757,7 +1757,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, _ = bin.unpack(">L", data, pos)
|
_, pos = string.unpack(">I8", data, pos)
|
||||||
|
|
||||||
response.entries = {}
|
response.entries = {}
|
||||||
while true do
|
while true do
|
||||||
@@ -1768,7 +1768,7 @@ NFS = {
|
|||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, value_follows = bin.unpack(">I", data, pos)
|
value_follows, pos = string.unpack(">I4", data, pos)
|
||||||
|
|
||||||
if (value_follows == 0) then
|
if (value_follows == 0) then
|
||||||
break
|
break
|
||||||
@@ -1778,7 +1778,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, entry.fileid = bin.unpack(">L", data, pos)
|
entry.fileid, pos = string.unpack(">I8", data, pos)
|
||||||
|
|
||||||
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
||||||
|
|
||||||
@@ -1787,7 +1787,7 @@ NFS = {
|
|||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
pos, entry.length = bin.unpack(">I", data, pos)
|
entry.length, pos = string.unpack(">I4", data, pos)
|
||||||
status, data = comm:GetAdditionalBytes( data, pos, entry.length )
|
status, data = comm:GetAdditionalBytes( data, pos, entry.length )
|
||||||
if not status then
|
if not status then
|
||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
@@ -1800,7 +1800,7 @@ NFS = {
|
|||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, entry.cookie = bin.unpack(">L", data, pos)
|
entry.cookie, pos = string.unpack(">I8", data, pos)
|
||||||
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
||||||
if not status then
|
if not status then
|
||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
@@ -1808,7 +1808,7 @@ NFS = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
entry.attributes = {}
|
entry.attributes = {}
|
||||||
pos, value_follows = bin.unpack(">I", data, pos)
|
value_follows, pos = string.unpack(">I4", data, pos)
|
||||||
if (value_follows ~= 0) then
|
if (value_follows ~= 0) then
|
||||||
status, data = comm:GetAdditionalBytes(data, pos, 84)
|
status, data = comm:GetAdditionalBytes(data, pos, 84)
|
||||||
if not status then
|
if not status then
|
||||||
@@ -1828,7 +1828,7 @@ NFS = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
entry.fhandle = ""
|
entry.fhandle = ""
|
||||||
pos, value_follows = bin.unpack(">I", data, pos)
|
value_follows, pos = string.unpack(">I4", data, pos)
|
||||||
if (value_follows ~= 0) then
|
if (value_follows ~= 0) then
|
||||||
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
status, data = comm:GetAdditionalBytes(data, pos, 4)
|
||||||
if not status then
|
if not status then
|
||||||
@@ -1836,13 +1836,13 @@ NFS = {
|
|||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
_, len = bin.unpack(">I", data, pos)
|
len = string.unpack(">I4", data, pos)
|
||||||
status, data = comm:GetAdditionalBytes(data, pos, len + 4)
|
status, data = comm:GetAdditionalBytes(data, pos, len + 4)
|
||||||
if not status then
|
if not status then
|
||||||
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
stdnse.debug4("NFS.ReadDirPlusDecode: Failed to call GetAdditionalBytes")
|
||||||
return -1, nil
|
return -1, nil
|
||||||
end
|
end
|
||||||
pos, entry.fhandle = bin.unpack( "A" .. len + 4, data, pos )
|
entry.fhandle, pos = string.unpack( "c" .. len + 4, data, pos )
|
||||||
else
|
else
|
||||||
stdnse.debug4("NFS.ReadDirPlusDecode: %s handle follow failed",
|
stdnse.debug4("NFS.ReadDirPlusDecode: %s handle follow failed",
|
||||||
entry.name)
|
entry.name)
|
||||||
@@ -1868,8 +1868,7 @@ NFS = {
|
|||||||
return false, "ReadDirPlus: No filehandle received"
|
return false, "ReadDirPlus: No filehandle received"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = bin.pack("A>L>L>I>I", file_handle, cookie,
|
data = file_handle .. string.pack(">I8 I8 I4 I4", cookie, opaque_data, dircount, maxcount)
|
||||||
opaque_data, dircount, maxcount)
|
|
||||||
|
|
||||||
packet = comm:EncodePacket(nil, NFS.Procedure[comm.version].READDIRPLUS,
|
packet = comm:EncodePacket(nil, NFS.Procedure[comm.version].READDIRPLUS,
|
||||||
{type = Portmap.AuthType.UNIX }, data)
|
{type = Portmap.AuthType.UNIX }, data)
|
||||||
@@ -3043,60 +3042,52 @@ Util =
|
|||||||
Util.TimeToString(attr[time].seconds))
|
Util.TimeToString(attr[time].seconds))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_int32 = function(int32, count)
|
marshall_int32 = function(int32)
|
||||||
if count then
|
return string.pack(">i4", int32)
|
||||||
return bin.pack(">i" .. count, int32)
|
|
||||||
end
|
|
||||||
return bin.pack(">i", int32)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
unmarshall_int32 = function(data, pos, count)
|
unmarshall_int32 = function(data, pos, count)
|
||||||
if count then
|
local ints = {}
|
||||||
return bin.unpack(">i" .. count, data, pos)
|
for i=1,(count or 1) do
|
||||||
|
ints[i], pos = string.unpack(">i4", data, pos)
|
||||||
end
|
end
|
||||||
return bin.unpack(">i", data, pos)
|
return pos, table.unpack(ints)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_uint32 = function(uint32, count)
|
marshall_uint32 = function(uint32)
|
||||||
if count then
|
return string.pack(">I4", uint32)
|
||||||
return bin.pack(">I" .. count, uint32)
|
|
||||||
end
|
|
||||||
return bin.pack(">I", uint32)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
unmarshall_uint32 = function(data, pos, count)
|
unmarshall_uint32 = function(data, pos, count)
|
||||||
if count then
|
local ints = {}
|
||||||
return bin.unpack(">I" .. count, data, pos)
|
for i=1,(count or 1) do
|
||||||
|
ints[i], pos = string.unpack(">I4", data, pos)
|
||||||
end
|
end
|
||||||
return bin.unpack(">I", data, pos)
|
return pos, table.unpack(ints)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_int64 = function(int64, count)
|
marshall_int64 = function(int64)
|
||||||
if count then
|
return string.pack(">i8", int64)
|
||||||
return bin.pack(">l" .. count, int64)
|
|
||||||
end
|
|
||||||
return bin.pack(">l", int64)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
unmarshall_int64 = function(data, pos, count)
|
unmarshall_int64 = function(data, pos, count)
|
||||||
if count then
|
local ints = {}
|
||||||
return bin.unpack(">l" .. count, data, pos)
|
for i=1,(count or 1) do
|
||||||
|
ints[i], pos = string.unpack(">i8", data, pos)
|
||||||
end
|
end
|
||||||
return bin.unpack(">l", data, pos)
|
return pos, table.unpack(ints)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_uint64 = function(uint64, count)
|
marshall_uint64 = function(uint64)
|
||||||
if count then
|
return string.pack(">I8", uint64)
|
||||||
return bin.pack(">L" .. count, uint64)
|
|
||||||
end
|
|
||||||
return bin.pack(">L", uint64)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
unmarshall_uint64 = function(data, pos, count)
|
unmarshall_uint64 = function(data, pos, count)
|
||||||
if count then
|
local ints = {}
|
||||||
return bin.unpack(">L" .. count, data, pos)
|
for i=1,(count or 1) do
|
||||||
|
ints[i], pos = string.unpack(">I8", data, pos)
|
||||||
end
|
end
|
||||||
return bin.unpack(">L", data, pos)
|
return pos, table.unpack(ints)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_opaque = function(data)
|
marshall_opaque = function(data)
|
||||||
@@ -3104,7 +3095,8 @@ Util =
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
unmarshall_opaque = function(len, data, pos)
|
unmarshall_opaque = function(len, data, pos)
|
||||||
return bin.unpack(">A" .. len, data, pos)
|
local opaque, pos = string.unpack("c" .. len, data, pos)
|
||||||
|
return pos, opaque
|
||||||
end,
|
end,
|
||||||
|
|
||||||
marshall_vopaque = function(data)
|
marshall_vopaque = function(data)
|
||||||
@@ -3118,7 +3110,7 @@ Util =
|
|||||||
unmarshall_vopaque = function(len, data, pos)
|
unmarshall_vopaque = function(len, data, pos)
|
||||||
local opaque, pad
|
local opaque, pad
|
||||||
pad = Util.CalcFillBytes(len)
|
pad = Util.CalcFillBytes(len)
|
||||||
pos, opaque = bin.unpack(">A" .. len, data, pos)
|
opaque, pos = string.unpack("c" .. len, data, pos)
|
||||||
return pos + pad, opaque
|
return pos + pad, opaque
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user