class Metasm::Data
all kind of data description (including repeated/uninitialized)
Constants
- DataSpec
keywords for data definition (used to recognize label names)
- INT_TYPE
maps data type to
Expression
parameters (signedness/bit size)
Attributes
count[RW]
the repetition count of the data parameter (dup constructs)
data[RW]
an Expression
, an Array of Data
, a String
, or :uninitialized
type[RW]
the data type, from INT_TYPE
(TODO store directly Expression
parameters ?)
Public Class Methods
new(type, data, count=1, backtrace=nil)
click to toggle source
# File metasm/main.rb, line 216 def initialize(type, data, count=1, backtrace=nil) @data, @type, @count, @backtrace = data, type, count, backtrace end
Public Instance Methods
encode(endianness)
click to toggle source
# File metasm/encode.rb, line 307 def encode(endianness) edata = case @data when :uninitialized EncodedData.new('', :virtsize => Expression::INT_SIZE[INT_TYPE[@type]]/8) when String # db 'foo' => 'foo' # XXX could be optimised, but should not be significant # dw 'foo' => "f\0o\0o\0" / "\0f\0o\0o" @data.unpack('C*').inject(EncodedData.new) { |ed, chr| ed << Expression.encode_imm(chr, INT_TYPE[@type], endianness, @backtrace) } when Expression @data.encode INT_TYPE[@type], endianness, @backtrace when Array @data.inject(EncodedData.new) { |ed, d| ed << d.encode(endianness) } end # n times (0...@count).inject(EncodedData.new) { |ed, cnt| ed << edata } end