module Ragweed; end module Ragweed::Wraposx; end module Ragweed::Wraposx::Vm # these are flavor arguments for vm_region # more to be added as support for 64bit processes gets added REGION_BASIC_INFO = 10 REGION_EXTENDED_INFO = 11 REGION_TOP_INFO = 12 # behavior identifiers BEHAVIOR_DEFAULT = 0 # /* default */ BEHAVIOR_RANDOM = 1 # /* random */ BEHAVIOR_SEQUENTIAL = 2 # /* forward sequential */ BEHAVIOR_RSEQNTL = 3 # /* reverse sequential */ BEHAVIOR_WILLNEED = 4 # /* will need in near future */ BEHAVIOR_DONTNEED = 5 # /* dont need in near future */ #Virtual memory map inheritance values for vm_inherit_t INHERIT_SHARE = 0 # /* share with child */ INHERIT_COPY = 1 # /* copy into child */ INHERIT_NONE = 2 # /* absent from child */ INHERIT_DONATE_COPY = 3 # /* copy and delete */ INHERIT_DEFAULT = 1 # VM_INHERIT_COPY INHERIT_LAST_VALID = 2 # VM_INHERIT_NONE #define VM_REGION_BASIC_INFO_COUNT ((mach_msg_type_number_t) (sizeof(vm_region_basic_info_data_t)/sizeof(int))) #define VM_REGION_EXTENDED_INFO_COUNT ((mach_msg_type_number_t) (sizeof(vm_region_extended_info_data_t)/sizeof(int))) #define VM_REGION_TOP_INFO_COUNT ((mach_msg_type_number_t) (sizeof(vm_region_top_info_data_t)/sizeof(int))) FLAVORS = { REGION_BASIC_INFO => {:size => 30, :count => 8}, REGION_EXTENDED_INFO => {:size => 32, :count => 8}, REGION_TOP_INFO => {:size => 17,:count => 5} } module Pflags READ = 0x1 #read permission WRITE = 0x2 #write permission EXECUTE = 0x4 #execute permission end end # Memory region info base class. # # to change slightly in 0.2.0+ # class Ragweed::Wraposx::RegionInfo def initialize(str=nil) refresh(str) if str end # (re)loads the data from str 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 def to_s fields = self.class.const_get :FIELDS fields.map {|f| send(f[0])}.pack(fields.map {|x| x[1]}.join("")) end def self.get(t, a, flavor) self.new(Ragweed::Wraposx::vm_region_raw(t, a, flavor)) end def get(t, a) refresh(Ragweed::Wraposx::vm_region_raw(t, a, self.class.const_get(:FLAVOR))) end 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 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 =<