Changeset 2333

Show
Ignore:
Timestamp:
04/01/05 16:18:33 (4 years ago)
Author:
spoonm
Message:

Added support for typdef like functionality

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • incoming/trunk/lib/rex/struct2/c_struct.rb

    r2330 r2333  
    4949 
    5050        @@dt_table = { 
    51           'uint8'     => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'C' ], 
    52           'uint16v'   => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'v' ], 
    53           'uint32v'   => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'V' ], 
    54           'uint16n'   => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'n' ], 
    55           'uint32n'   => [ proc { |*a| Rex::Struct2::Generic.new(*a) }, 'N' ], 
    56           'string'    => [ proc { |*a| Rex::Struct2::SString.new(*a) } ], 
    57           'sstruct'   => [ proc { |*a| Rex::Struct2::SStruct.new(*a) } ], 
    58           'object'    => [ proc { |o| o } ], # no class, treat as object... 
    59           'struct'    => [ proc { |o| o } ], # no class, treat as object... 
    60           'cstruct'   => [ proc { |o| o } ], # no class, treat as object... 
    61           'template'  => [ proc { |o| o.make_struct } ], 
     51          'uint8'     => proc { |*a| Rex::Struct2::Generic.new('C', *a) }, 
     52          'uint16v'   => proc { |*a| Rex::Struct2::Generic.new('v', *a) }, 
     53          'uint32v'   => proc { |*a| Rex::Struct2::Generic.new('V', *a) }, 
     54          'uint16n'   => proc { |*a| Rex::Struct2::Generic.new('n', *a) }, 
     55          'uint32n'   => proc { |*a| Rex::Struct2::Generic.new('N', *a) }, 
     56          'string'    => proc { |*a| Rex::Struct2::SString.new(*a) }, 
     57          'sstruct'   => proc { |*a| Rex::Struct2::SStruct.new(*a) }, 
     58          'object'    => proc { |o| o }, 
     59          'template'  => proc { |o| o.make_struct }, 
    6260        } 
     61 
     62        # CStruct.typedef(name, factory, ... ) 
     63        def CStruct.typedef(*args) 
     64                while args.length >= 2 
     65                        name    = args.shift 
     66                        factory = args.shift 
     67                        @@dt_table[name] = factory 
     68                end 
     69        end 
    6370 
    6471        def initialize(*dts) 
     
    7784                        name = dt[1] 
    7885 
    79                         entry = @@dt_table[type] 
     86                        factory = @@dt_table[type] 
    8087 
    81                         return if !entry 
     88                        return if !factory 
    8289 
    83                         factory = entry[0] 
    84  
    85                         obj = factory.call(*(entry[1 .. -1] + dt[2 .. -1])) 
     90                        # call with the arguments passed in 
     91                        obj = factory.call(*(dt[2 .. -1])) 
    8692 
    8793                        self.add_object(name, obj)