Class: Ptrace::MemArea

Inherits:
Object
  • Object
show all
Defined in:
lib/Ptrace.rb

Overview

A region of Memory in the target process.

Usage:

mem = MemArea.new(MemArea::DATA, pid)
val = mem.peek(0x0804100)
mem.poke(0x0804100, 0x0)

Constant Summary collapse

MEM_USER =

Target user area.

1
MEM_TEXT =

Target text (code) area.

2
MEM_DATA =

Target data area.

3
TYPES =

Valid memory region types.

[MEM_USER, MEM_TEXT, MEM_DATA]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, pid) ⇒ MemArea

Create a new memory region of the specified type for process ‘pid’.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/Ptrace.rb', line 120

def initialize(type, pid)
  @mem_type = type
  @pid = pid
  case type
    when MEM_USER
      @getter_sym = :peekusr
      @setter_sym = :pokeusr
    when MEM_TEXT
      @getter_sym = :peektext
      @setter_sym = :poketext
    when MEM_DATA
      @getter_sym = :peekdata
      @setter_sym = :pokedata
  end
end

Instance Attribute Details

#mem_typeObject (readonly)

Type of memory region.



111
112
113
# File 'lib/Ptrace.rb', line 111

def mem_type
  @mem_type
end

#pidObject (readonly)

PID of process owning this memory region.



115
116
117
# File 'lib/Ptrace.rb', line 115

def pid
  @pid
end

Instance Method Details

#peek(addr) ⇒ Object

Read a word of data from address ‘addr’ in memory region. This can raise an OperationNotPermittedError if access is denied, or an InvalidProcessError if the target process has exited.



141
142
143
# File 'lib/Ptrace.rb', line 141

def peek(addr)
  ptrace_send(:peek, @getter_sym, addr)
end

#poke(addr, value) ⇒ Object

Write a word of data to address ‘addr’ in memory region. This can raise an OperationNotPermittedError if access is denied, or an InvalidProcessError if the target process has exited.



150
151
152
# File 'lib/Ptrace.rb', line 150

def poke(addr, value)
  ptrace_send(:poke, @setter_sym, addr, value)
end