Parent

Included Modules

Class/Module Index [+]

Quicksearch

Rex::Struct2::CStruct

Attributes

v[R]

Public Class Methods

new(*dts) click to toggle source
# File lib/rex/struct2/c_struct.rb, line 77
def initialize(*dts)
        super()
        @name_table = [ ]
        @v = Rex::Struct2::CStruct_Values.new(self)

        return self.add_from_dt(*dts)
end
typedef(*args) click to toggle source

CStruct.typedef(name, factory, ... )

# File lib/rex/struct2/c_struct.rb, line 69
def CStruct.typedef(*args)
        while args.length >= 2
                name    = args.shift
                factory = args.shift
                @@dt_table[name] = factory
        end
end

Public Instance Methods

[](index, *other) click to toggle source

ya ya, I know, these are weird. I'm not sure why I even bothered to inherit from array...

# File lib/rex/struct2/c_struct.rb, line 145
def [](index, *other)
        if index.kind_of?(String)
                i = @name_table.index(index)
                return if !i
                return super(i)
        else
                return super(index, *other)
        end
end
[]=(index, *other) click to toggle source
# File lib/rex/struct2/c_struct.rb, line 155
def []=(index, *other)
        if index.kind_of?(String)
                i = @name_table.index(index)
                return if !i
                return super(i, *other)
        else
                return super(index, *other)
        end
end
add_from_dt(*dts) click to toggle source
# File lib/rex/struct2/c_struct.rb, line 85
def add_from_dt(*dts)
        dts.each { | dt |
                return if !dt.kind_of?(Array) || dt.length < 2

                type = dt[0]
                name = dt[1]

                factory = @@dt_table[type]

                return if !factory

                # call with the arguments passed in
                obj = factory.call(*(dt[2 .. -1]))

                self.add_object(name, obj)
        }

        return dts.length
end
add_object(*objs) click to toggle source
# File lib/rex/struct2/c_struct.rb, line 105
def add_object(*objs)
        while objs.length >= 2
                @name_table << objs.shift
                self        << objs.shift
        end
end
apply_restraint(*ress) click to toggle source

apply_restraint( name, restraint, name2, restraint2 ... )

# File lib/rex/struct2/c_struct.rb, line 112
def apply_restraint(*ress)
        while ress.length >= 2
                name = ress.shift
                res  = ress.shift
                self[name].restraint = res

                # update the restrainted object, so it will update the value
                # of the restrainter, with the initial size.  If you don't
                # want this behavior, um, you'll have to be careful with what
                # you supply as default values...
                self[name].update_restraint
        end
        return self
end
create_restraints(*ress) click to toggle source

create_restraints( [ name, stuff_to_restraint_constructor ] ... )

# File lib/rex/struct2/c_struct.rb, line 128
def create_restraints(*ress)
        ress.each { |r|
                # make a copy before we modify...
                r = r.dup
                # resolve names into objects
                r[1] = self[r[1]] if r[1]
                r[2] = self[r[2]] if r[2]

                # build and apply the restraint
                self.apply_restraint(r[0], Rex::Struct2::Restraint.new(*r[1 .. -1]))
        }

        return self
end
each_pair(&block) click to toggle source

Iterate through all fields and values

# File lib/rex/struct2/c_struct.rb, line 171
def each_pair(&block)
        @name_table.each do |k|
                block.call(k, self.v[k])
        end
end
keys() click to toggle source

Produce a list of field names

# File lib/rex/struct2/c_struct.rb, line 166
def keys
        @name_table
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.