mirror of
https://github.com/radareorg/r2ghidra.git
synced 2026-11-07 06:25:57 -10:00
Use the latest ghidra-native-0.5.0
* Fix some segfaults * Add meson build * Add LDFLAGS to link to zlib
This commit is contained in:
1 parent
52be9f9087
commit
78482ad5ac
14 files changed
+93
-64
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
include config.mk
|
||||
DESTDIR?=
|
||||
|
||||
GHIDRA_NATIVE_COMMIT=0.4.5
|
||||
GHIDRA_NATIVE_COMMIT=0.5.0
|
||||
|
||||
PUGIXML=third-party/pugixml/Makefile
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ The procedure is like the standard autoconf:
|
||||
|
||||
```
|
||||
$ ./preconfigure # optional, but useful for offline-packagers, as its downloads the external repos
|
||||
$ ./configure
|
||||
$ ./configure --prefix=$(r2 -H R2_PREFIX)
|
||||
$ make
|
||||
$ make install # or make user-install
|
||||
```
|
||||
@@ -124,8 +124,9 @@ At the moment there is no way to select which processors to support, so it build
|
||||
Also works with `muon/samu` and that's the preferred way to build r2ghidra on Windows.
|
||||
|
||||
```
|
||||
meson b
|
||||
ninja -C b
|
||||
meson setup b
|
||||
meson compile -C b
|
||||
meson install -C b
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
+19
-20
@@ -1,6 +1,9 @@
|
||||
# hardcoded for now
|
||||
USE_BISON=0
|
||||
|
||||
|
||||
LDFLAGS+=-lz
|
||||
|
||||
# GHIDRA_HOME=../ghidra/ghidra/
|
||||
# GHIDRA_DECOMPILER=$(GHIDRA_HOME)/Ghidra/Features/Decompiler/src/decompile/cpp
|
||||
GHIDRA_HOME=../ghidra-native
|
||||
@@ -10,42 +13,38 @@ G_DECOMPILER=marshal.cc space.cc float.cc address.cc pcoderaw.cc
|
||||
G_DECOMPILER+=translate.cc opcodes.cc globalcontext.cc
|
||||
G_DECOMPILER+=capability.cc architecture.cc options.cc graph.cc
|
||||
G_DECOMPILER+=cover.cc block.cc cast.cc typeop.cc database.cc
|
||||
G_DECOMPILER+=cpool.cc comment.cc fspec.cc action.cc loadimage.cc
|
||||
G_DECOMPILER+=cpool.cc comment.cc stringmanage.cc modelrules.cc fspec.cc action.cc loadimage.cc
|
||||
G_DECOMPILER+=varnode.cc op.cc type.cc variable.cc varmap.cc
|
||||
G_DECOMPILER+=jumptable.cc emulate.cc emulateutil.cc flow.cc userop.cc
|
||||
G_DECOMPILER+=funcdata.cc funcdata_block.cc funcdata_varnode.cc
|
||||
G_DECOMPILER+=multiprecision.cc funcdata.cc funcdata_block.cc funcdata_varnode.cc
|
||||
G_DECOMPILER+=funcdata_op.cc unionresolve.cc pcodeinject.cc heritage.cc prefersplit.cc
|
||||
G_DECOMPILER+=rangeutil.cc ruleaction.cc subflow.cc blockaction.cc
|
||||
G_DECOMPILER+=merge.cc double.cc coreaction.cc condexe.cc override.cc
|
||||
G_DECOMPILER+=dynamic.cc crc32.cc prettyprint.cc printlanguage.cc
|
||||
G_DECOMPILER+=printc.cc printjava.cc memstate.cc opbehavior.cc
|
||||
G_DECOMPILER+=paramid.cc transform.cc string_ghidra.cc stringmanage.cc
|
||||
G_DECOMPILER+=paramid.cc transform.cc string_ghidra.cc
|
||||
|
||||
G_DECOMPILER+=ghidra_arch.cc
|
||||
G_DECOMPILER+=loadimage_ghidra.cc
|
||||
G_DECOMPILER+=ghidra_context.cc
|
||||
G_DECOMPILER+=inject_ghidra.cc
|
||||
G_DECOMPILER+=cpool_ghidra.cc
|
||||
G_DECOMPILER+=comment_ghidra.cc
|
||||
G_DECOMPILER+=typegrp_ghidra.cc
|
||||
G_DECOMPILER+=ghidra_translate.cc
|
||||
G_DECOMPILER+=database_ghidra.cc
|
||||
|
||||
# G_DECOMPILER+=ghidra_process.cc
|
||||
G_DECOMPILER+=ghidra_arch.cc inject_ghidra.cc ghidra_translate.cc
|
||||
G_DECOMPILER+=loadimage_ghidra.cc typegrp_ghidra.cc database_ghidra.cc
|
||||
G_DECOMPILER+=ghidra_context.cc cpool_ghidra.cc comment_ghidra.cc
|
||||
# G_DECOMPILER+=ghidra_process.cc
|
||||
|
||||
G_DECOMPILER+= $(GHIDRA_LIBDECOMP_SRCS)
|
||||
|
||||
G_DECOMPILER+=sleigh_arch.cc
|
||||
G_DECOMPILER+=sleigh.cc
|
||||
G_DECOMPILER+=inject_sleigh.cc
|
||||
G_DECOMPILER+=filemanage.cc
|
||||
G_DECOMPILER+=semantics.cc
|
||||
G_DECOMPILER+=slghsymbol.cc
|
||||
G_DECOMPILER+=context.cc
|
||||
G_DECOMPILER+=pcodecompile.cc
|
||||
G_DECOMPILER+=sleighbase.cc
|
||||
G_DECOMPILER+=slghsymbol.cc
|
||||
G_DECOMPILER+=slghpatexpress.cc
|
||||
G_DECOMPILER+=slghpattern.cc
|
||||
G_DECOMPILER+=pcodecompile.cc
|
||||
G_DECOMPILER+=semantics.cc
|
||||
G_DECOMPILER+=context.cc
|
||||
G_DECOMPILER+=slaformat.cc
|
||||
G_DECOMPILER+=compression.cc
|
||||
G_DECOMPILER+=filemanage.cc
|
||||
|
||||
|
||||
# set(DECOMPILER_SOURCE_CONSOLE_CXX
|
||||
## G_DECOMPILER+=consolemain.cc
|
||||
@@ -106,7 +105,7 @@ sleigh: sleighc
|
||||
SLEIGHTC_OBJS=$(GHIDRA_DECOMPILER)/slgh_compile.o $(GHIDRA_DECOMPILER)/slghscan.o $(GHIDRA_DECOMPILER)/slghparse.o
|
||||
|
||||
sleighc: $(SLEIGHTC_OBJS) $(GHIDRA_OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o sleighc $(SLEIGHTC_OBJS) $(GHIDRA_OBJS)
|
||||
$(CXX) $(CXXFLAGS) -o sleighc $(SLEIGHTC_OBJS) $(GHIDRA_OBJS) $(LDFLAGS)
|
||||
|
||||
GHIDRA_SLEIGH_HOME=$(GHIDRA_HOME)/src/Processors
|
||||
GHIDRA_SLEIGH_SLASPECS=$(GHIDRA_SLEIGH_HOME)/*.slaspec
|
||||
|
||||
@@ -111,6 +111,7 @@ ghidra_decompiler_sources = [
|
||||
'ghidra-native/src/decompiler/float.cc',
|
||||
'ghidra-native/src/decompiler/flow.cc',
|
||||
'ghidra-native/src/decompiler/fspec.cc',
|
||||
'ghidra-native/src/decompiler/multiprecision.cc',
|
||||
'ghidra-native/src/decompiler/funcdata.cc',
|
||||
'ghidra-native/src/decompiler/funcdata_block.cc',
|
||||
'ghidra-native/src/decompiler/funcdata_op.cc',
|
||||
@@ -157,6 +158,8 @@ ghidra_decompiler_sources = [
|
||||
'ghidra-native/src/decompiler/raw_arch.cc',
|
||||
'ghidra-native/src/decompiler/ruleaction.cc',
|
||||
'ghidra-native/src/decompiler/rulecompile.cc',
|
||||
'ghidra-native/src/decompiler/compression.cc',
|
||||
'ghidra-native/src/decompiler/slaformat.cc',
|
||||
'ghidra-native/src/decompiler/semantics.cc',
|
||||
'ghidra-native/src/decompiler/sleigh.cc',
|
||||
'ghidra-native/src/decompiler/sleigh_arch.cc',
|
||||
@@ -172,6 +175,7 @@ ghidra_decompiler_sources = [
|
||||
'ghidra-native/src/decompiler/space.cc',
|
||||
'ghidra-native/src/decompiler/string_ghidra.cc',
|
||||
'ghidra-native/src/decompiler/stringmanage.cc',
|
||||
'ghidra-native/src/decompiler/modelrules.cc',
|
||||
'ghidra-native/src/decompiler/subflow.cc',
|
||||
'ghidra-native/src/decompiler/transform.cc',
|
||||
'ghidra-native/src/decompiler/translate.cc',
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ set PATH=%CD%\radare2\bin;%PATH%
|
||||
set VSARCH=x64
|
||||
|
||||
git submodule update --init
|
||||
set GNV=0.4.5
|
||||
set GNV=0.5.0
|
||||
|
||||
python -m wget https://github.com/radareorg/ghidra-native/releases/download/%GNV%/ghidra-native-%GNV%.zip
|
||||
|
||||
|
||||
@@ -286,8 +286,14 @@ static const std::map<std::string, std::vector <void (*)(ANNOTATOR_PARAMS)> > an
|
||||
**/
|
||||
static void ParseNode(pugi::xml_node node, ParseCodeXMLContext *ctx, std::ostream &stream, RCodeMeta *code) {
|
||||
// A leaf is an XML node which contains parts of the high level decompilation language
|
||||
if (node.type() == pugi::xml_node_type::node_pcdata) {
|
||||
stream << node.value();
|
||||
if (node.type () == pugi::xml_node_type::node_pcdata) {
|
||||
// XXX: optimise it?
|
||||
char* cleaned = strdup (node.value());
|
||||
if (strlen (cleaned) > 1) {
|
||||
r_str_trim (cleaned);
|
||||
}
|
||||
stream << cleaned;
|
||||
R_FREE (cleaned);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -80,11 +80,11 @@ asan:
|
||||
|
||||
$(R2G_CORE_PLUGIN): $(deps)
|
||||
$(CXX) -shared -o $@ $(R2GHIDRA_OBJS) $(GHIDRA_OBJS) $(PUGIXML_OBJS) core_ghidra.o \
|
||||
anal_ghidra.o core_ghidra_plugin.o anal_ghidra_plugin.o $(R2_LDFLAGS) $(CXXFLAGS)
|
||||
anal_ghidra.o core_ghidra_plugin.o anal_ghidra_plugin.o $(R2_LDFLAGS) $(LDFLAGS) $(CXXFLAGS)
|
||||
|
||||
$(R2G_ANAL_PLUGIN): $(deps)
|
||||
$(CXX) -shared $(GHIDRA_OBJS) $(PUGIXML_OBJS) anal_ghidra.o anal_ghidra_plugin.o \
|
||||
$(R2_LDFLAGS) $(CXXFLAGS) -o $@ $(R2GHIDRA_OBJS)
|
||||
$(R2GHIDRA_OBJS) $(R2_LDFLAGS) $(LDFLAGS) $(CXXFLAGS) -o $@
|
||||
|
||||
ifneq (,$(wildcard /usr/bin/codesign))
|
||||
sign macsign:
|
||||
|
||||
@@ -133,6 +133,38 @@ Scope *R2Architecture::buildDatabase(DocumentStorage &store) {
|
||||
symboltab->attachScope (globalscope, nullptr);
|
||||
return globalscope;
|
||||
}
|
||||
void R2Architecture::buildCoreTypes(DocumentStorage &store) {
|
||||
// TODO: load from r2?
|
||||
types->setCoreType ("void", 1, TYPE_VOID, false);
|
||||
types->setCoreType ("bool", 1, TYPE_BOOL, false);
|
||||
types->setCoreType ("uint8_t", 1, TYPE_UINT, false);
|
||||
types->setCoreType ("uint16_t", 2, TYPE_UINT, false);
|
||||
types->setCoreType ("uint32_t", 4, TYPE_UINT, false);
|
||||
types->setCoreType ("uint64_t", 8, TYPE_UINT, false);
|
||||
types->setCoreType ("int8_t", 1, TYPE_INT, false);
|
||||
types->setCoreType ("int16_t", 2, TYPE_INT, false);
|
||||
types->setCoreType ("int32_t", 4, TYPE_INT, false);
|
||||
types->setCoreType ("int64_t", 8, TYPE_INT, false);
|
||||
types->setCoreType ("double", 8, TYPE_FLOAT, false);
|
||||
types->setCoreType ("float", 4, TYPE_FLOAT, false);
|
||||
types->setCoreType ("float8", 8, TYPE_FLOAT, false);
|
||||
types->setCoreType ("float10", 10, TYPE_FLOAT, false);
|
||||
types->setCoreType ("float16", 16 ,TYPE_FLOAT, false);
|
||||
|
||||
types->setCoreType ("uchar", 1, TYPE_UNKNOWN, false);
|
||||
types->setCoreType ("ushort", 2, TYPE_UNKNOWN, false);
|
||||
types->setCoreType ("uint", 4, TYPE_UNKNOWN, false);
|
||||
types->setCoreType ("ulong", 8, TYPE_UNKNOWN, false);
|
||||
|
||||
types->setCoreType ("code", 1, TYPE_CODE, false);
|
||||
types->setCoreType ("char", 1, TYPE_INT, true);
|
||||
types->setCoreType ("wchar", 2, TYPE_INT, true);
|
||||
types->setCoreType ("char", 1, TYPE_INT, true);
|
||||
types->setCoreType ("char16_t", 2, TYPE_INT, true);
|
||||
types->setCoreType ("char32_t", 4, TYPE_INT, true);
|
||||
|
||||
types->cacheCoreTypes ();
|
||||
}
|
||||
|
||||
void R2Architecture::buildTypegrp(DocumentStorage &store) {
|
||||
r2TypeFactory_ = new R2TypeFactory (this);
|
||||
|
||||
@@ -46,6 +46,7 @@ protected:
|
||||
void buildLoader(DocumentStorage &store) override;
|
||||
Scope *buildDatabase(DocumentStorage &store) override;
|
||||
void buildTypegrp(DocumentStorage &store) override;
|
||||
void buildCoreTypes(DocumentStorage &store) override;
|
||||
void buildCommentDB(DocumentStorage &store) override;
|
||||
void postSpecFile() override;
|
||||
void buildAction(DocumentStorage &store) override;
|
||||
|
||||
+11
-2
@@ -1,4 +1,4 @@
|
||||
/* r2ghidra - LGPL - Copyright 2019-2023 - thestr4ng3r, pancake */
|
||||
/* r2ghidra - LGPL - Copyright 2019-2024 - thestr4ng3r, pancake */
|
||||
|
||||
#include "R2PrintC.h"
|
||||
#include "RCoreMutex.h"
|
||||
@@ -55,8 +55,17 @@ void R2PrintC::pushUnnamedLocation(const Address &addr, const Varnode *vn, const
|
||||
if (space->getType() == IPTR_PROCESSOR) {
|
||||
pushOp (&dereference, op);
|
||||
auto type = glb->types->getTypePointer (space->getAddrSize (), vn->getType (), space->getWordSize ());
|
||||
pushConstant (addr.getOffset (), type, vn, op);
|
||||
// pushConstant (addr.getOffset (), type, vn, op);
|
||||
pushConstant(addr.getOffset(),type,vartoken,vn, op);
|
||||
} else {
|
||||
PrintC::pushUnnamedLocation (addr,vn, op);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void R2PrintC::push_integer(uintb val,int4 sz,bool sign,tagtype tag, const Varnode *vn,const PcodeOp *op) {
|
||||
}
|
||||
|
||||
void R2PrintC::pushConstant(uintb val,const Datatype *ct,tagtype tag, const Varnode *vn, const PcodeOp *op) {
|
||||
}
|
||||
*/
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* r2ghidra - LGPL - Copyright 2019-2023 - thestr4ng3r, pancake */
|
||||
/* r2ghidra - LGPL - Copyright 2019-2024 - pancake */
|
||||
|
||||
#ifndef R2GHIDRA_R2PRINTC_H
|
||||
#define R2GHIDRA_R2PRINTC_H
|
||||
|
||||
@@ -452,6 +452,7 @@ Symbol *R2Scope::registerFlag(RFlagItem *flag) const {
|
||||
if (!bo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#if R2_VERSION_NUMBER >= 50909
|
||||
void *s = ht_up_find (bo->strings_db, flag->addr, nullptr);
|
||||
#else
|
||||
@@ -487,6 +488,7 @@ Symbol *R2Scope::registerFlag(RFlagItem *flag) const {
|
||||
|
||||
// Check whether flags should be displayed by their real name
|
||||
const char *name = (core->flags->realnames && flag->realname) ? flag->realname : flag->name;
|
||||
|
||||
#if R2_VERSION_NUMBER >= 50909
|
||||
const ut64 at = flag->addr;
|
||||
#else
|
||||
|
||||
+4
-31
@@ -18,35 +18,6 @@ R2TypeFactory::R2TypeFactory(R2Architecture *arch) : TypeFactory (arch), arch (a
|
||||
throw LowlevelError ("Failed to create RParseCType");
|
||||
}
|
||||
#endif
|
||||
// TODO: load from r2?
|
||||
setCoreType ("void", 1, TYPE_VOID, false);
|
||||
setCoreType ("bool", 1, TYPE_BOOL, false);
|
||||
setCoreType ("uint8_t", 1, TYPE_UINT, false);
|
||||
setCoreType ("uint16_t", 2, TYPE_UINT, false);
|
||||
setCoreType ("uint32_t", 4, TYPE_UINT, false);
|
||||
setCoreType ("uint64_t", 8, TYPE_UINT, false);
|
||||
setCoreType ("int8_t", 1, TYPE_INT, false);
|
||||
setCoreType ("int16_t", 2, TYPE_INT, false);
|
||||
setCoreType ("int32_t", 4, TYPE_INT, false);
|
||||
setCoreType ("int64_t", 8, TYPE_INT, false);
|
||||
setCoreType ("double", 8, TYPE_FLOAT, false);
|
||||
setCoreType ("float", 4, TYPE_FLOAT, false);
|
||||
setCoreType ("float8", 8, TYPE_FLOAT, false);
|
||||
setCoreType ("float10", 10, TYPE_FLOAT, false);
|
||||
setCoreType ("float16", 16 ,TYPE_FLOAT, false);
|
||||
|
||||
setCoreType ("uchar", 1, TYPE_UNKNOWN, false);
|
||||
setCoreType ("ushort", 2, TYPE_UNKNOWN, false);
|
||||
setCoreType ("uint", 4, TYPE_UNKNOWN, false);
|
||||
setCoreType ("ulong", 8, TYPE_UNKNOWN, false);
|
||||
|
||||
setCoreType ("code", 1, TYPE_CODE, false);
|
||||
setCoreType ("char", 1, TYPE_INT, true);
|
||||
setCoreType ("wchar", 2, TYPE_INT, true);
|
||||
setCoreType ("char", 1, TYPE_INT, true);
|
||||
setCoreType ("char16_t", 2, TYPE_INT, true);
|
||||
setCoreType ("char32_t", 4, TYPE_INT, true);
|
||||
cacheCoreTypes ();
|
||||
}
|
||||
|
||||
R2TypeFactory::~R2TypeFactory() {
|
||||
@@ -114,7 +85,7 @@ Datatype *R2TypeFactory::queryR2Struct(const string &n, std::set<std::string> &s
|
||||
arch->addWarning ("Struct " + n + " has no fields.");
|
||||
return nullptr;
|
||||
}
|
||||
setFields (fields, r, 0, 0);
|
||||
setFields (fields, r, 0, 0, 0);
|
||||
return r;
|
||||
} catch (std::invalid_argument &e) {
|
||||
arch->addWarning ("Failed to load struct " + n + " from sdb.");
|
||||
@@ -168,10 +139,12 @@ Datatype *R2TypeFactory::queryR2Typedef(const string &n, std::set<std::string> &
|
||||
if (!resolved) {
|
||||
return nullptr;
|
||||
}
|
||||
Datatype *typedefd = resolved->clone ();
|
||||
//Datatype *typedefd = resolved->clone ();
|
||||
Datatype *typedefd = getTypedef (resolved, n, 0, 0);
|
||||
setName (typedefd, n); // this removes the old name from the nametree
|
||||
setName (resolved, resolved->getName()); // add the old name back
|
||||
return typedefd;
|
||||
//return nullptr;
|
||||
}
|
||||
|
||||
Datatype *R2TypeFactory::queryR2(const string &n, std::set<std::string> &stackTypes) {
|
||||
|
||||
+3
-1
@@ -219,11 +219,12 @@ static void Decompile(RCore *core, ut64 addr, DecompileMode mode, std::stringstr
|
||||
case DecompileMode::OFFSET:
|
||||
case DecompileMode::STATEMENTS:
|
||||
case DecompileMode::DISASM:
|
||||
// XXX: Can docFunction return unindented xml??
|
||||
arch.print->docFunction(func);
|
||||
if (mode != DecompileMode::XML) {
|
||||
*out_code = ParseCodeXML(func, out_stream.str().c_str ());
|
||||
if (!*out_code) {
|
||||
std::cout << out_stream.str().c_str() << std::endl;
|
||||
std::cout << out_stream.str().c_str () << std::endl;
|
||||
throw LowlevelError ("Failed to parse XML code from Decompiler");
|
||||
}
|
||||
}
|
||||
@@ -428,6 +429,7 @@ static void Disassemble(RCore *core, ut64 ops) {
|
||||
const Translate *trans = arch.translate;
|
||||
PcodeRawOut emit (arch.translate);
|
||||
AssemblyRaw assememit;
|
||||
|
||||
#if R2_VERSION_NUMBER >= 50909
|
||||
Address addr (trans->getDefaultCodeSpace(), core->addr);
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user