Class: Twib::Interfaces::ITwibDebugger
- Inherits:
-
Twib::Interface
- Object
- Twib::Interface
- Twib::Interfaces::ITwibDebugger
- Defined in:
- lib/twib/interfaces/ITwibDebugger.rb
Overview
Debug interface bound to a specific process.
Defined Under Namespace
Modules: Command
Instance Method Summary collapse
-
#break_process ⇒ self
Breaks the target process.
-
#continue_debug_event(flags, thread_ids = []) ⇒ self
Continues the target process.
-
#get_debug_event ⇒ Switch::Debug::Event?
Gets a debug event from the target process.
-
#get_nso_infos ⇒ Array<Hash>
Queries NSO info for the target process.
-
#get_thread_context(thread_id) ⇒ String
Gets a thread’s context.
-
#list_threads ⇒ self
Lists threads in the target process.
-
#query_memory(addr) ⇒ Hash
Queries process segment information at the given address.
-
#read_memory(addr, size) ⇒ String
Reads from process memory at the given address.
-
#set_thread_context(thread_id) ⇒ self
Sets a thread’s context.
-
#wait_event ⇒ self
Waits for a debug event to become available.
-
#wait_event_async(&block) ⇒ self
Yields from a separate thread when a debug event is available.
-
#write_memory(addr, string) ⇒ String
Writes to process memory at the given address.
Methods inherited from Twib::Interface
Constructor Details
This class inherits a constructor from Twib::Interface
Instance Method Details
#break_process ⇒ self
Breaks the target process.
82 83 84 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 82 def break_process raise "nyi" end |
#continue_debug_event(flags, thread_ids = []) ⇒ self
Continues the target process.
89 90 91 92 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 89 def continue_debug_event(flags, thread_ids=[]) send(Command::CONTINUE_DEBUG_EVENT, ([flags] + thread_ids).pack("L<Q<*")).wait_ok self end |
#get_debug_event ⇒ Switch::Debug::Event?
Gets a debug event from the target process.
64 65 66 67 68 69 70 71 72 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 64 def get_debug_event rs = send(Command::GET_DEBUG_EVENT).wait if rs.result_code == 0x8c01 then # no debug events left return nil else rs.assert_ok end return Switch::Debug::Event::Event.unpack(rs.payload) end |
#get_nso_infos ⇒ Array<Hash>
Queries NSO info for the target process.
102 103 104 105 106 107 108 109 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 102 def get_nso_infos response = send(Command::GET_NSO_INFOS).wait_ok.payload count = response.unpack("Q<")[0] count.times.map do |i| Hash[ [:base, :size, :build_id].zip(response[8 + 0x30 * i, 0x30].unpack("Q<Q<a32"))] end end |
#get_thread_context(thread_id) ⇒ String
Gets a thread’s context.
76 77 78 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 76 def get_thread_context(thread_id) send(Command::GET_THREAD_CONTEXT, [thread_id].pack("Q<")).wait_ok.payload end |
#list_threads ⇒ self
Lists threads in the target process.
58 59 60 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 58 def list_threads raise "nyi" end |
#query_memory(addr) ⇒ Hash
Queries process segment information at the given address.
debug.query_memory(0)
# => {:base=>0, :size=>62308483072, :memory_type=>0,
# :memory_attribute=>0, :permission=>0,
# :device_ref_count=>0, :ipc_ref_count=>0}
32 33 34 35 36 37 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 32 def query_memory(addr) Hash[ [:base, :size, :memory_type, :memory_attribute, :permission, :device_ref_count, :ipc_ref_count].zip( send(Command::QUERY_MEMORY, [addr].pack("Q<")).wait_ok.payload.unpack("Q<Q<L<L<L<L<L<"))] end |
#read_memory(addr, size) ⇒ String
Reads from process memory at the given address.
43 44 45 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 43 def read_memory(addr, size) send(Command::READ_MEMORY, [addr, size].pack("Q<Q<")).wait_ok.payload end |
#set_thread_context(thread_id) ⇒ self
Sets a thread’s context.
96 97 98 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 96 def set_thread_context(thread_id) raise "nyi" end |
#wait_event ⇒ self
Waits for a debug event to become available.
120 121 122 123 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 120 def wait_event send(Command::WAIT_EVENT).wait_ok self end |
#wait_event_async(&block) ⇒ self
Yields from a separate thread when a debug event is available.
113 114 115 116 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 113 def wait_event_async(&block) send(Command::WAIT_EVENT, String.new, &block) self end |
#write_memory(addr, string) ⇒ String
Writes to process memory at the given address.
51 52 53 54 |
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 51 def write_memory(addr, string) send(Command::WRITE_MEMORY, [addr].pack("Q<") + string).wait_ok string end |