|
| 1 | +import java.util.Properties |
| 2 | + |
1 | 3 | // This cannot be used inside the `plugins` block, but can (and is) used elsewhere and |
2 | 4 | // should match the version used inside the `plugins` block. |
3 | 5 | val kotlinVersion = "1.9.23" |
@@ -25,9 +27,63 @@ plugins { |
25 | 27 | // for the correction version of Gradle to use for the Ghidra installation you specify. |
26 | 28 |
|
27 | 29 | // ----------------------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 | +} |
29 | 56 |
|
30 | 57 | 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 | + |
31 | 87 | apply(from = File(ghidraInstallDir).canonicalPath + "/support/buildExtension.gradle") |
32 | 88 | } else { |
33 | 89 | throw GradleException("GHIDRA_INSTALL_DIR is not defined!") |
|
0 commit comments