-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
191 lines (159 loc) · 5.83 KB
/
Copy pathbuild.gradle
File metadata and controls
191 lines (159 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* ###
* 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.
*/
// Builds a Ghidra Extension for a given Ghidra installation.
//
// An absolute path to the Ghidra installation directory must be supplied either by setting the
// GHIDRA_INSTALL_DIR environment variable or Gradle project property:
//
// > export GHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
// > gradle
//
// or
//
// > gradle -PGHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
//
// Alternatively a local.properties file with the 'ghidra.dir' property may be used:
//
// ghidra.dir=<Absolute path to Ghidra>
//
// Gradle should be invoked from the directory of the project to build. Please see the
// application.gradle.version property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
// for the correction version of Gradle to use for the Ghidra installation you specify.
//----------------------START "DO NOT MODIFY" SECTION------------------------------
Properties properties = null
try {
properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())
properties.load(project.rootProject.file("extension.properties").newDataInputStream())
} catch (Exception e) {
// Ignore
}
ext.loadProperty = { prop, localProp ->
if (project.hasProperty(prop)) {
return project.getProperty(prop)
} else if (System.env[prop]) {
return System.env[prop]
} else if (properties != null) {
return properties.getProperty(localProp)
} else {
return null
}
}
def ghidraInstallDir = loadProperty("GHIDRA_INSTALL_DIR", "ghidra.install.dir")
if (ghidraInstallDir == null) {
throw new GradleException("Must specify $prop environment variable or Gradle project property $localProp")
}
def ghidraConfigDir = loadProperty("GHIDRA_CONFIG_DIR", "ghidra.config.dir")
task distributeExtension {
group = "Ghidra"
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
dependsOn ':buildExtension'
}
//----------------------END "DO NOT MODIFY" SECTION-------------------------------
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
repositories {
mavenCentral()
}
configurations {
mockitoAgent
}
dependencies {
// implementation fileTree(dir: ghidraHome, includes: [
// "Ghidra/**/lib/*.jar",
// "Ghidra/Framework/**/lib/*.jar"
// ])
testImplementation 'org.mockito:mockito-core:5.23.0'
mockitoAgent('org.mockito:mockito-core:5.23.0') { transitive = false }
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
test {
// Use the JUnit Platform for running tests
useJUnitPlatform()
// In Groovy, we access the configuration path directly
jvmArgs "-javaagent:${configurations.mockitoAgent.asPath}"
// Optional: Show test results in the console
testLogging {
events "failed"
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
}
ext.findLatestExtension = {
def distDir = file("dist")
return distDir.listFiles()
?.findAll { it.name.endsWith('.zip') }
?.max { it.lastModified() }
}
tasks.register("installExtension", Copy) {
group = "Ghidra"
dependsOn ':buildExtension'
def newestZip = findLatestExtension()
if (!newestZip) {
throw new GradleException("No extension zip found!")
}
// Regex to capture: (ghidra_version) _ (timestamp) _ (extension_name).zip
// Example: ghidra_12.0.4_DEV_20260408_drtti.zip
def matcher = newestZip.name =~ /^(ghidra_.*?)_(\d{8})_(.*?)\.zip$/
if (!matcher.matches()) {
throw new GradleException("Filename ${newestZip.name} doesn't match expected Ghidra format.")
}
def ghidraVer = matcher.group(1) // ghidra_12.0.4_DEV
def extName = matcher.group(3) // drtti
def extensionDir = file("${ghidraConfigDir}/${ghidraVer}/Extensions/")
def installDest = file("${extensionDir.absolutePath}/$extName")
println "Unpacking ${newestZip.name} to ${installDest}"
// Clean existing installation to prevent ghost files
if (installDest.exists()) {
println "Cleaning upp existing installation"
installDest.deleteDir()
}
from zipTree(newestZip)
into extensionDir
outputs.upToDateWhen { false }
}
def getGitVersion() {
def gitTagProvider = providers.exec {
commandLine 'git', 'tag', '--points-at', 'HEAD'
}
def tag = gitTagProvider.standardOutput.asText.get().trim()
return tag.isEmpty() ? "DEV" : tag
}
// 2. Define your task
tasks.register("createRelease", Copy) {
dependsOn ':buildExtension'
// Use the { } closure for lazy evaluation
from {
def newestZip = findLatestExtension()
if (!newestZip) {
throw new GradleException("Build folder is empty. Run buildExtension first.")
}
newestZip
}
into layout.projectDirectory.dir("dist/release")
// Evaluate the tag ONLY when the task runs
rename { filename ->
def tag = getGitVersion()
// properties.name comes from extension.properties
def cleanName = project.name.toLowerCase().replaceAll("\\s", "-")
def name = "${cleanName}_${tag}.zip"
println("Release ${name} created successfully in dist/release folder.")
return name
}
}
// Exclude additional files from the built extension
buildExtension.exclude '.idea/**'
buildExtension.exclude '.gradle/**'