Skip to content

Commit

Permalink
Ida Pro 7.7 and Ghidra 10.1.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryMorse committed Mar 15, 2022
1 parent 2b19542 commit 1ff85b3
Show file tree
Hide file tree
Showing 74 changed files with 2,921 additions and 1,467 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.6)
project(ghidradec-idaplugin CXX C)
set(RELEASE_VERSION "1.3")

set(GHIDRA_VER "10.0.2")
set(GHIDRA_VER "10.1.2")
set(GHIDRA_SRC_ZIP "Ghidra_${GHIDRA_VER}_build.zip")
set(GHIDRA_SRC_ZIP_HASH "f28e3535178e6b3c1da0d066c2cd44ff7cc10bc2121add990ec98cb7427f6ae8")
set(GHIDRA_SRC_ZIP_HASH "c8614fa0145254c3540b50df808645290282adc797f1cce948ee3c3dfe9faa1d")

if(NOT EXISTS ${GHIDRA_SRC_ZIP})
file(DOWNLOAD "https://github.com/NationalSecurityAgency/ghidra/archive/refs/tags/${GHIDRA_SRC_ZIP}" ${GHIDRA_SRC_ZIP} TIMEOUT 60 EXPECTED_HASH SHA256=${GHIDRA_SRC_ZIP_HASH})
Expand Down
18 changes: 10 additions & 8 deletions Ghidra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ ARCH_TYPE=
ADDITIONAL_FLAGS=
SLEIGHVERSION=sleigh-2.1.0

EXTENSION_POINT=../../../../../../../ghidra.ext/Ghidra/Features/DecompilerExtensions/src/decompile/cpp
EXTENSION_POINT=../../../../../../../ghidra.ext-u/Ghidra/Features/DecompilerExtensions/src/decompile/cpp
GHIDRA_BIN=../../../../../../../ghidra.bin

OS = $(shell uname -s)
CPU = $(shell uname -m)

# TODO: need to revise to support arm64/aarch64 arch - improve on both OS and arch detection

ifeq ($(OS),Linux)
# Allow ARCH to be specified externally so we can build for 32-bit from a 64-bit Linux
ifndef ARCH
ARCH=$(CPU)
endif
ifeq ($(ARCH),x86_64)
ARCH_TYPE=-m64
OSDIR=linux64
OSDIR=linux_x86_64
else
ARCH_TYPE=-m32
OSDIR=linux32
OSDIR=linux_x86_32
endif
endif

ifeq ($(OS),Darwin)
MAKE_STATIC=
ARCH_TYPE=-arch x86_64
ADDITIONAL_FLAGS=-mmacosx-version-min=10.6 -w
OSDIR=osx64
OSDIR=mac_x86_64
endif

CC=gcc
Expand Down Expand Up @@ -94,7 +96,7 @@ GHIDRA= ghidra_arch inject_ghidra ghidra_translate loadimage_ghidra \
# Additional files specific to the sleigh compiler
SLACOMP=slgh_compile slghparse slghscan
# Additional special files that should not be considered part of the library
SPECIAL=consolemain sleighexample test testfunction
SPECIAL=consolemain sleighexample test
# Any additional modules for the command line decompiler
EXTRA= $(filter-out $(CORE) $(DECCORE) $(SLEIGH) $(GHIDRA) $(SLACOMP) $(SPECIAL),$(ALL_NAMES))

Expand All @@ -117,11 +119,11 @@ COMMANDLINE_NAMES=$(CORE) $(DECCORE) $(EXTRA) $(SLEIGH) consolemain
COMMANDLINE_DEBUG=-DCPUI_DEBUG -D__TERMINAL__
COMMANDLINE_OPT=-D__TERMINAL__

TEST_NAMES=$(CORE) $(DECCORE) $(SLEIGH) $(EXTRA) testfunction test
TEST_NAMES=$(CORE) $(DECCORE) $(SLEIGH) $(EXTRA) test
TEST_DEBUG=-D__TERMINAL__

