hacked in some lamey signedness foo

git-svn-id: file:///home/svn/incoming/trunk@2845 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Spoon M 2005-09-05 07:21:31 +00:00
parent 654b7f034c
commit baef7224af
2 changed files with 24 additions and 6 deletions

View File

@ -48,11 +48,12 @@ class CStruct < SStruct
attr_reader :v
@@dt_table = {
'uint8' => proc { |*a| Rex::Struct2::Generic.new('C', *a) },
'uint16v' => proc { |*a| Rex::Struct2::Generic.new('v', *a) },
'uint32v' => proc { |*a| Rex::Struct2::Generic.new('V', *a) },
'uint16n' => proc { |*a| Rex::Struct2::Generic.new('n', *a) },
'uint32n' => proc { |*a| Rex::Struct2::Generic.new('N', *a) },
'uint8' => proc { |*a| Rex::Struct2::Generic.new('C', false, *a) },
'int16v' => proc { |*a| Rex::Struct2::Generic.new('v', true, *a) },
'uint16v' => proc { |*a| Rex::Struct2::Generic.new('v', false, *a) },
'uint32v' => proc { |*a| Rex::Struct2::Generic.new('V', false, *a) },
'uint16n' => proc { |*a| Rex::Struct2::Generic.new('n', false, *a) },
'uint32n' => proc { |*a| Rex::Struct2::Generic.new('N', false, *a) },
'string' => proc { |*a| Rex::Struct2::SString.new(*a) },
'sstruct' => proc { |*a| Rex::Struct2::SStruct.new(*a) },
'object' => proc { |o| o },

View File

@ -12,9 +12,21 @@ class Generic
attr_reader :default
attr_writer :default
def initialize(packspec, default=nil)
attr_accessor :mask, :check_mask
def initialize(packspec, signed=false, default=nil)
@packspec = packspec
@default = default
bytelen = [ -1 ].pack(@packspec).length
self.mask = (1 << (8 * bytelen)) - 1
if signed
self.check_mask = 1 << (8 * bytelen - 1)
else
self.check_mask = 0
end
reset()
end
@ -44,6 +56,11 @@ class Generic
return if restraint && restraint.max && len > restraint.max
return if restraint && restraint.min && len < restraint.min
# else set our value and return length used for this element
if (value & check_mask) != 0
value = -((~value & mask) + 1)
end
self.value = value
return(len)
end