Skip to content

Commit e925db9

Browse files
Update Ghidra HEAD to commit 42794bc3f (#351)
* Fix some patches and rename test binary * Bump Ghidra HEAD commit 42794bc3f Changed files: ``` M Ghidra/Features/Decompiler/src/decompile/cpp/.gitignore M Ghidra/Features/Decompiler/src/decompile/cpp/Makefile M Ghidra/Features/Decompiler/src/decompile/cpp/address.cc M Ghidra/Features/Decompiler/src/decompile/cpp/address.hh M Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc M Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc M Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc M Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc M Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc M Ghidra/Features/Decompiler/src/decompile/cpp/op.cc M Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc M Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc M Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc M Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc M Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc M Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc M Ghidra/Features/Decompiler/src/decompile/cpp/type.cc ``` Commit details: ``` [Commit 1/1] Hash: 943ccd322ddc280cd28cb7cb6ef8328941c3d574 Date: 2025-07-23 22:49:35 +0000 Message: GP-5869 Fix for some out of bounds array indices and shift amounts Files changed: M Ghidra/Features/Decompiler/src/decompile/cpp/.gitignore M Ghidra/Features/Decompiler/src/decompile/cpp/Makefile M Ghidra/Features/Decompiler/src/decompile/cpp/address.cc M Ghidra/Features/Decompiler/src/decompile/cpp/address.hh M Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc M Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc M Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc M Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc M Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc M Ghidra/Features/Decompiler/src/decompile/cpp/op.cc M Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc M Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc M Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc M Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc M Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc M Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc M Ghidra/Features/Decompiler/src/decompile/cpp/type.cc ``` --------- Co-authored-by: Eric Kilmer <eric.d.kilmer@gmail.com>
1 parent e590133 commit e925db9

8 files changed

Lines changed: 33 additions & 174 deletions
Lines changed: 4 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,17 @@
1-
From 7c6e51dd1234387b98e1ad61d3f88a0565364b28 Mon Sep 17 00:00:00 2001
1+
From 9d1e7b00e8f5dca987038a78fbac400c835a78be Mon Sep 17 00:00:00 2001
22
From: Eric Kilmer <eric.d.kilmer@gmail.com>
33
Date: Mon, 12 Aug 2024 12:02:35 -0400
4-
Subject: [PATCH 1/6] Fix UBSAN errors in decompiler
4+
Subject: [PATCH 1/5] Fix UBSAN errors in decompiler
55

66
Co-authored-by: Alex Cameron <asc@tetsuo.sh>
77
---
8-
.../Decompiler/src/decompile/cpp/fspec.cc | 8 ++++++--
9-
.../Decompiler/src/decompile/cpp/op.cc | 6 +++++-
10-
.../Decompiler/src/decompile/cpp/opbehavior.cc | 8 +++++++-
118
.../src/decompile/cpp/pcodecompile.cc | 18 +++++++++++-------
12-
.../Decompiler/src/decompile/cpp/ruleaction.cc | 12 +++++++++---
139
.../Decompiler/src/decompile/cpp/semantics.cc | 2 ++
1410
.../Decompiler/src/decompile/cpp/semantics.hh | 2 +-
1511
.../src/decompile/cpp/slgh_compile.cc | 2 +-
16-
.../Decompiler/src/decompile/cpp/type.cc | 2 +-
1712
.../src/decompile/unittests/testfloatemu.cc | 2 +-
18-
10 files changed, 44 insertions(+), 18 deletions(-)
13+
5 files changed, 16 insertions(+), 10 deletions(-)
1914

20-
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
21-
index d78b78731c..caf4b24d15 100644
22-
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
23-
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
24-
@@ -2868,8 +2868,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
25-
modellist.push_back(mymodel);
26-
}
27-
decoder.closeElement(elemId);
28-
- ((ParamListMerged *)input)->finalize();
29-
- ((ParamListMerged *)output)->finalize();
30-
+ if (input->getType() == ParamList::p_merged) {
31-
+ ((ParamListMerged *)input)->finalize();
32-
+ }
33-
+ if (output->getType() == ParamList::p_merged) {
34-
+ ((ParamListMerged *)output)->finalize();
35-
+ }
36-
}
37-
38-
void ParameterBasic::setTypeLock(bool val)
39-
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
40-
index d51460be84..45bf394862 100644
41-
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
42-
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
43-
@@ -666,7 +666,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
44-
break;
45-
case CPUI_PIECE:
46-
resmask = getIn(0)->getNZMask();
47-
- resmask <<= 8*getIn(1)->getSize();
48-
+ if (8*getIn(1)->getSize() < sizeof(resmask)) {
49-
+ resmask <<= 8*getIn(1)->getSize();
50-
+ } else {
51-
+ resmask = 0;
52-
+ }
53-
resmask |= getIn(1)->getNZMask();
54-
break;
55-
case CPUI_INT_MULT:
56-
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
57-
index aebcfd9103..6c47e6eb15 100644
58-
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
59-
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
60-
@@ -746,7 +746,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
61-
uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
62-
63-
{
64-
- uintb res = (in1>>(in2*8)) & calc_mask(sizeout);
65-
+ uintb res = in1;
66-
+ if (in2 < sizeof(in1)) {
67-
+ res >>= (in2*8);
68-
+ } else {
69-
+ res = 0;
70-
+ }
71-
+ res &= calc_mask(sizeout);
72-
return res;
73-
}
74-
7515
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
7616
index ca9d71ab99..85d4dd281d 100644
7717
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
@@ -115,36 +55,6 @@ index ca9d71ab99..85d4dd281d 100644
11555
force_size(res->outvn,ConstTpl(ConstTpl::real,finalsize),*res->ops);
11656
return res;
11757
}
118-
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
119-
index 009570af71..72b2a10503 100644
120-
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
121-
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
122-
@@ -976,7 +976,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
123-
Varnode *outvn = op->getOut();
124-
if (outvn->isPrecisLo()||outvn->isPrecisHi()) return 0; // Don't pull apart double precision object
125-
126-
- uintb consume = calc_mask(newSize) << 8 * minByte;
127-
+ uintb consume = calc_mask(newSize);
128-
+ if (8 * minByte < sizeof(consume)) {
129-
+ consume <<= 8 * minByte;
130-
+ } else {
131-
+ consume = 0;
132-
+ }
133-
consume = ~consume;
134-
if ((consume & indir->getIn(0)->getConsume())!=0) return 0;
135-
136-
@@ -7031,8 +7036,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
137-
Varnode *sb = op->getIn(0);
138-
Datatype *sbType = sb->getTypeReadFacing(op);
139-
if (sbType->getMetatype() != TYPE_PTR) return 0;
140-
- TypeSpacebase *sbtype = (TypeSpacebase *)((TypePointer *)sbType)->getPtrTo();
141-
- if (sbtype->getMetatype() != TYPE_SPACEBASE) return 0;
142-
+ Datatype *sbTypePtr = ((TypePointer *)sbType)->getPtrTo();
143-
+ if (sbTypePtr->getMetatype() != TYPE_SPACEBASE) return 0;
144-
+ TypeSpacebase *sbtype = (TypeSpacebase *)sbTypePtr;
145-
Varnode *vn1 = op->getIn(1);
146-
if (!vn1->isConstant()) return 0;
147-
Varnode *outvn = op->getOut();
14858
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
14959
index cd9b9835b1..8a4616c3b9 100644
15060
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
@@ -192,20 +102,6 @@ index 50d85e22ba..9f3b456229 100644
192102
if (sym->getRefCount() == 0)
193103
msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
194104
else if (!sym->isPlaced())
195-
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
196-
index fd0ab26fb4..7f654c220b 100644
197-
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
198-
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
199-
@@ -3728,8 +3728,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
200-
top.submeta = sub; // Search on the incorrect submeta
201-
iter = tree.lower_bound(&top);
202-
while(iter != tree.end()) {
203-
+ if ((*iter)->getMetatype() != TYPE_PTR) break;
204-
TypePointer *ptr = (TypePointer *)*iter;
205-
- if (ptr->getMetatype() != TYPE_PTR) break;
206-
if (ptr->ptrto != base) break;
207-
++iter;
208-
if (ptr->submeta == sub) {
209105
diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
210106
index 2571f55f1a..fe40e22b1b 100644
211107
--- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
@@ -220,5 +116,5 @@ index 2571f55f1a..fe40e22b1b 100644
220116
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
221117
uintb encoding = format.getEncoding(f);
222118
--
223-
2.48.1
119+
2.50.1
224120

src/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 5e37c51ebc8a3ae0f32a3cb0049aaebafec48d7d Mon Sep 17 00:00:00 2001
1+
From 729f72060849dc4f29e89b1c76a980563ffd3e2a Mon Sep 17 00:00:00 2001
22
From: Alex Cameron <asc@tetsuo.sh>
33
Date: Wed, 3 Aug 2022 20:01:18 +1000
4-
Subject: [PATCH 2/6] Use `stroull` instead of `stroul` to parse address
4+
Subject: [PATCH 2/5] Use `stroull` instead of `stroul` to parse address
55
offsets
66

77
---
@@ -34,5 +34,5 @@ index dbaa2e775f..72927bf379 100644
3434
enddata = (const char *) tmpdata;
3535
if (enddata - s.c_str() == s.size()) { // If no size or offset override
3636
--
37-
2.48.1
37+
2.50.1
3838

src/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch renamed to src/patches/HEAD/0003-Ignore-floating-point-test-due-to-compilation-differ.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 2a8f30f31c24ecc7bd499648b97bb8b0c2705b78 Mon Sep 17 00:00:00 2001
1+
From 39cfff6f08dad8a85f992e09b3e26716c9173bf7 Mon Sep 17 00:00:00 2001
22
From: Eric Kilmer <eric.d.kilmer@gmail.com>
33
Date: Tue, 29 Oct 2024 17:51:09 -0400
4-
Subject: [PATCH 4/6] Ignore floating point test due to compilation differences
4+
Subject: [PATCH 3/5] Ignore floating point test due to compilation differences
55

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

src/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch renamed to src/patches/HEAD/0004-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 04cca72897d9088713a6e2dadb2774ad20ae7703 Mon Sep 17 00:00:00 2001
1+
From 2aa4395ef8874ee9890126f4bdad0d71adf9eacc Mon Sep 17 00:00:00 2001
22
From: Eric Kilmer <eric.d.kilmer@gmail.com>
33
Date: Wed, 30 Oct 2024 14:26:57 -0400
4-
Subject: [PATCH 5/6] Allow positive or negative NAN in decompiler floating
4+
Subject: [PATCH 4/5] Allow positive or negative NAN in decompiler floating
55
point test
66

77
At least on Apple Silicon, this test reports positive NAN.
@@ -33,5 +33,5 @@ index f8108d3d32..1060a3e193 100644
3333
<stringmatch name="Float print #14" min="1" max="1">double7 = 3.1415926535897933e-06;</stringmatch>
3434
</decompilertest>
3535
--
36-
2.48.1
36+
2.50.1
3737

src/patches/HEAD/0006-decompiler-Fix-strict-weak-ordering-TypePartialEnum.patch renamed to src/patches/HEAD/0005-decompiler-Fix-strict-weak-ordering-TypePartialEnum.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From a7dee0fbb1838e4e22a1c970718b84976ffb2932 Mon Sep 17 00:00:00 2001
1+
From 2a6bd0a0ad7797160db887bba7137b77aa148ba5 Mon Sep 17 00:00:00 2001
22
From: Eric Kilmer <eric.d.kilmer@gmail.com>
33
Date: Sat, 8 Feb 2025 17:59:57 -0500
4-
Subject: [PATCH 6/6] decompiler: Fix strict weak ordering TypePartialEnum
4+
Subject: [PATCH 5/5] decompiler: Fix strict weak ordering TypePartialEnum
55

66
This fixes Windows Debug error encountered in testing where it was
77
complaining about lack of strict weak ordering.
@@ -10,10 +10,10 @@ complaining about lack of strict weak ordering.
1010
1 file changed, 1 insertion(+)
1111

1212
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
13-
index 7f654c220b..3f10c78c2f 100644
13+
index 962c525b7f..7db5024b54 100644
1414
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
1515
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
16-
@@ -2300,6 +2300,7 @@ int4 TypePartialEnum::compareDependency(const Datatype &op) const
16+
@@ -2303,6 +2303,7 @@ int4 TypePartialEnum::compareDependency(const Datatype &op) const
1717

1818
{
1919
if (submeta != op.getSubMeta()) return (submeta < op.getSubMeta()) ? -1 : 1;
@@ -22,5 +22,5 @@ index 7f654c220b..3f10c78c2f 100644
2222
if (parent != tp->parent) return (parent < tp->parent) ? -1 : 1; // Compare absolute pointers
2323
if (offset != tp->offset) return (offset < tp->offset) ? -1 : 1;
2424
--
25-
2.48.1
25+
2.50.1
2626

src/setup-ghidra-source.cmake

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
5252
# TODO: CMake only likes numeric characters in the version string....
5353
set(ghidra_head_version "12.0")
5454
set(ghidra_version "${ghidra_head_version}")
55-
set(ghidra_head_git_tag "0a97fd8feb13c13c3f635122e290782050cf5bc7")
55+
set(ghidra_head_git_tag "42794bc3fa63b707eba3bf055228b12d3085f5eb")
5656
set(ghidra_git_tag "${ghidra_head_git_tag}")
5757
set(ghidra_shallow FALSE)
5858
set(ghidra_patches
@@ -61,10 +61,9 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
6161
"${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign
6262
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch"
6363
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
64-
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch"
65-
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch"
66-
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch"
67-
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0006-decompiler-Fix-strict-weak-ordering-TypePartialEnum.patch"
64+
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0003-Ignore-floating-point-test-due-to-compilation-differ.patch"
65+
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0004-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch"
66+
"${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0005-decompiler-Fix-strict-weak-ordering-TypePartialEnum.patch"
6867
)
6968
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
7069
else()

tests/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Tests from ghidra repo
1111
#
1212

13-
add_executable(sleigh_ghidra_test
13+
add_executable(sleigh_decomp_test
1414
${sleigh_core_source_list}
1515
${sleigh_deccore_source_list}
1616
${sleigh_source_list}
@@ -27,31 +27,31 @@ add_executable(sleigh_ghidra_test
2727
)
2828

2929
# if(sleigh_RELEASE_IS_HEAD)
30-
# target_sources(sleigh_ghidra_test PRIVATE
30+
# target_sources(sleigh_decomp_test PRIVATE
3131
# )
3232
# endif()
3333

34-
target_compile_features(sleigh_ghidra_test PRIVATE cxx_std_11)
35-
target_include_directories(sleigh_ghidra_test PRIVATE "${library_root}")
34+
target_compile_features(sleigh_decomp_test PRIVATE cxx_std_11)
35+
target_include_directories(sleigh_decomp_test PRIVATE "${library_root}")
3636
include(CheckIncludeFileCXX)
3737
check_include_file_cxx(termios.h HAVE_TERMIOS_H)
3838
if(HAVE_TERMIOS_H)
39-
target_compile_definitions(sleigh_ghidra_test PRIVATE
39+
target_compile_definitions(sleigh_decomp_test PRIVATE
4040
__TERMINAL__
4141
)
4242
endif()
43-
sleigh_add_optional_defines(sleigh_ghidra_test PRIVATE)
43+
sleigh_add_optional_defines(sleigh_decomp_test PRIVATE)
4444

45-
target_link_libraries(sleigh_ghidra_test PRIVATE ZLIB::ZLIB)
45+
target_link_libraries(sleigh_decomp_test PRIVATE ZLIB::ZLIB)
4646

4747
add_test(
48-
NAME sleigh_ghidra_unittest
49-
COMMAND sleigh_ghidra_test -sleighpath "${PROJECT_BINARY_DIR}" unittests
48+
NAME sleigh_decomp_unittest
49+
COMMAND sleigh_decomp_test -sleighpath "${PROJECT_BINARY_DIR}" unittests
5050
)
5151

5252
add_test(
53-
NAME sleigh_ghidra_datatest
54-
COMMAND sleigh_ghidra_test -sleighpath "${PROJECT_BINARY_DIR}"
53+
NAME sleigh_decomp_datatest
54+
COMMAND sleigh_decomp_test -sleighpath "${PROJECT_BINARY_DIR}"
5555
-path "${library_root}/../datatests"
5656
datatests
5757
)

0 commit comments

Comments
 (0)