GHIDRA_NAMES=$(CORE) $(DECCORE) $(GHIDRA)
GHIDRA_NAMES_DBG=$(GHIDRA_NAMES) callgraph ifacedecomp ifaceterm interface
GHIDRA_NAMES_DBG=$(GHIDRA_NAMES) callgraph ifacedecomp testfunction ifaceterm interface
GHIDRA_DEBUG=-DCPUI_DEBUG
GHIDRA_OPT=

Expand Down Expand Up @@ -296,7 +298,7 @@ libdecomp.a: $(LIBDECOMP_OPT_OBJS)
ar qc libdecomp.a $(LIBDECOMP_OPT_OBJS)
ranlib libdecomp.a

sleighexamp_dir:
sleighexamp_dir: slghscan.cc
rm -rf $(SLEIGHVERSION)
mkdir $(SLEIGHVERSION)
mkdir $(SLEIGHVERSION)/src $(SLEIGHVERSION)/specfiles
Expand Down
2 changes: 0 additions & 2 deletions Ghidra/architecture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ AddrSpace *Architecture::getSpaceBySpacebase(const Address &loc,int4 size) const
}
}
throw LowlevelError("Unable to find entry for spacebase register");
return (AddrSpace *)0;
}

/// Look-up the laned register record associated with a specific storage location. Currently, the
Expand Down Expand Up @@ -286,7 +285,6 @@ void Architecture::clearAnalysis(Funcdata *fd)
fd->clear(); // Clear stuff internal to function
// Clear out any analysis generated comments
commentdb->clearType(fd->getAddress(),Comment::warning|Comment::warningheader);
stringManager->clear();
}

/// Symbols do not necessarily need to be available for the decompiler.
Expand Down
18 changes: 9 additions & 9 deletions Ghidra/block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,18 +890,18 @@ void BlockGraph::identifyInternal(BlockGraph *ident,const vector<FlowBlock *> &n
ident->selfIdentify();
}

/// \param flags is the set of boolean properties
void BlockGraph::clearEdgeFlags(uint4 flags)
/// \param fl is the set of boolean properties
void BlockGraph::clearEdgeFlags(uint4 fl)

