Class: Twib::Interfaces::ITwibDebugger

Inherits:
Twib::Interface show all
Defined in:
lib/twib/interfaces/ITwibDebugger.rb

Overview

Debug interface bound to a specific process.

Defined Under Namespace

Modules: Command

Instance Method Summary collapse

Methods inherited from Twib::Interface

#initialize, #send

Constructor Details

This class inherits a constructor from Twib::Interface

Instance Method Details

#break_processself

Breaks the target process.

Returns:

  • (self)


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.

Parameters:

Returns:

  • (self)


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_eventSwitch::Debug::Event?

Gets a debug event from the target process.

Returns:



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_infosArray<Hash>

Queries NSO info for the target process.

Returns:

  • (Array<Hash>)


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.

Returns:

  • (String)


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_threadsself

Lists threads in the target process.

Returns:

  • (self)


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}

Parameters:

  • addr (Integer)

    Address to query

Returns:

  • (Hash)


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.

Parameters:

  • addr (Integer)

    Address to read from

  • size (Integer)

    How many bytes to read

Returns:

  • (String)


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.

Returns:

  • (self)


96
97
98
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 96

def set_thread_context(thread_id)
  raise "nyi"
end

#wait_eventself

Waits for a debug event to become available.

Returns:

  • (self)


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.

Returns:

  • (self)


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.

Parameters:

  • addr (Integer)

    Address to write to

  • string (String)

    Data to write

Returns:

  • (String)


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