【问题标题】:How do i export the binary code of a function in Ghidra (Ghidra script)如何在 Ghidra 中导出函数的二进制代码(Ghidra 脚本)
【发布时间】:2020-12-04 17:59:36
【问题描述】:

我想在 python (jython) 中编写一个 ghidra 脚本,将当前程序中所有函数的二进制代码导出到一个 .bin 文件。

我想出了这段代码,但我不确定如何在BinaryExporter 类中使用 export() 函数

函数签名:export(java.io.File file, DomainObject domainObj, AddressSetView addrSet, TaskMonitor monitor)

我应该如何填写参数?有没有更好的方法来做到这一点?

from ghidra.app.util.exporter import BinaryExporter


function_ASVs = [] #all functions address set view
exporter = BinaryExporter()

fm = currentProgram.getFunctionManager()
functions = fm.getFunctions(True)
for f in functions:
    function_ASVs.append(f.getBody())


with open("C:\Users\Me\Desktop\target_file.bin", "w") as f:
    for asv in function_ASVs:
        ret = exporter.export(f, currentProgram, asv, ???)

【问题讨论】:

    标签: jython-2.7 ghidra


    【解决方案1】:

    monitor 是 GhidraScript 从 FlatProgramAPI 继承的字段。您问题中的??? 应该是monitor

    我不使用 python,但我认为您可以将脚本压缩为:

    from ghidra.app.util.exporter import BinaryExporter
    
    asv = AddressSet()
    exporter = BinaryExporter()
    
    for f in currentProgram.getFunctionManager().getFunctions(True):
        asv.add(f.getBody())
    
    with open("C:\Users\Me\Desktop\target_file.bin", "w") as f:
        ret = exporter.export(f, currentProgram, asv, monitor)
    

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 2021-11-16
      • 2019-12-09
      • 2021-11-14
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多