Added support for typdef like functionality
git-svn-id: file:///home/svn/incoming/trunk@2333 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
95023a82e9
commit
87e3fda1fc
|
@ -48,19 +48,26 @@ class CStruct < SStruct
|
||||||
attr_reader :v
|
attr_reader :v
|
||||||
|
|
||||||
@@dt_table = {
|
@@dt_table = {
|
||||||
'uint8' => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'C' ],
|
'uint8' => proc { |*a| Rex::Struct2::Generic.new('C', *a) },
|
||||||
'uint16v' => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'v' ],
|
'uint16v' => proc { |*a| Rex::Struct2::Generic.new('v', *a) },
|
||||||
'uint32v' => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'V' ],
|
'uint32v' => proc { |*a| Rex::Struct2::Generic.new('V', *a) },
|
||||||
'uint16n' => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'n' ],
|
'uint16n' => proc { |*a| Rex::Struct2::Generic.new('n', *a) },
|
||||||
'uint32n' => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'N' ],
|
'uint32n' => proc { |*a| Rex::Struct2::Generic.new('N', *a) },
|
||||||
'string' => [ proc { |*a| Rex::Struct2::SString.new(*a) } ],
|
'string' => proc { |*a| Rex::Struct2::SString.new(*a) },
|
||||||
'sstruct' => [ proc { |*a| Rex::Struct2::SStruct.new(*a) } ],
|
'sstruct' => proc { |*a| Rex::Struct2::SStruct.new(*a) },
|
||||||
'object' => [ proc { |o| o } ], # no class, treat as object...
|
'object' => proc { |o| o },
|
||||||
'struct' => [ proc { |o| o } ], # no class, treat as object...
|
'template' => proc { |o| o.make_struct },
|
||||||
'cstruct' => [ proc { |o| o } ], # no class, treat as object...
|
|
||||||
'template' => [ proc { |o| o.make_struct } ],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# CStruct.typedef(name, factory, ... )
|
||||||
|
def CStruct.typedef(*args)
|
||||||
|
while args.length >= 2
|
||||||
|
name = args.shift
|
||||||
|
factory = args.shift
|
||||||
|
@@dt_table[name] = factory
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(*dts)
|
def initialize(*dts)
|
||||||
super()
|
super()
|
||||||
@name_table = [ ]
|
@name_table = [ ]
|
||||||
|
@ -76,13 +83,12 @@ class CStruct < SStruct
|
||||||
type = dt[0]
|
type = dt[0]
|
||||||
name = dt[1]
|
name = dt[1]
|
||||||
|
|
||||||
entry = @@dt_table[type]
|
factory = @@dt_table[type]
|
||||||
|
|
||||||
return if !entry
|
return if !factory
|
||||||
|
|
||||||
factory = entry[0]
|
# call with the arguments passed in
|
||||||
|
obj = factory.call(*(dt[2 .. -1]))
|
||||||
obj = factory.call(*(entry[1 .. -1] + dt[2 .. -1]))
|
|
||||||
|
|
||||||
self.add_object(name, obj)
|
self.add_object(name, obj)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue