Fixes #127. Applying patch from Alex that solves ASN.1 encoding issues.

git-svn-id: file:///home/svn/framework3/trunk@5049 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2007-07-16 01:13:25 +00:00
parent ce1532a64e
commit 24aac8b5ae
1 changed files with 21 additions and 10 deletions

View File

@ -94,18 +94,29 @@ CONST = Rex::Proto::SMB::Constants
return decoded return decoded
end end
#
# Prepends an ASN1 formatted length field to a piece of data
#
def self.asn1encode(str = '') def self.asn1encode(str = '')
res = '' res = ''
case str.length
when 0 .. 0x80 # If the high bit of the first byte is 1, it contains the number of
res = [str.length].pack('C') + str # length bytes that follow
when 0x81 .. 0x100
res = [0x81, str.length].pack('CC') + str case data.length
when 0x101 .. 0x100000 when 0 .. 0x7F
res = [0x82, str.length].pack('Cn') + str res = [data.length].pack('C') + data
when 0x100001 .. 0xffffffff when 0x80 .. 0xFF
res = [0x83, str.length].pack('CN') + str res = [0x81, data.length].pack('CC') + data
end when 0x100 .. 0xFFFF
res = [0x82, data.length].pack('Cn') + data
when 0x10000 .. 0xffffff
res = [0x83, data.length >> 16, data.length & 0xFFFF].pack('CCn') + data
when 0x1000000 .. 0xffffffff
res = [0x84, data.length].pack('CN') + data
else
raise "ASN1 data too long"
end
return res return res
end end