Class: ASMREPL::MacOS::Tracer
- Inherits:
-
Object
- Object
- ASMREPL::MacOS::Tracer
- Defined in:
- lib/asmrepl/macos.rb
Instance Method Summary collapse
- #continue ⇒ Object
-
#initialize(pid) ⇒ Tracer
constructor
A new instance of Tracer.
- #state ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(pid) ⇒ Tracer
Returns a new instance of Tracer.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/asmrepl/macos.rb', line 158 def initialize pid @pid = pid @target = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) unless MacOS.task_for_pid(MacOS.mach_task_self, pid, @target.ref).zero? raise "Couldn't get task pid. Did you run with sudo?" end @thread_list = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) thread_count = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) raise unless MacOS.task_threads(@target, @thread_list.ref, thread_count).zero? @thread = Fiddle::Pointer.new(@thread_list[0, Fiddle::SIZEOF_VOIDP].unpack1("l!")) end |
Instance Method Details
#continue ⇒ Object
198 199 200 201 202 |
# File 'lib/asmrepl/macos.rb', line 198 def continue unless MacOS.ptrace(MacOS::PT_CONTINUE, @pid, 1, 0).zero? raise end end |
#state ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/asmrepl/macos.rb', line 178 def state # Probably should use this for something # count = thread_count[0] # I can't remember what header I found this in, but it's from a macOS header # :sweat-smile: x86_THREAD_STATE64_COUNT = ThreadState.sizeof / Fiddle::SIZEOF_INT # Same here x86_THREAD_STATE64 = 4 state_count = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT64_T) state_count[0, Fiddle::SIZEOF_INT64_T] = [x86_THREAD_STATE64_COUNT].pack("l!") state = ThreadState.malloc raise unless MacOS.thread_get_state(@thread, x86_THREAD_STATE64, state, state_count).zero? state end |
#wait ⇒ Object
174 175 176 |
# File 'lib/asmrepl/macos.rb', line 174 def wait Process.waitpid @pid end |