Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghidra 11.1 #268

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ set(public_include_header_list
"${library_root}/modelrules.hh"
"${library_root}/signature.hh"
"${library_root}/signature_ghidra.hh"
"${library_root}/compression.hh"
"${library_root}/multiprecision.hh"
"${library_root}/slaformat.hh"
)
if(sleigh_RELEASE_IS_HEAD)
list(APPEND public_include_header_list
"${library_root}/compression.hh"
"${library_root}/multiprecision.hh"
"${library_root}/slaformat.hh"
)
endif()
# if(sleigh_RELEASE_IS_HEAD)
# list(APPEND public_include_header_list
# )
# endif()
# Create custom target so that IDEs know these files are part of the sources
add_custom_target(sleigh_all_headers SOURCES ${public_include_header_list})
set(public_headers_dir ${CMAKE_CURRENT_BINARY_DIR}/include)
Expand All @@ -162,9 +162,7 @@ endforeach()
configure_file(cmake/libconfig.h.in "${public_headers_dir}/sleigh/libconfig.h")

# External Dependencies
if(sleigh_RELEASE_IS_HEAD)
find_package(ZLIB REQUIRED)
endif()
find_package(ZLIB REQUIRED)

#
# sla
Expand Down Expand Up @@ -198,9 +196,7 @@ set_target_properties(sleigh_sla PROPERTIES
OUTPUT_NAME_DEBUG sla_dbg
)

if(sleigh_RELEASE_IS_HEAD)
target_link_libraries(sleigh_sla PUBLIC ZLIB::ZLIB)
endif()
target_link_libraries(sleigh_sla PUBLIC ZLIB::ZLIB)

#
# decomp
Expand Down Expand Up @@ -229,9 +225,7 @@ set_target_properties(sleigh_decomp PROPERTIES
OUTPUT_NAME_DEBUG decomp_dbg
)

if(sleigh_RELEASE_IS_HEAD)
target_link_libraries(sleigh_decomp PUBLIC ZLIB::ZLIB)
endif()
target_link_libraries(sleigh_decomp PUBLIC ZLIB::ZLIB)

# This is the root directory where all individual processor spec file directories will be created.
# NOTE: Needs to be defined here before the install rules
Expand Down
7 changes: 3 additions & 4 deletions cmake/install-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

# Extra version details. Either 'stable' or 'HEAD'
set(sleigh_RELEASE_IS_HEAD "@sleigh_RELEASE_IS_HEAD@")
if(sleigh_RELEASE_IS_HEAD)
include(CMakeFindDependencyMacro)
find_dependency(ZLIB)
endif()

include(CMakeFindDependencyMacro)
find_dependency(ZLIB)

include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake")

Expand Down
5 changes: 0 additions & 5 deletions extra-tools/sleigh-lift/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,9 @@ int main(int argc, char *argv[]) {
ghidra::ContextInternal ctx;
ghidra::Sleigh engine(&load_image, &ctx);
ghidra::DocumentStorage storage;
#ifdef sleigh_RELEASE_IS_HEAD
std::istringstream sla("<sleigh>" + sla_file_path->string() + "</sleigh>");
ghidra::Element *root =
storage.parseDocument(sla)->getRoot();
#else
ghidra::Element *root =
storage.openDocument(sla_file_path->string())->getRoot();
#endif
storage.registerTag(root);
std::optional<std::filesystem::path> pspec_file_path;
if (args->pspec_file_name) {
Expand Down
69 changes: 27 additions & 42 deletions src/patches/stable/0001-Fix-UBSAN-errors-in-decompiler.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
From 0e437cb96249306d17f26ff6614871ecd9b37359 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 2 Aug 2023 23:19:42 +1000
Subject: [PATCH 1/2] Fix UBSAN errors in decompiler
From 6c36965500d26d5a35dfbc91725956ae1d51e394 Mon Sep 17 00:00:00 2001
From: Alex Cameron <[email protected]>
Date: Mon, 5 Jun 2023 16:45:04 +1200
Subject: [PATCH 1/5] Fix UBSAN errors in decompiler

---
.../Decompiler/src/decompile/cpp/fspec.cc | 8 ++++++--
Expand All @@ -14,16 +13,15 @@ Subject: [PATCH 1/2] Fix UBSAN errors in decompiler
.../Decompiler/src/decompile/cpp/semantics.cc | 2 ++
.../Decompiler/src/decompile/cpp/semantics.hh | 2 +-
.../src/decompile/cpp/slgh_compile.cc | 2 +-
.../Decompiler/src/decompile/cpp/slghsymbol.cc | 2 +-
.../Decompiler/src/decompile/cpp/type.cc | 2 +-
.../src/decompile/unittests/testfloatemu.cc | 2 +-
12 files changed, 57 insertions(+), 21 deletions(-)
11 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index 8380d3cd..a18d5007 100644
index dc96f0c19..3482cf17c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -2661,8 +2661,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
@@ -2727,8 +2727,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
modellist.push_back(mymodel);
}
decoder.closeElement(elemId);
Expand All @@ -39,7 +37,7 @@ index 8380d3cd..a18d5007 100644

void ParameterBasic::setTypeLock(bool val)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
index f7781707..283d81c3 100644
index fc094ee96..1f7e53ebe 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
@@ -503,7 +503,13 @@ void Funcdata::setHighLevel(void)
Expand All @@ -58,10 +56,10 @@ index f7781707..283d81c3 100644
uint4 vnFlags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce);

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
index 0e3decc8..403ec35a 100644
index 921335173..46cdc39f3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
@@ -672,7 +672,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
@@ -666,7 +666,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
break;
case CPUI_PIECE:
resmask = getIn(0)->getNZMask();
Expand All @@ -75,10 +73,10 @@ index 0e3decc8..403ec35a 100644
break;
case CPUI_INT_MULT:
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
index fcd75cc7..ed0e005a 100644
index aebcfd910..6c47e6eb1 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
@@ -750,7 +750,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
@@ -746,7 +746,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const

