class Ptrace::RegSet

# ———————————————————————– The CPU registers for the process. This acts as a Hash mapping register names to contents. The Hash acts as a snapshot of the CPU state; the registers are read from the process using read(), and written to the process using write().

Usage:

regs = RegSet.new(RegSet::GEN, pid)
regs.read
puts regs.inspect
regs['eax'] = 0x0
regs.write

Constants

EXT

Extended floating-point register set (fpx on Linux).

FP

Floating-point register set (ST(0) and friends in x86).

GEN

General register set (EAX and friends in x86).

GETTER_SYMS

Method names for read accessor, keyed by register type.

SETTER_SYMS

Method names for write accessor, keyed by register type.

TYPES

Valid register set types.

Attributes

pid[R]

PID of process owning this register set.

reg_type[R]

Type of this register set.

Public Class Methods

new(type, pid) click to toggle source

Create a new register set of the specified type for process 'pid'.

# File lib/Ptrace.rb, line 260
def initialize(type, pid)
  @reg_type = type
  @getter = GETTER_SYMS[type]
  @setter = SETTER_SYMS[type]
  @pid = pid
  @regs = {}
end

Public Instance Methods

read() click to toggle source

Read the current state of the CPU registers from the process. This fills the contents of the RegSet Hash, and returns the Hash. This can raise an OperationNotPermittedError if access is denied, or an InvalidProcessError if the target process has exited.

# File lib/Ptrace.rb, line 274
def read
  @regs = ptrace_send(@getter)
end
write() click to toggle source

Write the contents of the RegSet Hash to the process CPU registers. This can raise an OperationNotPermittedError if access is denied, or an InvalidProcessError if the target process has exited.

# File lib/Ptrace.rb, line 283
def write
  ptrace_send(@setter, @regs)
end

Private Instance Methods

ptrace_send( sym, arg=nil ) click to toggle source
# File lib/Ptrace.rb, line 296
def ptrace_send( sym, arg=nil )
  begin
    args = [@pid]
    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