class Twib::Interfaces::ITwibDebugger
Debug interface bound to a specific process.
Public Instance Methods
Breaks the target process. @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 84 def break_process raise "nyi" end
Continues the target process. @param flags [Integer] See www.switchbrew.org/index.php?title=SVC#ContinueDebugFlagsOld @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 91 def continue_debug_event(flags, thread_ids=[]) send(Command::CONTINUE_DEBUG_EVENT, ([flags, thread_ids.length] + thread_ids).pack("L<Q<Q<*")).wait_ok self end
Gets a debug event from the target process. @return [Switch::Debug::Event, nil] A debug event, or nil if none were left
# File lib/twib/interfaces/ITwibDebugger.rb, line 66 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
Queries NSO info for the target process. @return [Array<Hash>]
# File lib/twib/interfaces/ITwibDebugger.rb, line 104 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
Gets a thread's context. @return [String]
# File lib/twib/interfaces/ITwibDebugger.rb, line 78 def get_thread_context(thread_id) send(Command::GET_THREAD_CONTEXT, [thread_id].pack("Q<")).wait_ok.payload end
Lists threads in the target process. @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 60 def list_threads raise "nyi" end
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}
@param addr [Integer] Address to query @return [Hash]
# 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
Reads from process memory at the given address. @param addr [Integer] Address to read from @param size [Integer] How many bytes to read @return [String]
# File lib/twib/interfaces/ITwibDebugger.rb, line 43 def read_memory(addr, size) response = send(Command::READ_MEMORY, [addr, size].pack("Q<Q<")).wait_ok.payload length = response.unpack("Q<")[0] return response[8, length] end
Sets a thread's context. @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 98 def set_thread_context(thread_id) raise "nyi" end
Waits for a debug event to become available. @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 122 def wait_event send(Command::WAIT_EVENT).wait_ok self end
Yields from a separate thread when a debug event is available. @return [self]
# File lib/twib/interfaces/ITwibDebugger.rb, line 115 def wait_event_async(&block) send(Command::WAIT_EVENT, String.new, &block) self end
Writes to process memory at the given address. @param addr [Integer] Address to write to @param string [String] Data to write @return [String]
# File lib/twib/interfaces/ITwibDebugger.rb, line 53 def write_memory(addr, string) send(Command::WRITE_MEMORY, [addr, string.bytesize].pack("Q<Q<") + string).wait_ok string end