Ghidra's decompiler介绍
该插件将Ghidra的反编译器代码集成到Ida插件中,并为Ida和Ghidra的所有平台支持提供了基本的反编译器功能。它提供了基本的源代码显示,试图模仿Hex-Rays反编译器的显示。仅在考虑Ida 7.x时编写。
备注:此代码非常原始,而且很可能是错误的!
BUILDING
在所有平台上,您都应该将blc克隆到IDA SDK的plugins子目录中,以便最终获得<sdkdir>/plugins/blc
。这是因为构建文件都使用相对路径来查找必要的IDA头文件和链接库。
为Linux / OS X构建blc:
使用include Makefile生成插件。您可能需要调整搜索到的路径以找到您的IDA安装(/Applications/IDA Pro N.NN
在OSX /opt/ida-N.NN
上假定并且在Linux 上假定,如果N.NN是从IDA SDK目录的名称派生的,例如idasdk73
与7.3
IDA版本号关联并应与其匹配) )。要成功链接插件,这是必需的。
$ cd <sdkdir>/plugins/blc$ make
编译后的二进制文件将以 <sdkdir>/plugins/blc/bin
LINUX
-------------------------------------------
| ida | ida64 |
-------------------------------------------IDA 7.x | | |
plugin | blc.so | blc64.so |
-------------------------------------------OS/X
-------------------------------------------
| ida | ida64 |
-------------------------------------------IDA 7.x | | | |
plugin | blc.dylib | blc64.dylib |
-------------------------------------------
将插件复制到您的<IDADIR>/plugins
目录中,并且blc应该列为Ida和Ghidra支持的所有体系结构的可用插件。
为Windows构建BLC
使用随附的解决方案(.sln
)文件(blc.sln
)在Visual Studio C ++ 2017或更高版本中进行构建。根据您使用的IDA版本,有两个构建目标可用:
-----------------------------------------
| ida | ida64 |
-----------------------------------------IDA 7.x | Release/x64 | Release64/x64 |
plugin | blc.dll | blc64.dll |
-----------------------------------------
将插件复制到您的<IDADIR>/plugins
目录中,并且blc应该被列为Ida和Ghidra支持的所有体系结构的可用插件。
安装
假设您已将IDA安装到<idadir>
,请通过将已编译的二进制文件从复制<sdkdir>/plugins/blc/bin
到到<idadir>/plugins
(Linux / Windows)或<idadir>/idabin/plugins
(OS X)来安装插件。
该插件取决于Ghira处理器规格,您需要从自己的Ghidra安装中复制该规格。安装Ghidra只需解压缩最新的Ghidra版本即可,例如:https ://ghidra-sre.org/ghidra_9.1_PUBLIC_20191023.zip在解压缩的 Ghidra文件夹中,您会找到一个Ghidra
子目录,该子目录又包含一个Processors
子目录。反编译器需要访问包含在中的文件Ghidra/Processors
。默认情况下,插件会查找$GHIDRA_DIR
它希望指向您的Ghidra安装文件夹(例如已$GHIDRA_DIR/Ghidra/Processors
存在)的环境变量。如果 $GHIDRA_DIR
未设置,则该插件希望找到<idadir>/plugins/Ghidra/Processors
您可以使用符号链接或通过从Ghidra安装复制适当的目录来创建的内容。
r2ghidra介绍
这是radar2的Ghidra反编译器的集成。 它完全基于Ghidra的反编译器部分,该部分完全用C ++编写,因此Ghidra本身完全不需要,并且插件可以独立构建。 该项目是在R2con 2019上作为Cutter演讲的一部分提出的:https://youtu.be/eHtMiezr7l8?t=950
安装
有一个r2pm软件包,可以很容易地安装它,例如:
r2pm -i r2ghidra-dec
该软件包仅安装radare2部分。 要使用Cutter中的r2ghidra,请使用从Cutter 1.9开始提供的预构建发行版,该发行版捆绑了r2ghidra,或遵循以下构建说明。
用法
Usage: pdg # Native Ghidra decompiler plugin
| pdg # Decompile current function with the Ghidra decompiler
| pdgd # Dump the debug XML Dump
| pdgx # Dump the XML of the current decompiled function
| pdgj # Dump the current decompiled function as JSON
| pdgo # Decompile current function side by side with offsets
| pdgs # Display loaded Sleigh Languages
| pdg* # Decompiled code is returned to r2 as comment
以下配置变量(用于e命令)可用于调整r2ghidra的行为:
r2ghidra.cmt.cpp: C++ comment style
r2ghidra.cmt.indent: Comment indent
r2ghidra.indent: Indent increment
r2ghidra.lang: Custom Sleigh ID to override auto-detection (e.g. x86:LE:32:default)
r2ghidra.linelen: Max line length
r2ghidra.nl.brace: Newline before opening '{'
r2ghidra.nl.else: Newline before else
r2ghidra.sleighhome: SLEIGHHOME
在这里,r2ghidra.sleighhome必须指向包含*.sla,*.lspec,...文件的目录,用于反编译器应支持的体系结构。 但是,这在使用r2pm软件包或如下所示安装时会自动设置。
Building
首先,确保已获取此存储库中包含的子模块并且该模块是最新的:
git submodule init
git submodule update
然后,可以按如下所示构建和安装radare2插件:
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
make
make install
在这里,将CMAKE_INSTALL_PREFIX设置为radare2可以从中加载插件的位置。 必须执行安装步骤才能使插件正常工作,因为该步骤包括安装必要的Sleigh文件。
要同时构建Cutter插件,请将-DBUILD_CUTTER_PLUGIN = ON -DCUTTER_SOURCE_DIR = / path / to / cutter / source传递给cmake,例如:
/my/path> git clone https://github.com/radareorg/cutter
/my/path> # build Cutter, clone r2ghidra-dec, etc.
...
/my/path/r2ghidra-dec> mkdir build && cd build
/my/path/r2ghidra-dec/build> cmake -DBUILD_CUTTER_PLUGIN=ON -DCUTTER_SOURCE_DIR=/my/path/cutter -DCMAKE_INSTALL_PREFIX=~/.local ..
/my/path/r2ghidra-dec/build> make && make install
License
Please note that this plugin is available under the LGPLv3, which is more strict than Ghidra's license!
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.