Class: Ragweed::Wraposx::RegionInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ragweed/wraposx/region_info.rb

Overview

Memory region info base class. Currently Apple only supports the basic flavor. The other two flavors are included for completeness.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = nil) ⇒ RegionInfo

Returns a new instance of RegionInfo.



46
47
48
# File 'lib/ragweed/wraposx/region_info.rb', line 46

def initialize(str=nil)
  refresh(str) if str
end

Class Method Details

.get(t, a, flavor) ⇒ Object



66
67
68
# File 'lib/ragweed/wraposx/region_info.rb', line 66

def self.get(t, a, flavor)
  self.new(Ragweed::Wraposx::vm_region_raw(t, a, flavor))
end

Instance Method Details

#dump(&block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ragweed/wraposx/region_info.rb', line 84

def dump(&block)
  maybe_hex = lambda {|a| begin; "\n" + (" " * 9) + block.call(a, 16).hexdump(true)[10..-2]; rescue; ""; end }      
  maybe_dis = lambda {|a| begin; "\n" + block.call(a, 16).distorm.map {|i| "         " + i.mnem}.join("\n"); rescue; ""; end }

  string ="  -----------------------------------------------------------------------\n  INFO:\n  protection:       \#{self.protection.to_s(2).rjust(8, \"0\")} \#{Ragweed::Wraposx::Vm::Pflags.flag_dump(self.protection)}\n  max_protection:   \#{self.max_protection.to_s(2).rjust(8, \"0\")} \#{Ragweed::Wraposx::Vm::Pflags.flag_dump(self.max_protection)}\n  inheritance:      \#{self.inheritance.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.inheritance)}\n  shared:           \#{self.shared.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.shared)}\n  reserved:         \#{self.reserved.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.reserved)}\n  offset:           \#{self.offset.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.offset)}\n  behavior:         \#{self.behavior.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.behavior)}\n  user_wired_count: \#{self.user_wired_count.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.user_wired_count)}\n  address:          \#{self.address.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.address)}\n  size:             \#{self.size.to_s(16).rjust(8, \"0\")} \#{maybe_hex.call(self.size)}\n"
end

#get(t, a) ⇒ Object



70
71
72
# File 'lib/ragweed/wraposx/region_info.rb', line 70

def get(t, a)
  refresh(Ragweed::Wraposx::vm_region_raw(t, a, self.class.const_get(:FLAVOR)))
end

#inspectObject



74
75
76
77
78
79
80
81
82
# File 'lib/ragweed/wraposx/region_info.rb', line 74

def inspect
  fields = self.class.const_get(:FIELDS)
  body = lambda do
    fields.map do |f|
      "#{f[0]}=#{send(f[0]).to_s}"
    end.join(", ")
  end
  "#<#{self.class.name.split("::").last} #{body.call}>"
end

#refresh(str) ⇒ Object

(re)loads the data from str



51
52
53
54
55
56
57
58
59
# File 'lib/ragweed/wraposx/region_info.rb', line 51

def refresh(str)
  fields = self.class.const_get :FIELDS
  if str and not str.empty?
    str.unpack(fields.map {|x| x[1]}.join("")).each_with_index do |val, i|
      raise "i is nil" if i.nil?
      instance_variable_set "@#{ fields[i][0] }".intern, val
    end            
  end
end

#to_sObject



61
62
63
64
# File 'lib/ragweed/wraposx/region_info.rb', line 61

def to_s
  fields = self.class.const_get :FIELDS
  fields.map {|f| send(f[0])}.pack(fields.map {|x| x[1]}.join(""))
end