Skip to content

Commit

Permalink
More complete patch for all files with missing include guard (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekilmer authored Jul 29, 2022
1 parent 01cf5e5 commit b3e26db
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 66 deletions.

This file was deleted.

137 changes: 137 additions & 0 deletions patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
From 44c439d879c18c2873d5605821132957680a4405 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <[email protected]>
Date: Thu, 28 Jul 2022 09:20:03 -0400
Subject: [PATCH] Add include guards to decompiler C++ headers

---
Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh | 6 ++++++
Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh | 5 +++++
.../Features/Decompiler/src/decompile/cpp/slgh_compile.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh | 6 ++++++
6 files changed, 32 insertions(+)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
index 875d3bb78..6ade01ecc 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
@@ -17,6 +17,9 @@
/// \file bfd_arch.hh
/// \brief Specific implementation of Architecture using GNU BFD libraries

+#ifndef __BFD_ARCH__
+#define __BFD_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage_bfd.hh"

@@ -47,3 +50,5 @@ class BfdArchitecture : public SleighArchitecture {
BfdArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
virtual ~BfdArchitecture(void) {}
};
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
index 364a5258d..edd6ce865 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
@@ -14,8 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#ifndef __GRAPH__
+#define __GRAPH__
+
#include "funcdata.hh"

extern void dump_dataflow_graph(Funcdata &data,ostream &s);
extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s);
extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s);
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
index 3ca912dd6..0b70d8b22 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
@@ -16,6 +16,9 @@
/// \file ifaceterm.hh
/// \brief Add some terminal capabilities to the command-line interface (IfaceStatus)

+#ifndef __IFACE_TERM__
+#define __IFACE_TERM__
+
#include "interface.hh"

#ifdef __TERMINAL__
@@ -48,3 +51,5 @@ class IfaceTerm : public IfaceStatus {
virtual void popScript(void);
virtual bool isStreamFinished(void) const;
};
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
index 2245840a0..490abf901 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
@@ -15,6 +15,10 @@
*/
/// \file raw_arch.hh
/// \brief Bare bones capability for treating a file as a raw executable image
+
+#ifndef __RAW_ARCH__
+#define __RAW_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage.hh"

@@ -46,3 +50,4 @@ class RawBinaryArchitecture : public SleighArchitecture {
virtual ~RawBinaryArchitecture(void) {}
};

+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
index e7ab19185..8fd9ba2fd 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
@@ -16,6 +16,9 @@
/// \file slgh_compile.hh
/// \brief High-level control of the sleigh compilation process

+#ifndef __SLGH_COMPILE__
+#define __SLGH_COMPILE__
+
#include "sleighbase.hh"
#include "pcodecompile.hh"
#include "filemanage.hh"
@@ -446,3 +449,5 @@ class SleighCompile : public SleighBase {

extern SleighCompile *slgh; ///< A global reference to the SLEIGH compiler accessible to the parse functions
extern int yydebug; ///< Debug state for the SLEIGH parse functions
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
index d395fb8a3..6371148b0 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
@@ -15,6 +15,10 @@
*/
/// \file xml_arch.hh
/// \brief Extension to read executables based on an XML format
+
+#ifndef __XML_ARCH__
+#define __XML_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage_xml.hh"

@@ -45,3 +49,5 @@ class XmlArchitecture : public SleighArchitecture {
XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
virtual ~XmlArchitecture(void) {}
};
+
+#endif
--
2.37.1

This file was deleted.

137 changes: 137 additions & 0 deletions patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
From 143296b212e6c3c8bc8cc1e0d88511f5bbc858ff Mon Sep 17 00:00:00 2001
From: Eric Kilmer <[email protected]>
Date: Thu, 28 Jul 2022 09:20:03 -0400
Subject: [PATCH] Add include guards to decompiler C++ headers

---
Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh | 6 ++++++
Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh | 5 +++++
.../Features/Decompiler/src/decompile/cpp/slgh_compile.hh | 5 +++++
Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh | 6 ++++++
6 files changed, 32 insertions(+)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
index 9d1f21d04..4f5c8ac2b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
@@ -17,6 +17,9 @@
/// \file bfd_arch.hh
/// \brief Specific implementation of Architecture using GNU BFD libraries

+#ifndef __BFD_ARCH__
+#define __BFD_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage_bfd.hh"

@@ -45,3 +48,5 @@ class BfdArchitecture : public SleighArchitecture {
BfdArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
virtual ~BfdArchitecture(void) {}
};
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
index 364a5258d..edd6ce865 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
@@ -14,8 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#ifndef __GRAPH__
+#define __GRAPH__
+
#include "funcdata.hh"

extern void dump_dataflow_graph(Funcdata &data,ostream &s);
extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s);
extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s);
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
index 3ca912dd6..0b70d8b22 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
@@ -16,6 +16,9 @@
/// \file ifaceterm.hh
/// \brief Add some terminal capabilities to the command-line interface (IfaceStatus)

+#ifndef __IFACE_TERM__
+#define __IFACE_TERM__
+
#include "interface.hh"

#ifdef __TERMINAL__
@@ -48,3 +51,5 @@ class IfaceTerm : public IfaceStatus {
virtual void popScript(void);
virtual bool isStreamFinished(void) const;
};
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
index 7457a6303..a99fcbcd8 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
@@ -15,6 +15,10 @@
*/
/// \file raw_arch.hh
/// \brief Bare bones capability for treating a file as a raw executable image
+
+#ifndef __RAW_ARCH__
+#define __RAW_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage.hh"

@@ -44,3 +48,4 @@ class RawBinaryArchitecture : public SleighArchitecture {
virtual ~RawBinaryArchitecture(void) {}
};

+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
index edb19aed3..78c8ad21c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
@@ -16,6 +16,9 @@
/// \file slgh_compile.hh
/// \brief High-level control of the sleigh compilation process

+#ifndef __SLGH_COMPILE__
+#define __SLGH_COMPILE__
+
#include "sleighbase.hh"
#include "pcodecompile.hh"
#include "filemanage.hh"
@@ -446,3 +449,5 @@ class SleighCompile : public SleighBase {

extern SleighCompile *slgh; ///< A global reference to the SLEIGH compiler accessible to the parse functions
extern int yydebug; ///< Debug state for the SLEIGH parse functions
+
+#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
index 4d404e6ad..0154582b0 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
@@ -15,6 +15,10 @@
*/
/// \file xml_arch.hh
/// \brief Extension to read executables based on an XML format
+
+#ifndef __XML_ARCH__
+#define __XML_ARCH__
+
#include "sleigh_arch.hh"
#include "loadimage_xml.hh"

@@ -43,3 +47,5 @@ class XmlArchitecture : public SleighArchitecture {
XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
virtual ~XmlArchitecture(void) {}
};
+
+#endif
--
2.37.1

4 changes: 2 additions & 2 deletions src/setup-ghidra-source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(ghidra_shallow TRUE)
set(ghidra_patches
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0002-Add-include-guard-to-decompiler-terminal-interface-h.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch"
)

# Ghidra pinned commits used for pinning last known working HEAD commit
Expand All @@ -35,7 +35,7 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0003-Add-include-guard-to-decompiler-terminal-interface-h.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch"
)
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
else()
Expand Down

0 comments on commit b3e26db

Please sign in to comment.