Skip to content

Commit

Permalink
Ghidra 11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ekilmer committed Feb 9, 2025
1 parent aeea2f6 commit c08a067
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 66 deletions.
35 changes: 11 additions & 24 deletions src/patches/stable/0001-Fix-UBSAN-errors-in-decompiler.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From d3de474854d052712217ad731fffcea6334808ff Mon Sep 17 00:00:00 2001
From e694ad80e2965178c541a7414e55c76a1e318411 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Mon, 12 Aug 2024 12:02:35 -0400
Subject: [PATCH 1/6] Fix UBSAN errors in decompiler
Expand All @@ -9,16 +9,16 @@ Co-authored-by: Alex Cameron <asc@tetsuo.sh>
.../Decompiler/src/decompile/cpp/op.cc | 6 +++++-
.../Decompiler/src/decompile/cpp/opbehavior.cc | 8 +++++++-
.../src/decompile/cpp/pcodecompile.cc | 18 +++++++++++-------
.../Decompiler/src/decompile/cpp/ruleaction.cc | 18 ++++++++++++++----
.../Decompiler/src/decompile/cpp/ruleaction.cc | 12 +++++++++---
.../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/type.cc | 2 +-
.../src/decompile/unittests/testfloatemu.cc | 2 +-
10 files changed, 49 insertions(+), 19 deletions(-)
10 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index 6ebec206c9..e5a1ad598c 100644
index 3e9f310446..c903810382 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -2868,8 +2868,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
Expand All @@ -37,7 +37,7 @@ index 6ebec206c9..e5a1ad598c 100644

void ParameterBasic::setTypeLock(bool val)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
index d76a799960..37ba971a34 100644
index e165951fe6..00169e22e5 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
@@ -666,7 +666,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
Expand Down Expand Up @@ -116,10 +116,10 @@ index ca9d71ab99..85d4dd281d 100644
return res;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
index f667c6ca95..6ea3916520 100644
index b7fda34cc9..a3d164aa2d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
@@ -977,7 +977,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
@@ -976,7 +976,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
Varnode *outvn = op->getOut();
if (outvn->isPrecisLo()||outvn->isPrecisHi()) return 0; // Don't pull apart double precision object

Expand All @@ -133,7 +133,7 @@ index f667c6ca95..6ea3916520 100644
consume = ~consume;
if ((consume & indir->getIn(0)->getConsume())!=0) return 0;

@@ -7026,8 +7031,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
@@ -7288,8 +7293,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 @@ -145,19 +145,6 @@ index f667c6ca95..6ea3916520 100644
Varnode *vn1 = op->getIn(1);
if (!vn1->isConstant()) return 0;
Varnode *outvn = op->getOut();
@@ -8831,7 +8837,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
Varnode *outvn = op->getOut();
int4 flowsize = outvn->getSize();
uintb mask = calc_mask( flowsize );
- mask <<= 8*((int4)op->getIn(1)->getOffset());
+ if (8*((int4)op->getIn(1)->getOffset()) < sizeof(mask)) {
+ mask <<= 8*((int4)op->getIn(1)->getOffset());
+ } else {
+ mask = 0;
+ }
bool aggressive = outvn->isPtrFlow();
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 cd9b9835b1..8a4616c3b9 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
Expand Down Expand Up @@ -206,10 +193,10 @@ index 50d85e22ba..9f3b456229 100644
msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
else if (!sym->isPlaced())
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
index 7cda43127f..20a5bc1c83 100644
index 88ca8e36c8..f25b019a4f 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
@@ -3661,8 +3661,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
@@ -3728,8 +3728,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 @@ -233,5 +220,5 @@ index 2571f55f1a..fe40e22b1b 100644
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
uintb encoding = format.getEncoding(f);
--
2.47.0
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 4bbcb71e2c2cf1362628917c26879bbcb4717665 Mon Sep 17 00:00:00 2001
From cc36245a600051a66a4ab6c6ffff835d609ae92a Mon Sep 17 00:00:00 2001
From: Alex Cameron <asc@tetsuo.sh>
Date: Wed, 3 Aug 2022 20:01:18 +1000
Subject: [PATCH 2/6] Use `stroull` instead of `stroul` to parse address
Expand Down Expand Up @@ -34,5 +34,5 @@ index dbaa2e775f..72927bf379 100644
enddata = (const char *) tmpdata;
if (enddata - s.c_str() == s.size()) { // If no size or offset override
--
2.47.0
2.48.1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 7eb62bb534ac02b723baad0bb0a9cb7d33813972 Mon Sep 17 00:00:00 2001
From f0ee9c783a7acd850f6565278842a23865441e6a Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Tue, 29 Oct 2024 15:30:57 -0400
Subject: [PATCH 4/6] Use string resize instead of reserve
Subject: [PATCH 3/6] Use string resize instead of reserve

assign will fix up the size to hold all of what's copied
---
Expand Down Expand Up @@ -32,5 +32,5 @@ index 5f5fa0c7b3..4cd77156f2 100644
}
data.isTruncated = (numChars >= maximumChars);
--
2.47.0
2.48.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 9b118da968eac4a5ad910dc51d7d70150bab0408 Mon Sep 17 00:00:00 2001
From 43b0f78ca2ce8e2adbcc4f3b3298940c72dc9b5b Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Tue, 29 Oct 2024 17:51:09 -0400
Subject: [PATCH 5/6] Ignore floating point test due to compilation differences
Subject: [PATCH 4/6] Ignore floating point test due to compilation differences

