IDAPython 将操作码的十六进制转储到文件
IDAPython dump hex pres of opcode to file
我尝试将操作码旁边的十六进制表示转储到文本文件中,但我还没有真正成功。这是现在的样子:
.init_proc start: 6a0 end: 6b0
6a0 å-à PUSH {LR}; _init
6a4 ëO BL frame_dummy
6a8 ë¨ BL __do_global_ctors_aux
6ac äð POP {PC}
strerror start: 6c4 end: 6d0
6c4 âÆ ADR R12, 0x6CC
6c8 âŒÊ ADD R12, R12, #0x8000
6cc å¼þ` LDR PC, [R12,#(strerror_ptr - 0x86CC)]!; __imp_strerror
不幸的是,get_bytes函数只returns一个字符串而不是一个整数,所以
我无法将其转换为十六进制。还有其他方法吗?
这是我的 idapython 脚本:
cur_addr = 0
with open("F:/Ida_scripts/ida_output.txt", "w") as f:
for func in Functions():
start = get_func_attr(func, FUNCATTR_START)
end = get_func_attr(func, FUNCATTR_END)
f.write("%s\t start: %x\t end: %x" % (get_func_name(func), start, end))
cur_addr = start
while cur_addr <= end:
f.write("\n%x\t%s\t%s" % (curr_addr, get_bytes(cur_addr, get_item_size(curr_addr)), generate_disasm_line(cur_addr, 0)))
cur_addr = next_head(cur_addr, end)
f.write("\n\n")
如果 get_bytes()
return 是一个字符串,那么我假设您想将该字符串中的每个字节都转换为十六进制并打印出来。试试这个:
print(' '.join('%02x' % ord(c) for c in get_bytes(…))
这将打印如下内容:
61 62 63 64
(对于 'abcd'
作为输入。)
或作为函数:
def str_to_hex(s):
return ' '.join('%02x' % ord(c) for c in s)
请注意,在 Python3 中,str
类型是 unicode 数据类型,因此每个字符不仅仅是一个字节;你有字节数组的 bytes
类型(也许你的 get_bytes()
应该 return 这个而不是字符串)。在 Python2 中,str
类型是字节数组,unicode
类型是 unicode 字符串。我不知道你在哪个 Python 版本开发。
我尝试将操作码旁边的十六进制表示转储到文本文件中,但我还没有真正成功。这是现在的样子:
.init_proc start: 6a0 end: 6b0
6a0 å-à PUSH {LR}; _init
6a4 ëO BL frame_dummy
6a8 ë¨ BL __do_global_ctors_aux
6ac äð POP {PC}
strerror start: 6c4 end: 6d0
6c4 âÆ ADR R12, 0x6CC
6c8 âŒÊ ADD R12, R12, #0x8000
6cc å¼þ` LDR PC, [R12,#(strerror_ptr - 0x86CC)]!; __imp_strerror
不幸的是,get_bytes函数只returns一个字符串而不是一个整数,所以 我无法将其转换为十六进制。还有其他方法吗? 这是我的 idapython 脚本:
cur_addr = 0
with open("F:/Ida_scripts/ida_output.txt", "w") as f:
for func in Functions():
start = get_func_attr(func, FUNCATTR_START)
end = get_func_attr(func, FUNCATTR_END)
f.write("%s\t start: %x\t end: %x" % (get_func_name(func), start, end))
cur_addr = start
while cur_addr <= end:
f.write("\n%x\t%s\t%s" % (curr_addr, get_bytes(cur_addr, get_item_size(curr_addr)), generate_disasm_line(cur_addr, 0)))
cur_addr = next_head(cur_addr, end)
f.write("\n\n")
如果 get_bytes()
return 是一个字符串,那么我假设您想将该字符串中的每个字节都转换为十六进制并打印出来。试试这个:
print(' '.join('%02x' % ord(c) for c in get_bytes(…))
这将打印如下内容:
61 62 63 64
(对于 'abcd'
作为输入。)
或作为函数:
def str_to_hex(s):
return ' '.join('%02x' % ord(c) for c in s)
请注意,在 Python3 中,str
类型是 unicode 数据类型,因此每个字符不仅仅是一个字节;你有字节数组的 bytes
类型(也许你的 get_bytes()
应该 return 这个而不是字符串)。在 Python2 中,str
类型是字节数组,unicode
类型是 unicode 字符串。我不知道你在哪个 Python 版本开发。