class Ptrace::MemArea
# ———————————————————————– A region of Memory in the target process.
Usage:
mem = MemArea.new(MemArea::DATA, pid) val = mem.peek(0x0804100) mem.poke(0x0804100, 0x0)
Constants
Attributes
mem_type[R]
Type of memory region.
pid[R]
PID of process owning this memory region.
Public Class Methods
new(type, pid)
click to toggle source
Create a new memory region of the specified type for process 'pid'.
# 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
Public Instance Methods
peek(addr)
click to toggle source
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.
# File lib/Ptrace.rb, line 141 def peek(addr) ptrace_send(:peek, @getter_sym, addr) end
poke(addr, value)
click to toggle source
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.
# File lib/Ptrace.rb, line 150 def poke(addr, value) ptrace_send(:poke, @setter_sym, addr, value) end
Private Instance Methods
ptrace_send( sym, cmd, addr, arg=nil )
click to toggle source
# File lib/Ptrace.rb, line 156 def ptrace_send( sym, cmd, addr, arg=nil ) begin raise OperationNotSupportedError if (not PTRACE_COMMANDS.include? cmd) args = [PTRACE_COMMANDS[cmd], @pid, addr] args << arg if arg Debugger.send( sym, *args ) rescue RuntimeError => e case e.message when 'PTRACE: Operation not permitted' raise OperationNotPermittedError.new(e.message) when 'PTRACE: No such process' raise InvalidProcessError.new(e.message) else raise end end end