{
flags = ~flags;
fl = ~fl;
int4 size = list.size();
for(int4 i=0;i<size;++i) {
FlowBlock *bl = list[i];
for(int4 j=0;j<size;++j) {
FlowBlock *bl = list[j];
for(int4 i=0;i<bl->intothis.size();++i)
bl->intothis[i].label &= flags;
bl->intothis[i].label &= fl;
for(int4 i=0;i<bl->outofthis.size();++i)
bl->outofthis[i].label &= flags;
bl->outofthis[i].label &= fl;
}
}

Expand Down Expand Up @@ -3350,8 +3350,8 @@ void BlockSwitch::finalizePrinting(Funcdata &data) const
CaseOrder &curcase( caseblocks[i] );
if (jump->numIndicesByBlock(curcase.basicblock) > 0) {
if (curcase.depth == 0) { // Only set label on chain roots
int4 index = jump->getIndexByBlock(curcase.basicblock,0);
curcase.label = jump->getLabelByIndex(index);
int4 ind = jump->getIndexByBlock(curcase.basicblock,0);
curcase.label = jump->getLabelByIndex(ind);
int4 j = curcase.chain;
int4 depthcount = 1;
while(j != -1) {
Expand Down
2 changes: 1 addition & 1 deletion Ghidra/block.hh
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class BlockGraph : public FlowBlock {
void forceOutputNum(int4 i); ///< Force number of outputs
void selfIdentify(void); ///< Inherit our edges from the edges of our components
void identifyInternal(BlockGraph *ident,const vector<FlowBlock *> &nodes);
void clearEdgeFlags(uint4 flags); ///< Clear a set of properties from all edges in the graph
void clearEdgeFlags(uint4 fl); ///< Clear a set of properties from all edges in the graph
static FlowBlock *createVirtualRoot(const vector<FlowBlock *> &rootlist);
void findSpanningTree(vector<FlowBlock *> &preorder,vector<FlowBlock *> &rootlist);
bool findIrreducible(const vector<FlowBlock *> &preorder,int4 &irreduciblecount);
Expand Down
20 changes: 16 additions & 4 deletions Ghidra/cast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ Datatype *CastStrategyC::castStandard(Datatype *reqtype,Datatype *curtype,
care_uint_int = true;
isptr = true;
}
while(reqbase->getTypedef() != (Datatype *)0)
reqbase = reqbase->getTypedef();
while(curbase->getTypedef() != (Datatype *)0)
curbase = curbase->getTypedef();
if (curbase == reqbase) return (Datatype *)0; // Different typedefs could point to the same type
if ((reqbase->getMetatype()==TYPE_VOID)||(curtype->getMetatype()==TYPE_VOID))
return (Datatype *)0; // Don't cast from or to VOID
Expand Down Expand Up @@ -348,19 +352,27 @@ bool CastStrategyC::isSubpieceCastEndian(Datatype *outtype,Datatype *intype,uint
bool CastStrategyC::isSextCast(Datatype *outtype,Datatype *intype) const

{
if (outtype->getMetatype()!=TYPE_INT) return false;
type_metatype metaout = outtype->getMetatype();
if (metaout != TYPE_UINT && metaout != TYPE_INT)
return false;
type_metatype metain = intype->getMetatype();
if ((metain!=TYPE_INT)&&(metain!=TYPE_UINT)&&(metain!=TYPE_BOOL))
// Casting to larger storage always extends based on signedness of the input data-type
// So the input must be SIGNED in order to treat SEXT as a cast
if ((metain!=TYPE_INT)&&(metain!=TYPE_BOOL))
return false;
return true;
}

bool CastStrategyC::isZextCast(Datatype *outtype,Datatype *intype) const

{
if (outtype->getMetatype()!=TYPE_UINT) return false;
type_metatype metaout = outtype->getMetatype();
if (metaout != TYPE_UINT && metaout != TYPE_INT)
return false;
type_metatype metain = intype->getMetatype();
if ((metain!=TYPE_INT)&&(metain!=TYPE_UINT)&&(metain!=TYPE_BOOL))
// Casting to larger storage always extends based on signedness of the input data-type
// So the input must be UNSIGNED in order to treat ZEXT as a cast
if ((metain!=TYPE_UINT)&&(metain!=TYPE_BOOL))
return false;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Ghidra/condexe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ bool ConditionMarker::finalJudgement(Varnode *vn)
return true;
}

bool ConditionMarker::verifyCondition(PcodeOp *op,PcodeOp *initop)
bool ConditionMarker::verifyCondition(PcodeOp *op,PcodeOp *iop)

{
setupInitOp(initop);
setupInitOp(iop);
Varnode *matchvn = findMatch(op);
if (matchvn == (Varnode *)0) return false;
if (!finalJudgement(matchvn)) return false;
Expand Down
2 changes: 1 addition & 1 deletion Ghidra/condexe.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ConditionMarker {
public:
ConditionMarker(void); ///< Constructor
~ConditionMarker(void); ///< Destructor
bool verifyCondition(PcodeOp *op, PcodeOp *initop); ///< Perform the correlation test on two CBRANCH operations
bool verifyCondition(PcodeOp *op, PcodeOp *iop); ///< Perform the correlation test on two CBRANCH operations
int4 getMultiSlot(void) const { return multislot; } ///< Get the MULTIEQUAL slot in the critical path
bool getFlip(void) const { return matchflip; } ///< Return \b true is the expressions are anti-correlated
static bool varnodeSame(Varnode *a,Varnode *b);
Expand Down
Loading

0 comments on commit 1ff85b3

Please sign in to comment.