From ff5929e1fcd97dae036469bd2bcd09a6ec414c23 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Thu, 20 Jul 2023 23:16:37 +1000 Subject: [PATCH] Remove unnecessary `sign_extend` patch (#194) The issue was actually with the UBSAN patch to the `sign_extend` function and not the upstream commit itself. When NationalSecurityAgency/ghidra@3c08b44 landed, I had to regenerate the UBSAN patch but I botched the part of the patch that modifies `sign_extend` and introduced this bug. Now that the UBSAN patch no longer touches this function, I should just get rid of the new patch and things should "just work". --- .../0003-Undo-regression-in-sign_extend.patch | 41 ------------------- src/setup-ghidra-source.cmake | 1 - 2 files changed, 42 deletions(-) delete mode 100644 src/patches/HEAD/0003-Undo-regression-in-sign_extend.patch diff --git a/src/patches/HEAD/0003-Undo-regression-in-sign_extend.patch b/src/patches/HEAD/0003-Undo-regression-in-sign_extend.patch deleted file mode 100644 index 70c65f1..0000000 --- a/src/patches/HEAD/0003-Undo-regression-in-sign_extend.patch +++ /dev/null @@ -1,41 +0,0 @@ -From df7483a5c86ebea356eea1fe833aa9fd6e9d44ff Mon Sep 17 00:00:00 2001 -From: Alex Cameron -Date: Wed, 12 Jul 2023 15:39:28 +1000 -Subject: [PATCH 3/3] Undo regression in `sign_extend` - ---- - .../Decompiler/src/decompile/cpp/address.cc | 18 +++++++++++++----- - 1 file changed, 13 insertions(+), 5 deletions(-) - -diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc -index 40526a88f..af856f272 100644 ---- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc -+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc -@@ -666,11 +666,19 @@ uintb uintb_negate(uintb in,int4 size) - uintb sign_extend(uintb in,int4 sizein,int4 sizeout) - - { -- intb sval = in; -- sval <<= (sizeof(intb) - sizein) * 8; -- uintb res = (uintb)(sval >> (sizeout - sizein) * 8); -- res >>= (sizeof(uintb) - sizeout)*8; -- return res; -+ int4 signbit; -+ uintb mask; -+ -+ signbit = sizein*8 - 1; -+ in &= calc_mask(sizein); -+ if (sizein >= sizeout) return in; -+ if ((in>>signbit) != 0) { -+ mask = calc_mask(sizeout); -+ uintb tmp = mask << signbit; // Split shift into two pieces -+ tmp = (tmp<<1) & mask; // In case, everything is shifted out -+ in |= tmp; -+ } -+ return in; - } - - /// Swap the least significant \b size bytes in \b val --- -2.39.2 (Apple Git-143) - diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index fb6ffcf..7029723 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -57,7 +57,6 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD") "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch" "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch" - "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0003-Undo-regression-in-sign_extend.patch" ) string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit) else()