Skip to content

Ghidra is a software reverse engineering (SRE) framework

Add OpenBSD support for x86_64 and arm_64.

Kurt Millere02b069461b5
diff --git a/GPL/DemanglerGnu/build.gradle b/GPL/DemanglerGnu/build.gradle
index 13b8cf7f33..1fa482295e 100644
--- a/GPL/DemanglerGnu/build.gradle
+++ b/GPL/DemanglerGnu/build.gradle
@@ -84,6 +84,8 @@ model {
targetPlatform "mac_arm_64"
targetPlatform "freebsd_x86_64"
targetPlatform "freebsd_arm_64"
+ targetPlatform "openbsd_x86_64"
+ targetPlatform "openbsd_arm_64"
sources {
c {
source {
@@ -108,6 +110,8 @@ model {
targetPlatform "mac_arm_64"
targetPlatform "freebsd_x86_64"
targetPlatform "freebsd_arm_64"
+ targetPlatform "openbsd_x86_64"
+ targetPlatform "openbsd_arm_64"
sources {
c {
source {
diff --git a/GPL/nativeBuildProperties.gradle b/GPL/nativeBuildProperties.gradle
index f2505898f3..5685ddc858 100644
--- a/GPL/nativeBuildProperties.gradle
+++ b/GPL/nativeBuildProperties.gradle
@@ -49,6 +49,10 @@ model {
gcc(Gcc).target(current)
clang(Clang).target(current)
}
+ if (isOpenBSD(current)) {
+ gcc(Gcc).target(current)
+ clang(Clang).target(current)
+ }
if (isWindows(current) && VISUAL_STUDIO_INSTALL_DIR) {
// https://github.com/gradle/gradle-native/issues/617#issuecomment-575735288
visualCpp(VisualCpp) {
diff --git a/GPL/nativePlatforms.gradle b/GPL/nativePlatforms.gradle
index 3b08da6170..5d832b2b14 100644
--- a/GPL/nativePlatforms.gradle
+++ b/GPL/nativePlatforms.gradle
@@ -27,7 +27,9 @@ project.ext.PLATFORMS = [
[name: "mac_x86_64", os: "osx", arch: "x86_64"],
[name: "mac_arm_64", os: "osx", arch: "arm64"],
[name: "freebsd_x86_64", os: "freebsd", arch: "x86_64"],
- [name: "freebsd_arm_64", os: "freebsd", arch: "arm64"]
+ [name: "freebsd_arm_64", os: "freebsd", arch: "arm64"],
+ [name: "openbsd_x86_64", os: "openbsd", arch: "x86_64"],
+ [name: "openbsd_arm_64", os: "openbsd", arch: "arm64"]
]
/*********************************************************************************
@@ -57,6 +59,9 @@ ext.getCurrentPlatformName = {
case ~/FreeBSD.*/:
os = "freebsd"
break
+ case ~/OpenBSD.*/:
+ os = "openbsd"
+ break
default:
throw new GradleException("Unrecognized platform operating system: $os")
}
@@ -132,6 +137,20 @@ ext.isCurrentFreeBSD = {
return isFreeBSD(getCurrentPlatformName())
}
+/*********************************************************************************
+ * Returns true if the given platform is OpenBSD.
+ *********************************************************************************/
+ext.isOpenBSD = { platform_name ->
+ return platform_name.startsWith("openbsd")
+}
+
+/*********************************************************************************
+ * Returns true if the current platform is OpenBSD.
+ *********************************************************************************/
+ext.isCurrentOpenBSD = {
+ return isOpenBSD(getCurrentPlatformName())
+}
+
/*********************************************************************************
* Returns true if the given platform is Windows.
*********************************************************************************/
diff --git a/Ghidra/Features/Decompiler/buildNatives.gradle b/Ghidra/Features/Decompiler/buildNatives.gradle
index d2332bafa4..10556dc6a7 100644
--- a/Ghidra/Features/Decompiler/buildNatives.gradle
+++ b/Ghidra/Features/Decompiler/buildNatives.gradle
@@ -45,6 +45,8 @@ model {
targetPlatform "mac_arm_64"
targetPlatform "freebsd_x86_64"
targetPlatform "freebsd_arm_64"
+ targetPlatform "openbsd_x86_64"
+ targetPlatform "openbsd_arm_64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
@@ -157,6 +159,8 @@ model {
targetPlatform "mac_arm_64"
targetPlatform "freebsd_x86_64"
targetPlatform "freebsd_arm_64"
+ targetPlatform "openbsd_x86_64"
+ targetPlatform "openbsd_arm_64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile b/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
index 61ebba3c72..9dfd2390ee 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
@@ -35,6 +35,13 @@ ifeq ($(OS),Darwin)
OSDIR=mac_x86_64
endif
+ifeq ($(OS),OpenBSD)
+ifeq ($(ARCH),amd64)
+ ARCH_TYPE=-m64
+ OSDIR=openbsd_x86_64
+endif
+endif
+
CXX=g++ -std=c++11
# Debug flags
diff --git a/Ghidra/Features/FileFormats/buildNatives.gradle b/Ghidra/Features/FileFormats/buildNatives.gradle
index 7501715968..010f09bd60 100644
--- a/Ghidra/Features/FileFormats/buildNatives.gradle
+++ b/Ghidra/Features/FileFormats/buildNatives.gradle
@@ -36,6 +36,8 @@ model {
targetPlatform "mac_arm_64"
targetPlatform "freebsd_x86_64"
targetPlatform "freebsd_arm_64"
+ targetPlatform "openbsd_x86_64"
+ targetPlatform "openbsd_arm_64"
sources {
c {
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
index 06e37c2afe..a7c152720f 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -80,6 +80,16 @@ public enum Platform {
*/
FREEBSD_ARM_64(OperatingSystem.FREE_BSD, Architecture.ARM_64, "freebsd_arm_64", ".so", ""),
+ /**
+ * Identifies a OpenBSD x86 64-bit OS.
+ */
+ OPENBSD_X86_64(OperatingSystem.OPEN_BSD, Architecture.X86_64, "openbsd_x86_64", ".so", ""),
+
+ /**
+ * Identifies a OpenBSD ARM 64-bit OS.
+ */
+ OPENBSD_ARM_64(OperatingSystem.OPEN_BSD, Architecture.ARM_64, "openbsd_arm_64", ".so", ""),
+
/**
* Identifies an unsupported OS.
*/
@@ -234,6 +244,11 @@ public enum Platform {
paths.add("/System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64");
paths.add("/System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64h");
}
+ else if (operatingSystem == OperatingSystem.OPEN_BSD) {
+ paths.add("/usr/lib");
+ paths.add("/usr/X11R6/lib");
+ paths.add("/usr/local/lib");
+ }
else if (CURRENT_PLATFORM == WIN_X86_64) {
String windir = System.getenv("SystemRoot");
if (windir != null) {
diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
index e803f338a1..2a2a5464dd 100644
--- a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,6 +20,7 @@ public enum OperatingSystem {
LINUX("Linux"),
MAC_OS_X("Mac OS X"),
FREE_BSD("FreeBSD"),
+ OPEN_BSD("OpenBSD"),
UNSUPPORTED("Unsupported Operating System");
/**
diff --git a/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java b/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
index c47527e807..134c9b6188 100644
--- a/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
+++ b/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
@@ -218,6 +218,7 @@ public class ApplicationUtilities {
case WINDOWS -> new File(getEnvFile("LOCALAPPDATA", true), appName);
case LINUX -> new File("/var/tmp/" + userDirName);
case FREE_BSD -> new File("/var/tmp/" + userDirName);
+ case OPEN_BSD -> new File("/var/tmp/" + userDirName);
case MAC_OS_X -> new File("/var/tmp/" + userDirName);
default -> throw new FileNotFoundException(
"Failed to find the user cache directory: Unsupported operating system.");
@@ -275,6 +276,7 @@ public class ApplicationUtilities {
case WINDOWS -> new File(getEnvFile("APPDATA", true), versionedSubdir);
case LINUX -> new File(userHomeDir, ".config/" + versionedSubdir);
case FREE_BSD -> new File(userHomeDir, ".config/" + versionedSubdir);
+ case OPEN_BSD -> new File(userHomeDir, ".config/" + versionedSubdir);
case MAC_OS_X -> new File(userHomeDir, "Library/" + versionedSubdir);
default -> throw new FileNotFoundException(
"Failed to find the user settings directory: Unsupported operating system.");
diff --git a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/AppConfig.java b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/AppConfig.java
index 9760e5c724..7210f88b1b 100644
--- a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/AppConfig.java
+++ b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/AppConfig.java
@@ -453,6 +453,7 @@ public class AppConfig {
new File(localAppDataDirPath, appName + "/" + userSettingsDirName);
break;
case LINUX:
+ case OPEN_BSD:
userSettingsDir =
new File(userHomeDir, ".config/" + appName + "/" + userSettingsDirName);
break;
diff --git a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/JavaFinder.java b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/JavaFinder.java
index 400f26b6fd..8d82e27b0e 100644
--- a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/JavaFinder.java
+++ b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/JavaFinder.java
@@ -36,7 +36,7 @@ public abstract class JavaFinder {
* The different supported platforms (operating systems).
*/
public enum Platform {
- WINDOWS, MACOS, LINUX;
+ WINDOWS, MACOS, LINUX, OPEN_BSD;
}
/**
@@ -54,6 +54,9 @@ public abstract class JavaFinder {
if (os.contains("mac")) {
return Platform.MACOS;
}
+ if (os.contains("openbsd")) {
+ return Platform.OPEN_BSD;
+ }
}
return Platform.LINUX;
}
@@ -69,6 +72,8 @@ public abstract class JavaFinder {
return new WindowsJavaFinder();
case MACOS:
return new MacJavaFinder();
+ case OPEN_BSD:
+ return new OpenBSDJavaFinder();
case LINUX:
default:
return new LinuxJavaFinder();
diff --git a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/OpenBSDJavaFinder.java b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/OpenBSDJavaFinder.java
new file mode 100644
index 0000000000..79561b5cf0
--- /dev/null
+++ b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/OpenBSDJavaFinder.java
@@ -0,0 +1,38 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.launch;
+
+import java.io.File;
+import java.util.*;
+
+/**
+ * Class responsible for finding Java installations on an OpenBSD system.
+ */
+public class OpenBSDJavaFinder extends LinuxJavaFinder {
+
+ @Override
+ protected List<File> getJavaRootInstallDirs() {
+ File localdir = new File("/usr/local");
+
+ File[] filteredFiles = localdir.listFiles((dir, name) ->
+ name.toLowerCase().startsWith("jdk-")
+ );
+
+ return filteredFiles != null
+ ? new ArrayList<>(Arrays.asList(filteredFiles))
+ : new ArrayList<>();
+ }
+}