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)


84
85
86
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 84

def break_process
  raise "nyi"
end

#continue_debug_event(flags, thread_ids = []) ⇒ self

Continues the target process.

Parameters:

Returns:

  • (self)


91
92
93
94
# 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

#get_debug_eventSwitch::Debug::Event?

Gets a debug event from the target process.

Returns:



66
67
68
69
70
71
72
73
74
# 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

#get_nso_infosArray<Hash>

Queries NSO info for the target process.

Returns:

  • (Array<Hash>)


104
105
106
107
108
109
110
111
# 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

#get_thread_context(thread_id) ⇒ String

Gets a thread’s context.

Returns:

  • (String)


78
79
80
# 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

#list_threadsself

Lists threads in the target process.

Returns:

  • (self)


60
61
62
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 60

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
46
47
# 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

#set_thread_context(thread_id) ⇒ self

Sets a thread’s context.

Returns:

  • (self)


98
99
100
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 98

def set_thread_context(thread_id)
  raise "nyi"
end

#wait_eventself

Waits for a debug event to become available.

Returns:

  • (self)


122
123
124
125
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 122

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)


115
116
117
118
# File 'lib/twib/interfaces/ITwibDebugger.rb', line 115

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)


53
54
55
56
# 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