This test fails on macOS and Windows. I'm unsure whether it's an OS or
compiler issue.
Expand All @@ -24,5 +24,5 @@ index fe40e22b1b..91440e2510 100644
ASSERT_EQUALS(ff.printDecimal(f2, false), "0.33333334");
double f3 = doubleFromRawBits(0x3fd0000000000000);
--
2.47.0
2.48.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f130a89a600a210e12e4505a4533d27ea7b7e4f7 Mon Sep 17 00:00:00 2001
From ef11bf80063c80967a6ddb8726e710bd207575f3 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Wed, 30 Oct 2024 14:26:57 -0400
Subject: [PATCH 6/6] Allow positive or negative NAN in decompiler floating
Subject: [PATCH 5/6] Allow positive or negative NAN in decompiler floating
point test

At least on Apple Silicon, this test reports positive NAN.
Expand Down Expand Up @@ -33,5 +33,5 @@ index f8108d3d32..1060a3e193 100644
<stringmatch name="Float print #14" min="1" max="1">double7 = 3.1415926535897933e-06;</stringmatch>
</decompilertest>
--
2.47.0
2.48.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 5d6886b914c266f0a97941666fda75e0f7311d35 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Sat, 8 Feb 2025 17:59:57 -0500
Subject: [PATCH 6/6] decompiler: Fix strict weak ordering TypePartialEnum

This fixes Windows Debug error encountered in testing where it was
complaining about lack of strict weak ordering.
---
Ghidra/Features/Decompiler/src/decompile/cpp/type.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
index f25b019a4f..2f1337a740 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
@@ -2300,6 +2300,7 @@ int4 TypePartialEnum::compareDependency(const Datatype &op) const

{
if (submeta != op.getSubMeta()) return (submeta < op.getSubMeta()) ? -1 : 1;
+ if (parent == &op) return 1; // op is our TypeEnum
TypePartialEnum *tp = (TypePartialEnum *) &op; // Both must be partial
if (parent != tp->parent) return (parent < tp->parent) ? -1 : 1; // Compare absolute pointers
if (offset != tp->offset) return (offset < tp->offset) ? -1 : 1;
--
2.48.1

10 changes: 5 additions & 5 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.2.1")
set(ghidra_version "11.3")
set(ghidra_git_tag "Ghidra_${ghidra_version}_build")
set(ghidra_shallow TRUE)

Expand All @@ -40,10 +40,10 @@ 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/0003-Add-missing-index-check-to-prevent-errors-in-Windows.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0004-Use-string-resize-instead-of-reserve.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0005-Ignore-floating-point-test-due-to-compilation-differ.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0006-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0003-Use-string-resize-instead-of-reserve.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0004-Ignore-floating-point-test-due-to-compilation-differ.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0006-decompiler-Fix-strict-weak-ordering-TypePartialEnum.patch"
)

# Ghidra pinned commits used for pinning last known working HEAD commit
Expand Down

0 comments on commit c08a067

Please sign in to comment.