Skip to content

Commit 5cffc8a

Browse files
committed
Get the Ghidra version in our build process.
1 parent 90bffc0 commit 5cffc8a

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

build.gradle.kts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.Properties
2+
13
// This cannot be used inside the `plugins` block, but can (and is) used elsewhere and
24
// should match the version used inside the `plugins` block.
35
val kotlinVersion = "1.9.23"
@@ -25,9 +27,63 @@ plugins {
2527
// for the correction version of Gradle to use for the Ghidra installation you specify.
2628

2729
// ----------------------START "DO NOT MODIFY" SECTION------------------------------
28-
val ghidraInstallDir: String? = System.getenv("GHIDRA_INSTALL_DIR") ?: project.findProperty("GHIDRA_INSTALL_DIR") as String?
30+
val ghidraInstallDir: String? =
31+
System.getenv("GHIDRA_INSTALL_DIR") ?: project.findProperty("GHIDRA_INSTALL_DIR") as String?
32+
33+
data class Version(
34+
val major: Int,
35+
val minor: Int,
36+
val patch: Int = 0,
37+
) : Comparable<Version> {
38+
override fun compareTo(other: Version): Int =
39+
when {
40+
major != other.major -> major.compareTo(other.major)
41+
minor != other.minor -> minor.compareTo(other.minor)
42+
else -> patch.compareTo(other.patch)
43+
}
44+
45+
companion object {
46+
fun parse(version: String): Version {
47+
val parts = version.split(".")
48+
return Version(
49+
major = parts[0].toInt(),
50+
minor = parts.getOrNull(1)?.toInt() ?: 0,
51+
patch = parts.getOrNull(2)?.toInt() ?: 0,
52+
)
53+
}
54+
}
55+
}
2956

3057
if (ghidraInstallDir != null) {
58+
val ghidraPropsFile = file("$ghidraInstallDir/Ghidra/application.properties")
59+
if (!ghidraPropsFile.exists()) {
60+
throw GradleException("Unable to find the Ghidra properties file")
61+
}
62+
val ghidraProps =
63+
ghidraPropsFile.inputStream().use { stream ->
64+
Properties().apply { load(stream) }
65+
}
66+
val (ghidraAppName, ghidraAppVersion, ghidraReleaseName) =
67+
run {
68+
val appName =
69+
ghidraProps.getProperty("application.name")
70+
?: throw GradleException("Unable to get Ghidra app name")
71+
val appVersion =
72+
ghidraProps.getProperty("application.version")
73+
?: throw GradleException("Unable to get Ghidra app version")
74+
val releaseName =
75+
ghidraProps.getProperty("application.release.name")
76+
?: throw GradleException("Unable to Ghidra release name")
77+
Triple(appName, appVersion, releaseName)
78+
}
79+
if (ghidraAppName != "Ghidra") {
80+
throw GradleException("GHIDRA_INSTALL_DIR does not point to a valid Ghidra installation")
81+
}
82+
if (ghidraReleaseName != "PUBLIC") {
83+
logger.warn("Building against a non-PUBLIC version of Ghidra. Release name is $ghidraReleaseName.")
84+
}
85+
// TODO: Handle different source sets based on Ghidra version.
86+
3187
apply(from = File(ghidraInstallDir).canonicalPath + "/support/buildExtension.gradle")
3288
} else {
3389
throw GradleException("GHIDRA_INSTALL_DIR is not defined!")

0 commit comments

Comments
 (0)