{
Expand All @@ -94,7 +92,7 @@ index fcd75cc7..ed0e005a 100644
}

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
index ca9d71ab..85d4dd28 100644
index ca9d71ab9..85d4dd281 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
@@ -621,8 +621,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
Expand Down Expand Up @@ -137,7 +135,7 @@ index ca9d71ab..85d4dd28 100644
return res;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
index 4851365d..d069d1c9 100644
index 3703c8ef5..ac6e21c00 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
@@ -976,7 +976,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
Expand All @@ -154,7 +152,7 @@ index 4851365d..d069d1c9 100644
consume = ~consume;
if ((consume & indir->getIn(0)->getConsume())!=0) return 0;

@@ -6782,8 +6787,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
@@ -6803,8 +6808,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
Varnode *sb = op->getIn(0);
Datatype *sbType = sb->getTypeReadFacing(op);
if (sbType->getMetatype() != TYPE_PTR) return 0;
Expand All @@ -166,7 +164,7 @@ index 4851365d..d069d1c9 100644
Varnode *vn1 = op->getIn(1);
if (!vn1->isConstant()) return 0;
Varnode *outvn = op->getOut();
@@ -8593,7 +8599,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
@@ -8616,7 +8622,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
Varnode *outvn = op->getOut();
int4 flowsize = outvn->getSize();
uintb mask = calc_mask( flowsize );
Expand All @@ -180,7 +178,7 @@ index 4851365d..d069d1c9 100644
if (!aggressive) {
if ((vn->getConsume() & mask) != vn->getConsume()) return 0;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
index 2e3531ea..42482be7 100644
index cd9b9835b..8a4616c3b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
@@ -22,6 +22,7 @@ ConstTpl::ConstTpl(const_type tp)
Expand All @@ -200,23 +198,23 @@ index 2e3531ea..42482be7 100644

bool ConstTpl::isConstSpace(void) const
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
index 8e283dca..652600c1 100644
index e0b069959..9117a45c7 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
@@ -48,7 +48,7 @@ private:
static void printHandleSelector(ostream &s,v_field val);
static v_field readHandleSelector(const string &name);
@@ -47,7 +47,7 @@ class ConstTpl {
uintb value_real;
v_field select; // Which part of handle to use as constant
public:
- ConstTpl(void) { type = real; value_real = 0; }
+ ConstTpl(void) { type = real; value_real = 0; select = v_space; }
ConstTpl(const ConstTpl &op2) {
type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; }
ConstTpl(const_type tp,uintb val);
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
index b40f7438..3c37958d 100644
index c060053bf..c9004023c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
@@ -2163,8 +2163,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
@@ -2164,8 +2164,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
ostringstream msg;
SymbolTree::const_iterator iter;
for(iter=scope->begin();iter!=scope->end();++iter) {
Expand All @@ -226,24 +224,11 @@ index b40f7438..3c37958d 100644
if (sym->getRefCount() == 0)
msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
else if (!sym->isPlaced())
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
index b308e1b7..af2982ae 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
@@ -2569,7 +2569,7 @@ void ContextOp::restoreXml(const Element *el,SleighBase *trans)
const List &list(el->getChildren());
List::const_iterator iter;
iter = list.begin();
- patexp = (PatternValue *)PatternExpression::restoreExpression(*iter,trans);
+ patexp = PatternExpression::restoreExpression(*iter,trans);
patexp->layClaim();
}

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
index 30faf0b6..e76a0619 100644
index e6292e138..bd31b7470 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
@@ -3359,8 +3359,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
@@ -3561,8 +3561,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
top.submeta = sub; // Search on the incorrect submeta
iter = tree.lower_bound(&top);
while(iter != tree.end()) {
Expand All @@ -254,7 +239,7 @@ index 30faf0b6..e76a0619 100644
++iter;
if (ptr->submeta == sub) {
diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
index c35bde87..061e5367 100644
index c35bde877..061e53677 100644
--- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
@@ -346,7 +346,7 @@ TEST(float_opTrunc_to_int) {
Expand All @@ -267,5 +252,5 @@ index c35bde87..061e5367 100644
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
uintb encoding = format.getEncoding(f);
--
2.39.2 (Apple Git-143)
2.44.0

Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
From 95f230f46bdb95aa4aab7f5d320691f87107fb36 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 2 Aug 2023 23:20:14 +1000
Subject: [PATCH 2/2] Use `stroull` instead of `stroul` to parse address
From 290b06621c7a8c32c1470d16dbd8740876d57640 Mon Sep 17 00:00:00 2001
From: Alex Cameron <[email protected]>
Date: Wed, 3 Aug 2022 20:01:18 +1000
Subject: [PATCH 2/5] Use `stroull` instead of `stroul` to parse address
offsets

---
Ghidra/Features/Decompiler/src/decompile/cpp/space.cc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
index bf4e1dc9..594b4583 100644
index bda09fc94..d077ee375 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
@@ -16,6 +16,8 @@
Expand All @@ -22,7 +21,7 @@ index bf4e1dc9..594b4583 100644
namespace ghidra {

AttributeId ATTRIB_BASE = AttributeId("base",89);
@@ -290,7 +292,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
@@ -274,7 +276,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
}
}
catch(LowlevelError &err) { // Name doesn't exist
Expand All @@ -35,5 +34,5 @@ index bf4e1dc9..594b4583 100644
enddata = (const char *) tmpdata;
if (enddata - s.c_str() == s.size()) { // If no size or offset override
--
2.39.2 (Apple Git-143)
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From a7fc8b440ab58cb377460e11c7449488ff5abc96 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <[email protected]>
Date: Sat, 30 Mar 2024 18:46:16 -0400
Subject: [PATCH 5/5] Add missing index check to prevent errors in Windows

Not sure why this only appears when testing on Windows.
---
Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
index ac94d261c..a76ad389b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
@@ -1842,7 +1842,7 @@ void IfcProtooverride::execute(istream &s)
s >> ws;
Address callpoint(parse_machaddr(s,discard,*dcp->conf->types));
int4 i;
- for(i=0;dcp->fd->numCalls();++i)
+ for(i=0;i<dcp->fd->numCalls();++i)
if (dcp->fd->getCallSpecs(i)->getOp()->getAddr() == callpoint) break;
if (i == dcp->fd->numCalls())
throw IfaceExecutionError("No call is made at this address");
--
2.44.0

25 changes: 13 additions & 12 deletions src/setup-ghidra-source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set_property(CACHE sleigh_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
find_package(Git REQUIRED)

# Ghidra pinned stable version commit
set(ghidra_version "11.0.3")
set(ghidra_version "11.1")
set(ghidra_git_tag "Ghidra_${ghidra_version}_build")
set(ghidra_shallow TRUE)

Expand All @@ -40,6 +40,7 @@ set(ghidra_patches
"${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0001-Fix-UBSAN-errors-in-decompiler.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0005-Add-missing-index-check-to-prevent-errors-in-Windows.patch"
)

# Ghidra pinned commits used for pinning last known working HEAD commit
Expand Down Expand Up @@ -165,12 +166,12 @@ set(sleigh_deccore_source_list
"${library_root}/unionresolve.cc"
"${library_root}/modelrules.cc"
"${library_root}/signature.cc"
"${library_root}/multiprecision.cc"
)
if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
list(APPEND sleigh_deccore_source_list
"${library_root}/multiprecision.cc"
)
endif()
# if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
# list(APPEND sleigh_deccore_source_list
# )
# endif()

set(sleigh_extra_source_list
"${library_root}/callgraph.cc"
Expand Down Expand Up @@ -199,13 +200,13 @@ set(sleigh_source_list
"${library_root}/semantics.cc"
"${library_root}/context.cc"
"${library_root}/filemanage.cc"
"${library_root}/slaformat.cc"
"${library_root}/compression.cc"
)
if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
list(APPEND sleigh_source_list
"${library_root}/slaformat.cc"
"${library_root}/compression.cc"
)
endif()
# if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
# list(APPEND sleigh_source_list
# )
# endif()

set(sleigh_ghidra_source_list
"${library_root}/ghidra_arch.cc"
Expand Down
3 changes: 3 additions & 0 deletions support/include/sleigh/libsleigh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ namespace ghidra {
#include <ghidra/modelrules.hh>
#include <ghidra/signature.hh>
#include <ghidra/signature_ghidra.hh>
#include <ghidra/compression.hh>
#include <ghidra/multiprecision.hh>
#include <ghidra/slaformat.hh>

// #ifdef sleigh_RELEASE_IS_HEAD
// #endif
Expand Down
Loading
Loading