Skip to content

Commit

Permalink
set rip on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 7, 2021
1 parent 40b8561 commit d2bd569
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/asmrepl/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.jitbuffer size

# x86_64-linux-gnu/sys/ptrace.h
PTRACE_GETREGS = 12
PTRACE_SETREGS = 13

def self.traceme
raise unless ptrace(PTRACE_TRACEME, 0, 0, 0).zero?
Expand Down Expand Up @@ -86,6 +87,10 @@ class ThreadState
define_method(field) do
to_ptr[Fiddle::SIZEOF_INT64_T * i, Fiddle::SIZEOF_INT64_T].unpack1("l!")
end

define_method("#{field}=") do |v|
to_ptr[Fiddle::SIZEOF_INT64_T * i, Fiddle::SIZEOF_INT64_T] = [v].pack("l!")
end
end

define_singleton_method(:sizeof) do
Expand All @@ -98,6 +103,12 @@ def [] name
to_ptr[Fiddle::SIZEOF_INT64_T * idx, Fiddle::SIZEOF_INT64_T].unpack1("l!")
end

def []= name, val
idx = fields.index(name)
return unless idx
to_ptr[Fiddle::SIZEOF_INT64_T * idx, Fiddle::SIZEOF_INT64_T] = [val].pack("l!")
end

def self.malloc
new Fiddle::Pointer.malloc sizeof
end
Expand Down Expand Up @@ -176,6 +187,12 @@ def state
state
end

def state= state
raise unless Linux.ptrace(PTRACE_SETREGS, @pid, 0, state).zero?

state
end

def continue
unless Linux.ptrace(Linux::PTRACE_CONT, @pid, 1, 0).zero?
raise
Expand Down

0 comments on commit d2bd569

Please sign in to comment.