mirror of
https://github.com/radareorg/r2ghidra.git
synced 2026-11-07 06:25:57 -10:00
Use ghidra-native and remove the huge ghidra submodule
* 20MB repo instead of 600MB * Apply the minimum required patches to work with r2ghidra * Add STM8 support * Fix crash happening in bc/6994 binary * Bump version to 5.3.1
This commit is contained in:
1 parent
c2ebd1e4db
commit
f865f92eca
17 files changed
+61
-71
No files matched your search
@@ -73,7 +73,7 @@ jobs:
|
||||
- name: Installing Radare2
|
||||
run: sudo dpkg -i radare2/dist/debian/*/*.deb
|
||||
- name: Building r2ghidra with cmake
|
||||
run: git submodule update --init ; mkdir build && cd build && cmake .. && make -j4 && sudo make install
|
||||
run: git submodule update --init ; make ghidra/ghidra/Ghidra ; mkdir build && cd build && cmake .. && make -j4 && sudo make install
|
||||
- name: Packaging r2ghidra for Debian
|
||||
run: make -C scripts/debian
|
||||
- name: Testing r2ghidra oneliner
|
||||
@@ -144,9 +144,9 @@ jobs:
|
||||
set PATH=%CD%\radare2\bin;%PATH%
|
||||
set ARCH=x64
|
||||
git submodule update --init
|
||||
make ghidra/ghidra/Ghidra
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
mkdir destdir
|
||||
mkdir build
|
||||
mkdir destdir build
|
||||
cd build
|
||||
cmake -GNinja ..
|
||||
cmake --build .
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
name: docker
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Checkout submodules
|
||||
run: |
|
||||
git submodule init
|
||||
git submodule update
|
||||
- name: Docker Build
|
||||
run: cd scripts && docker build -t r2ghidra . -f Dockerfile.buster && cd ..
|
||||
- name: Build and Test
|
||||
run: docker run --rm -v "`pwd`:/build" -t r2ghidra /bin/bash -c "cd /build && scripts/ci-script"
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
[submodule "ghidra/ghidra"]
|
||||
path = ghidra/ghidra
|
||||
branch = r2ghidra
|
||||
url = https://github.com/radareorg/ghidra.git
|
||||
[submodule "third-party/pugixml"]
|
||||
path = third-party/pugixml
|
||||
url = https://github.com/zeux/pugixml.git
|
||||
@@ -13,16 +13,23 @@ endif
|
||||
ghidra-processors.txt:
|
||||
cp -f ghidra-processors.txt.default ghidra-processors.txt
|
||||
|
||||
asan:
|
||||
CFLAGS="-fsanitize=address" $(MAKE) -C src
|
||||
asan: ghidra/ghidra/Ghidra ghidra-processors.txt
|
||||
#touch ghidra/ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/*.cc src/*.cpp
|
||||
touch src/*.cpp
|
||||
CFLAGS="-fsanitize=address -g" $(MAKE) -C src -j
|
||||
make user-install
|
||||
|
||||
asan-run:
|
||||
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib r2 -s 9664 /Users/pancake/Downloads/usr-4/bin/bc
|
||||
|
||||
help:
|
||||
@echo
|
||||
@echo "./configure # first you need to run configure"
|
||||
@echo "make # build r2ghidra plugins"
|
||||
@echo "make install # install plugin and sleighs into prefix"
|
||||
@echo "make user-install # install in your home"
|
||||
@echo "make uninstall # uninstall r2ghidra from prefix (see user-uninstall)"
|
||||
@echo "./configure # first you need to run configure"
|
||||
@echo "make # build r2ghidra plugins"
|
||||
@echo "make install # install plugin and sleighs into prefix"
|
||||
@echo "make uninstall # uninstall r2ghidra from prefix (see user-uninstall)"
|
||||
@echo "make user-install # install in your home"
|
||||
@echo "make user-uninstall # uninstall r2ghidra from prefix (see user-uninstall)"
|
||||
@echo
|
||||
|
||||
clean:
|
||||
@@ -53,8 +60,16 @@ user-uninstall:
|
||||
$(MAKE) -C src sleigh-uninstall
|
||||
rm -f $(DESTDIR)/$(BINDIR)/sleighc
|
||||
|
||||
gclean:
|
||||
rm -rf ghidra-native ghidra/ghidra/Ghidra
|
||||
|
||||
ghidra/ghidra/Ghidra:
|
||||
$(MAKE) -C ghidra
|
||||
git clone https://github.com/radareorg/ghidra-native
|
||||
$(MAKE) -C ghidra-native patch
|
||||
mkdir -p ghidra/ghidra/Ghidra/Features/Decompiler/src/decompile/cpp
|
||||
cp -rf ghidra-native/src/decompiler/* ghidra/ghidra/Ghidra/Features/Decompiler/src/decompile/cpp
|
||||
mkdir -p ghidra/ghidra/Ghidra/Processors
|
||||
cp -rf ghidra-native/src/Processors/* ghidra/ghidra/Ghidra/Processors/
|
||||
|
||||
mrproper: clean
|
||||
git submodule deinit --all -f
|
||||
|
||||
@@ -89,8 +89,8 @@ At the moment there is no way to select which processors to support, so it build
|
||||
First, make sure the submodule contained within this repository is fetched and up to date:
|
||||
|
||||
```
|
||||
git submodule init
|
||||
git submodule update
|
||||
git submodule update --init
|
||||
make ghidra/ghidra/Ghidra
|
||||
```
|
||||
|
||||
Then, the radare2 plugin can be built and installed as follows:
|
||||
|
||||
@@ -109,12 +109,12 @@ done
|
||||
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
|
||||
: ${INSTALL_MAN:=${INSTALL} -m 444}
|
||||
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
|
||||
PKGNAME='r2ghidra' ; VERSION='5.2.1' ; VERSION_MAJOR=5; VERSION_MINOR=2; VERSION_PATCH=1; VERSION_NUMBER=50201; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
|
||||
PKGNAME='r2ghidra' ; VERSION='5.3.1' ; VERSION_MAJOR=5; VERSION_MINOR=3; VERSION_PATCH=1; VERSION_NUMBER=50301; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
cat <<EOF2
|
||||
'configure' configures r2ghidra-5.2.1 to adapt to many kinds of systems.
|
||||
'configure' configures r2ghidra-5.3.1 to adapt to many kinds of systems.
|
||||
|
||||
Usage: ./configure [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -186,10 +186,10 @@ ocho() {
|
||||
|
||||
show_version() {
|
||||
if [ "$QUIET" = 1 ]; then
|
||||
echo "5.2.1"
|
||||
echo "5.3.1"
|
||||
exit 0
|
||||
fi
|
||||
echo "r2ghidra-5.2.1 configuration script done with acr v1.9.8.
|
||||
echo "r2ghidra-5.3.1 configuration script done with acr v1.9.8.
|
||||
The 'Free Software Foundation' message is only for autodetection.
|
||||
Originally written by pancake <nopcode.org>."
|
||||
exit 0
|
||||
@@ -218,7 +218,7 @@ case $flag in
|
||||
show_version ; ;;
|
||||
-r|--r|--report)
|
||||
echo "PKGNAME: r2ghidra"
|
||||
echo "VERSION: 5.2.1"
|
||||
echo "VERSION: 5.3.1"
|
||||
echo "LANGS: c++"
|
||||
echo "PKG-CONFIG: r_core r_asm r_anal"
|
||||
exit 0
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
PKGNAME r2ghidra
|
||||
VERSION 5.2.1
|
||||
VERSION 5.3.1
|
||||
CONTACT pancake ; [email protected]
|
||||
|
||||
LANG_CXX!
|
||||
|
||||
@@ -21,6 +21,7 @@ PIC
|
||||
PowerPC
|
||||
RISCV
|
||||
Sparc
|
||||
STM8
|
||||
SuperH
|
||||
SuperH4
|
||||
TI_MSP430
|
||||
|
||||
Submodule ghidra/ghidra deleted from 5560ac1711.
+1
-1
@@ -3,7 +3,7 @@ project(
|
||||
'cpp',
|
||||
license : 'LGPL3',
|
||||
meson_version : '>=0.50.1',
|
||||
version : '5.2.1',
|
||||
version : '5.3.1',
|
||||
default_options : ['c_std=c11', 'cpp_std=c++11']
|
||||
)
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ static const std::map<std::string, ArchMapper> arch_map = {
|
||||
{ "pic24", { "PIC-24F", "default", 24 } },
|
||||
{ "z80", { "z80", "default", 8 } },
|
||||
{ "sparc", { "sparc" } },
|
||||
{ "stm8", { "STM8" } },
|
||||
{ "sh", { "SuperH4" } },
|
||||
{ "msp430", { "TI_MSP430" } },
|
||||
{ "m68k", {
|
||||
|
||||
@@ -60,6 +60,7 @@ void AnnotateOpref(ANNOTATOR_PARAMS)
|
||||
annotation.type = R_CODEMETA_TYPE_OFFSET;
|
||||
annotation.offset.offset = op->getAddr().getOffset();
|
||||
}
|
||||
|
||||
void AnnotateFunctionName(ANNOTATOR_PARAMS)
|
||||
{
|
||||
const char *func_name = node.child_value();
|
||||
@@ -180,10 +181,9 @@ void AnnotateLocalVariable(Symbol *symbol, std::vector<RCodeMetaItem> *out)
|
||||
return;
|
||||
RCodeMetaItem annotation = {};
|
||||
annotation.variable.name = strdup(symbol->getName().c_str());
|
||||
if(symbol->getCategory() == 0)
|
||||
annotation.type = R_CODEMETA_TYPE_FUNCTION_PARAMETER;
|
||||
else
|
||||
annotation.type = R_CODEMETA_TYPE_LOCAL_VARIABLE;
|
||||
annotation.type = (symbol->getCategory() == 0)
|
||||
? R_CODEMETA_TYPE_FUNCTION_PARAMETER
|
||||
: R_CODEMETA_TYPE_LOCAL_VARIABLE;
|
||||
out->push_back(annotation);
|
||||
}
|
||||
|
||||
@@ -297,13 +297,8 @@ static void ParseNode(pugi::xml_node node, ParseCodeXMLContext *ctx, std::ostrea
|
||||
for(auto &annotation : annotations)
|
||||
{
|
||||
annotation.end = stream.tellp();
|
||||
#if R2_VERSION_MAJOR == 5 && R2_VERSION_MINOR == 2 && R2_VERSION_PATCH == 0
|
||||
r_codemeta_add_annotation (code, &annotation);
|
||||
#else
|
||||
r_codemeta_add_item (code, &annotation);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST_UNKNOWN_NODES
|
||||
if(close_test)
|
||||
stream << "</" << node.name() << ">";
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ R2PrintC::R2PrintC(Architecture *g, const string &nm)
|
||||
: PrintC(g, nm)
|
||||
{
|
||||
option_NULL = true;
|
||||
option_space_after_comma = true;
|
||||
// option_space_after_comma = true;
|
||||
// option_nocasts = true;
|
||||
/// option_convention = true;
|
||||
/// option_hide_exts = true;
|
||||
|
||||
+5
-6
@@ -123,7 +123,7 @@ FunctionSymbol *R2Scope::registerFunction(RAnalFunction *fcn) const
|
||||
auto flag = reinterpret_cast<RFlagItem *>(pos);
|
||||
if(flag->space && flag->space->name && !strcmp(flag->space->name, R_FLAGS_FS_SECTIONS))
|
||||
continue;
|
||||
if (flag->realname && *flag->realname) {
|
||||
if (!R_STR_ISEMPTY (flag->realname)) {
|
||||
fcn_name = flag->realname;
|
||||
break;
|
||||
}
|
||||
@@ -180,10 +180,7 @@ FunctionSymbol *R2Scope::registerFunction(RAnalFunction *fcn) const
|
||||
{
|
||||
uintb off;
|
||||
int delta = var->delta + fcn->bp_off - extraPop; // not 100% sure if extraPop is correct here
|
||||
if(delta >= 0)
|
||||
off = delta;
|
||||
else
|
||||
off = stackSpace->getHighest() + delta + 1;
|
||||
off = (delta >= 0)? delta: stackSpace->getHighest() + delta + 1;
|
||||
return Address(stackSpace, off);
|
||||
}
|
||||
case R_ANAL_VAR_KIND_REG:
|
||||
@@ -496,7 +493,7 @@ Symbol *R2Scope::queryR2Absolute(ut64 addr, bool contain) const
|
||||
RCoreLock core(arch->getCore());
|
||||
|
||||
RAnalFunction *fcn = r_anal_get_function_at(core->anal, addr);
|
||||
#if 0
|
||||
#if 1
|
||||
// This can cause functions to be registered twice (hello-arm test)
|
||||
if(!fcn && contain)
|
||||
{
|
||||
@@ -642,5 +639,7 @@ LabSymbol *R2Scope::findCodeLabel(const Address &addr) const
|
||||
|
||||
Funcdata *R2Scope::resolveExternalRefFunction(ExternRefSymbol *sym) const
|
||||
{
|
||||
if (!sym)
|
||||
return nullptr;
|
||||
return queryFunction(sym->getRefAddr());
|
||||
}
|
||||
@@ -43,7 +43,7 @@ SleighInstruction *R2Sleigh::getInstruction(Address &addr)
|
||||
void SleighParserContext::setPrototype(SleighInstructionPrototype *p)
|
||||
{
|
||||
prototype = p;
|
||||
*getBaseState() = &prototype->rootState;
|
||||
*getBaseState() = &prototype->rootState;
|
||||
}
|
||||
|
||||
void R2Sleigh::reconstructContext(ParserContext &protoContext)
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ static RAsmPlugin r_asm_plugin_ghidra = {
|
||||
KV(.arch, "sleigh"),
|
||||
KV(.author, "FXTi"),
|
||||
KV(.version, nullptr),
|
||||
KV(.cpus, "6502,6805,8051,arm,avr,cr16,dalvik,hppa,java,m68k,m8c,mips,mcs96,msp430,pic24,ppc,sh,sparc,tricore,toy,v850,x86,z80"),
|
||||
KV(.cpus, "6502,6805,8051,arm,avr,cr16,dalvik,hppa,java,m68k,m8c,mips,mcs96,msp430,pic24,ppc,sh,sparc,stm8,tricore,toy,v850,x86,z80"),
|
||||
KV(.desc, "SLEIGH Disassembler from Ghidra"),
|
||||
KV(.license, "GPL3"),
|
||||
KV(.user, nullptr),
|
||||
|
||||
+12
-6
@@ -19,6 +19,8 @@
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#undef DEBUG_EXCEPTIONS
|
||||
|
||||
#define CMD_PREFIX "pdg"
|
||||
#define CFG_PREFIX "r2ghidra"
|
||||
|
||||
@@ -60,8 +62,10 @@ static const ConfigVar cfg_var_sleighhome ("sleighhome", "", "SLEIGHH
|
||||
static const ConfigVar cfg_var_sleighid ("lang", "", "Custom Sleigh ID to override auto-detection (e.g. x86:LE:32:default)");
|
||||
static const ConfigVar cfg_var_cmt_cpp ("cmt.cpp", "true", "C++ comment style");
|
||||
static const ConfigVar cfg_var_cmt_indent ("cmt.indent", "4", "Comment indent");
|
||||
#if 0
|
||||
static const ConfigVar cfg_var_nl_brace ("nl.brace", "false", "Newline before opening '{'");
|
||||
static const ConfigVar cfg_var_nl_else ("nl.else", "false", "Newline before else");
|
||||
#endif
|
||||
static const ConfigVar cfg_var_indent ("indent", "4", "Indent increment");
|
||||
static const ConfigVar cfg_var_linelen ("linelen", "120", "Max line length");
|
||||
static const ConfigVar cfg_var_maximplref ("maximplref", "2", "Maximum number of references to an expression before showing an explicit variable.");
|
||||
@@ -116,8 +120,6 @@ static void PrintUsage(const RCore *const core)
|
||||
|
||||
enum class DecompileMode { DEFAULT, XML, DEBUG_XML, OFFSET, STATEMENTS, JSON };
|
||||
|
||||
//#define DEBUG_EXCEPTIONS
|
||||
|
||||
static void ApplyPrintCConfig(RConfig *cfg, PrintC *print_c)
|
||||
{
|
||||
if(!print_c)
|
||||
@@ -128,11 +130,13 @@ static void ApplyPrintCConfig(RConfig *cfg, PrintC *print_c)
|
||||
else
|
||||
print_c->setCStyleComments();
|
||||
|
||||
/*
|
||||
print_c->setSpaceAfterComma(true);
|
||||
|
||||
print_c->setNewlineBeforeOpeningBrace(cfg_var_nl_brace.GetBool(cfg));
|
||||
print_c->setNewlineBeforeElse(cfg_var_nl_else.GetBool(cfg));
|
||||
print_c->setNewlineAfterPrototype(false);
|
||||
*/
|
||||
print_c->setIndentIncrement(cfg_var_indent.GetInt(cfg));
|
||||
print_c->setLineCommentIndent(cfg_var_cmt_indent.GetInt(cfg));
|
||||
print_c->setMaxLineSize(cfg_var_linelen.GetInt(cfg));
|
||||
@@ -144,18 +148,20 @@ static void Decompile(RCore *core, ut64 addr, DecompileMode mode, std::stringstr
|
||||
if(!function)
|
||||
throw LowlevelError("No function at this offset");
|
||||
R2Architecture arch(core, cfg_var_sleighid.GetString(core->config));
|
||||
DocumentStorage store;
|
||||
DocumentStorage store = DocumentStorage();
|
||||
arch.max_implied_ref = cfg_var_maximplref.GetInt(core->config);
|
||||
arch.setRawPtr(cfg_var_rawptr.GetBool(core->config));
|
||||
arch.init(store);
|
||||
Funcdata *func = arch.symboltab->getGlobalScope()->findFunction(Address(arch.getDefaultCodeSpace(), function->addr));
|
||||
|
||||
auto faddr = Address(arch.getDefaultCodeSpace(), function->addr);
|
||||
Funcdata *func = arch.symboltab->getGlobalScope()->findFunction(faddr);
|
||||
arch.print->setOutputStream(&out_stream);
|
||||
arch.setPrintLanguage("r2-c-language");
|
||||
auto r2c = dynamic_cast<R2PrintC *>(arch.print);
|
||||
bool showCasts = cfg_var_casts.GetBool(core->config);
|
||||
r2c->setOptionNoCasts(!showCasts);
|
||||
ApplyPrintCConfig(core->config, dynamic_cast<PrintC *>(arch.print));
|
||||
if(!func)
|
||||
if(func == nullptr)
|
||||
throw LowlevelError("No function in Scope");
|
||||
arch.getCore()->sleepBegin();
|
||||
auto action = arch.allacts.getCurrent();
|
||||
@@ -545,7 +551,7 @@ static int r2ghidra_cmd(void *user, const char *input)
|
||||
RCore *core = (RCore *) user;
|
||||
if (!strncmp (input, CMD_PREFIX, strlen(CMD_PREFIX)))
|
||||
{
|
||||
_cmd (core, input + 3);
|
||||
_cmd (core, input + strlen(CMD_PREFIX));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user