Class: Indis::DataEntity

Inherits:
Entity
  • Object
show all
Defined in:
lib/indis-core/data_entity.rb

Overview

DataEntity represens “data bytes” that are directly used e.g. in a load to register instruction. There are four sizes of data: 8, 16, 32 and 64 bits long, namely byte, word, dword and qword

Constant Summary collapse

KIND =
{
  1 => :byte,
  2 => :word,
  4 => :dword,
  8 => :qword,
}
NAMED_TYPE =
{
  byte:  'DCB',
  word:  'DCW',
  dword: 'DCD',
  qword: 'DCQ'
}

Instance Attribute Summary collapse

Attributes inherited from Entity

#size, #tags, #vmaddr

Instance Method Summary collapse

Methods inherited from Entity

#unmap

Constructor Details

#initialize(ofs, size, vmmap) ⇒ DataEntity

Returns a new instance of DataEntity.

Parameters:

  • ofs (Fixnum)

    virtual address

  • size (Fixnum)

    entity size in bytes

  • vmmap (Indus::VMMap)

    map of the target to load value from

Raises:

  • (AttributeError)

    if the size is not one of the known values



47
48
49
50
51
52
# File 'lib/indis-core/data_entity.rb', line 47

def initialize(ofs, size, vmmap)
  raise ArgumentError, "Unaligned size" unless KIND[size]
  super ofs
  @size = size
  @value = vmmap.bytes_at(ofs, size).reverse_each.reduce(0) { |v, i| (v << 8) + i }
end

Instance Attribute Details

#valueFixnum (readonly)

Returns the value of entity.

Returns:

  • (Fixnum)

    the value of entity



41
42
43
# File 'lib/indis-core/data_entity.rb', line 41

def value
  @value
end

Instance Method Details

#kindKIND

Returns entity kind.

Returns:

  • (KIND)

    entity kind



55
56
57
# File 'lib/indis-core/data_entity.rb', line 55

def kind
  KIND[@size]
end

#to_aObject



63
64
65
# File 'lib/indis-core/data_entity.rb', line 63

def to_a
  [NAMED_TYPE[kind], sprintf("%0#{@size*2}X", @value)]
end

#to_sObject



59
60
61
# File 'lib/indis-core/data_entity.rb', line 59

def to_s
  "#{NAMED_TYPE[kind]}\t#{sprintf("%0#{@size*2}X", @value)}"
end