Skip to content

Commit

Permalink
ida: set_decompiler_comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyg committed Dec 11, 2023
1 parent 06adbc4 commit 7cde25f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions samples/ida/idaclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def self.add_command(name, *rq_args, &postprocess)
add_command('exit_ida', :exit_code0, :can_ignore_ret) { |s| s == "bye" }
add_command('get_comment', :addr) { |s| s if s != '' }
add_command('set_comment', :addr, :comment, :can_ignore_ret) { |s| s == "ok" }
add_command('set_decompiler_comment', :addr, :comment, :can_ignore_ret) { |s| s == "ok" }
add_command('get_cursor_pos') { |a| addr(a) }
add_command('set_cursor_pos', :addr, :can_ignore_ret) { |s| s == "ok" }
add_command('get_selection') { |lst| lst.split.map { |a| addr(a) } }
Expand All @@ -134,6 +135,8 @@ def self.add_command(name, *rq_args, &postprocess)
add_command('get_segment_start', :addr) { |a| addr(a) }
add_command('get_segment_end', :addr) { |a| addr(a) }
add_command('get_segment_name', :addr) { |s| s if s != '' }
add_command('set_segment_name', :addr, :name) { |s| s == "ok" }
add_command('add_segment_fromfile', :path, :off, :addr, :len) { |s| s == "ok" }
add_command('get_op_mnemonic', :addr) { |s| s if s != '' }
add_command('make_align', :addr, :count, :align, :can_ignore_ret) { |s| s == "ok" }
add_command('make_array', :addr, :count, :can_ignore_ret) { |s| s == "ok" }
Expand All @@ -143,6 +146,7 @@ def self.add_command(name, *rq_args, &postprocess)
add_command('make_qword', :addr, :can_ignore_ret) { |s| s == "ok" }
add_command('make_string', :addr_start, :len0, :type0, :can_ignore_ret) { |s| s == "ok" }
add_command('make_code', :addr, :can_ignore_ret) { |s| s == "ok" }
add_command('make_func', :addr, :can_ignore_ret) { |s| s == "ok" }
add_command('undefine', :addr, :can_ignore_ret) { |s| s == "ok" }
add_command('patch_byte', :addr, :newbyte, :can_ignore_ret) { |s| s == "ok" }
add_command('get_input_path') { |s| s if s != '' }
Expand Down
36 changes: 35 additions & 1 deletion samples/ida/idaremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# remote control for IDA using a text protocol
# by default listens on localhost:56789
# tested with IDA7.3, IDA7.4
# tested with IDA7.3, IDA7.5, IDA8.1
# to stop, run 'idaremote.quit()' from within IDA

class IdaRemote:
Expand Down Expand Up @@ -204,6 +204,18 @@ def cmd_set_comment(self, addr, cmt):
return "ok"
return ""

# set a decompiler comment
def cmd_set_decompiler_comment(self, addr, cmt):
ea = int(addr, 0)
cfunc = idaapi.decompile(ea)
tl = idaapi.treeloc_t()
tl.ea = ea
# add comment after semicolon, will not show on if() line
tl.itp = idaapi.ITP_SEMI
cfunc.set_user_cmt(tl, cmt)
cfunc.save_user_cmts()
return "ok"

# return the current cursor address (ScreenEA)
def cmd_get_cursor_pos(self):
return self.fmt_addr(idc.get_screen_ea())
Expand Down Expand Up @@ -299,6 +311,24 @@ def cmd_get_segment_end(self, a):
def cmd_get_segment_name(self, a):
return idc.get_segm_name(int(a, 0))

# rename a segment (a address, n newname)
def cmd_set_segment_name(self, a, n):
if idc.set_segm_name(int(a, 0), n):
return "ok"
return ""

# load an existing binary file as new ida segment
# seek file to foff, load at address a, length l
def cmd_add_segment_fromfile(self, path, foff, a, l):
if idc.loadfile(path, int(foff, 0), int(a, 0), int(l, 0)):
# create a segment covering the new data
segtype = 1 # 32b
if idaapi.get_inf_structure().is_64bit():
segtype = 2 # 64b
idc.add_segm_ex(int(a, 0), int(a, 0)+int(l, 0), 0, segtype, 0, 0, 0)
return "ok"
return ""

# return the mnemonic of an opcode at addr
def cmd_get_op_mnemonic(self, a):
return idc.print_insn_mnem(int(a, 0))
Expand Down Expand Up @@ -336,6 +366,10 @@ def cmd_make_string(self, a, len, kind):
def cmd_make_code(self, a):
return str(idc.create_insn(int(a, 0)))

# tell IDA to create a function
def cmd_make_func(self, a):
return str(ida_funcs.add_func(int(a, 0)))

# undefine at an address
# for code, undefine following instructions too
def cmd_undefine(self, a):
Expand Down

0 comments on commit 7cde25f

Please sign in to comment.