【问题标题】:Convert instructions to op code bytes in python script for IDA Pro在 IDA Pro 的 python 脚本中将指令转换为操作码字节
【发布时间】:2022-11-13 12:10:27
【问题描述】:

我需要将我反汇编的指令转换为操作代码字节,但我找不到可以让我这样做的函数,我试过 idc.get_bytes 但它似乎不起作用。

这是我的python脚本:

import sys
import idc
import idautils

f = open(idc.ARGV[1], 'w') if len(idc.ARGV) > 1 else sys.stdout
log = f.write

# log current file path
log(idc.get_input_file_path() + '\n')

# wait for auto-analysis to complete
idc.auto_wait()

# count functions
log( 'count %d\n' % len(list(idautils.Functions())) )

for func in idautils.Functions():
    flags = idc.get_func_attr(func, FUNCATTR_FLAGS)
    if flags & FUNC_LIB or flags & FUNC_THUNK:
        continue
    dism_addr = list(idautils.FuncItems(func))
    for line in dism_addr:
        #log(idc.print_insn_mnem(line) + '\n' )
        disass = idc.generate_disasm_line(line, 0)
        log(disass + '\n' )

# if logging to a file, close it and exit IDA Pro
if f != sys.stdout:
    f.close()
    idc.qexit(0)

我在 IDA Pro 7.7sp1 的批处理模式下使用这个脚本,你能建议我一个方法吗? 先感谢您。

【问题讨论】:

标签: python reverse-engineering ida


【解决方案1】:

那么,像这样的事情?

def GetFuncHeads(funcea=None):
    """
    Get all heads in a function

    @param funcea: any address in the function
    """
    func = ida_funcs.get_func(funcea)
    if not func:
        return []
    else:
        funcea = func.start_ea

    ea = funcea

    heads = []
    for start, end in idautils.Chunks(funcea):
        heads.extend([head for head in idautils.Heads(start, end)])

    return heads

def GetInsnLen(ea):
    insn = ida_ua.insn_t()
    inslen = ida_ua.decode_insn(insn, ea)
    if inslen:
        return inslen
    return 0

opcodes = [idc.get_bytes(ea, GetInsnLen(ea)) for ea in GetFuncHeads(here())]

【讨论】:

    猜你喜欢
    • 2014-01-04
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2011-01-16
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多