Class: Indis::Segment

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

Overview

Note:

this class is heavily based on Mach-O

A segment describes one given segment contained in the target binary. Segment’s virtual size might be different from physical (stored in file), in this case the data is padded with zeroes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, name, vmaddr, vmsize, iooff, bytes) ⇒ Segment

Returns a new instance of Segment.

Parameters:

  • target (Indis::Target)

    the target containing a segment

  • name (String)

    segment name

  • vmaddr (Fixnum)

    starting virtual address

  • vmsize (Fixnum)

    size (in bytes)

  • iooff (Fixnum)

    offset from the beginning of of file to segment data

  • bytes (String)

    known data bytes (loaded from binary)



51
52
53
54
55
56
57
58
59
60
# File 'lib/indis-core/segment.rb', line 51

def initialize(target, name, vmaddr, vmsize, iooff, bytes)
  @target = target
  @name = name
  @sections = []
  
  @vmaddr = vmaddr
  @vmsize = vmsize
  @iooff = iooff
  @bytes = pad_bytes(bytes)
end

Instance Attribute Details

#bytesString (readonly)

The whole (zero-padded if required) bytes string for a segment

Returns:



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

def bytes
  @bytes
end

#iooffFixnum (readonly)

Returns offset from the beginning of of file to segment data.

Returns:

  • (Fixnum)

    offset from the beginning of of file to segment data



43
44
45
# File 'lib/indis-core/segment.rb', line 43

def iooff
  @iooff
end

#nameString (readonly)

Returns segment name.

Returns:



33
34
35
# File 'lib/indis-core/segment.rb', line 33

def name
  @name
end

#sectionsArray<Indis::Section> (readonly)

Contains a list of current segment sections

Returns:



29
30
31
# File 'lib/indis-core/segment.rb', line 29

def sections
  @sections
end

#targetIndis::Target (readonly)

Returns owning target.

Returns:



31
32
33
# File 'lib/indis-core/segment.rb', line 31

def target
  @target
end

#vmaddrFixnum (readonly)

Returns starting virtual address.

Returns:

  • (Fixnum)

    starting virtual address



35
36
37
# File 'lib/indis-core/segment.rb', line 35

def vmaddr
  @vmaddr
end

#vmsizeFixnum (readonly)

Returns segment size.

Returns:



37
38
39
# File 'lib/indis-core/segment.rb', line 37

def vmsize
  @vmsize
end

Instance Method Details

#to_vmrangeRange

Constructs a Range of virtual addresses used by segment

Returns:

  • (Range)

    the range of all addresses



65
66
67
# File 'lib/indis-core/segment.rb', line 65

def to_vmrange
  @vmaddr...(@vmaddr+@vmsize)
end