这个 Python 命令行工具会反编译二进制文件中的所有函数,并将它们以单独的 C 文件形式写入目录:```mermaid
flowchart LR
a(filename ) --> b[ghidrecomp] a2[(Symbol Server)] --> b
b --> e(Ghidra Project Files) b --> output
subgraph output
subgraph decompilations direction LR i(func1.c) h(func2.c) f(funcB.c) end
subgraph callgraphs direction LR j(callgraph1.md) k(callgraph2.md) l(callgraphN.md) end
subgraph bsim-xml direction LR n(sig-md5-bin1.xml) m(sig-md5-bin2.xml) o(sig-md5-binN.xml) end
end
或者,对单个 `C` 文件和头文件使用 `--cppexport`:```mermaid
flowchart LR
a(filename ) --> b[ghidrecomp]
a2[(Symbol Server)] --> b
b --> e(Ghidra Project Files)
b --> singlefile
subgraph singlefile
direction LR
s1(all_funcs.c)
s2(all_funcs.h)
end
其主要目的是将反编译结果用于研究与分析。该工具依赖 Ghidra 进行反编译,并通过 pyghidra 使用 jpype 与 Ghidra 通信。
所有这些功能最终均由 Ghidra 提供
-o OUTPUT_PATH)--cppexport)-s SYMBOLS_PATH)
--sym-file-path)--filter)--gdt)--sast),对反编译代码进行静态分析
usage: ghidrecomp [-h] [--cppexport] [--filter FILTERS] [--project-path PROJECT_PATH] [--gdt [GDT]] [-o OUTPUT_PATH] [-v] [--skip-cache] [--sym-file-path SYM_FILE_PATH | -s SYMBOLS_PATH | --skip-symbols] [-t THREAD_COUNT] [--va] [--fa] [--max-ram-percent MAX_RAM_PERCENT] [--print-flags] [--callgraphs] [--callgraph-filter CALLGRAPH_FILTER] [--mdd MAX_DISPLAY_DEPTH] [--max-time-cg-gen MAX_TIME_CG_GEN] [--cg-direction {calling,called,both}] [--bsim] [--bsim-sig-path BSIM_SIG_PATH] [--bsim-template BSIM_TEMPLATE] [--bsim-cat BSIM_CAT] [--sast] [--semgrep-rules SEMGREP_RULES] [--codeql-rules CODEQL_RULES] bin
ghidrecomp - A Command Line Ghidra Decompiler
positional arguments: bin Path to binary used for analysis
options: -h, --help show this help message and exit --cppexport Use Ghidras CppExporter to decompile to single file (default: False) --filter FILTERS Regex match for function name (default: None) --project-path PROJECT_PATH Path to base ghidra projects (default: ghidra_projects) --gdt [GDT] Additional GDT to apply (default: None) -o OUTPUT_PATH, --output-path OUTPUT_PATH Location for all decompilations (default: ghidrecomps) -v, --version show program's version number and exit --skip-cache Skip cached and genearate new decomp and callgraphs. (default: False) --sym-file-path SYM_FILE_PATH Specify single pdb symbol file for bin (default: None) -s SYMBOLS_PATH, --symbols-path SYMBOLS_PATH Path for local symbols directory (default: symbols) --skip-symbols Do not apply symbols (default: False) -t THREAD_COUNT, --thread-count THREAD_COUNT Threads to use for processing. Defaults to cpu count (default: 12) --va Enable verbose analysis (default: False) --fa Force new analysis (even if already analyzed) (default: False)
JVM Options: --max-ram-percent MAX_RAM_PERCENT Set JVM Max Ram % of host RAM (default: 50.0) --print-flags Print JVM flags at start (default: False)
Callgraph Options: --callgraphs Generate callgraph markdown (default: False) --callgraph-filter CALLGRAPH_FILTER Only generate callgraphs for functions matching filter (default: .) --mdd MAX_DISPLAY_DEPTH, --max-display-depth MAX_DISPLAY_DEPTH Max Depth for graph generation (default: None) --max-time-cg-gen MAX_TIME_CG_GEN Max time in seconds to wait for callgraph gen. (default: 5) --cg-direction {calling,called,both} Direction for callgraph. (default: calling)
BSim Options: --bsim Generate BSim function feature vector signatures (default: False) --bsim-sig-path BSIM_SIG_PATH Path to store BSim xml sigs (default: bsim-xmls) --bsim-template BSIM_TEMPLATE BSim database template (default: medium_nosize) --bsim-cat BSIM_CAT BSim category. (type:value) --bsim-cat color:red (default: None)
SAST Options: --sast Run SAST scanning on decompiled code with semgrep and CodeQL (default: False) --semgrep-rules SEMGREP_RULES Path to local semgrep rule file or directory (can be specified multiple times, default: p/c) (default: None) --codeql-rules CODEQL_RULES Comma-separated paths to local CodeQL query directories (placeholder) (default: None)
## 输出文件树