2021-03-17 22:22:43 +00:00
|
|
|
/* ###
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-03-26 17:45:32 +00:00
|
|
|
apply plugin: 'eclipse'
|
2019-04-09 15:59:17 +00:00
|
|
|
|
|
|
|
apply from: 'gradle/root/eclipse.gradle'
|
|
|
|
apply from: "gradle/support/eclipseLauncher.gradle"
|
2019-07-18 17:39:17 +00:00
|
|
|
apply from: "gradle/support/loadApplicationProperties.gradle"
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************************
|
2023-02-23 15:08:17 +00:00
|
|
|
* Print current Gradle version and make sure the correct version of gradle is being used
|
|
|
|
***************************************************************************************/
|
2019-06-30 06:22:49 +00:00
|
|
|
import org.gradle.util.GradleVersion;
|
2023-02-23 15:08:17 +00:00
|
|
|
println "Gradle: " + GradleVersion.current().version
|
2023-04-20 10:19:14 +00:00
|
|
|
checkGradleVersion()
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
/***************************************************************************************
|
|
|
|
* Define the location of JAVA_HOME
|
|
|
|
***************************************************************************************/
|
|
|
|
if (System.env.JAVA_HOME) {
|
|
|
|
// Allow Gradle's default JAVA_HOME to be overridden by an environment variable we set
|
|
|
|
project.ext.JAVA_HOME = System.env.JAVA_HOME;
|
|
|
|
}
|
|
|
|
else {
|
2019-09-26 16:08:10 +00:00
|
|
|
project.ext.JAVA_HOME = "${System.properties.'java.home'}"
|
2019-03-26 17:45:32 +00:00
|
|
|
}
|
2019-09-13 17:00:50 +00:00
|
|
|
|
|
|
|
/***************************************************************************************
|
|
|
|
* Make sure Gradle wasn't launched with a 32-bit Java...it can cause confusing errors
|
|
|
|
***************************************************************************************/
|
|
|
|
if ("32".equals(System.getProperty("sun.arch.data.model"))) {
|
|
|
|
throw new GradleException("\n\n\t32-bit Java detected! Please use 64-bit Java.\n\n");
|
|
|
|
}
|
|
|
|
|
2024-05-01 13:56:08 +00:00
|
|
|
/***************************************************************************************
|
|
|
|
* Identify supported Python command
|
|
|
|
***************************************************************************************/
|
2024-05-22 21:40:21 +00:00
|
|
|
project.ext.SUPPORTED_PY_VERSIONS = ['3.12', '3.11', '3.10', '3.9', '3.8', '3.7']
|
2024-05-01 13:56:08 +00:00
|
|
|
project.ext.PYTHON3 = findPython3()
|
|
|
|
|
2019-03-26 17:45:32 +00:00
|
|
|
/*********************************************************************************
|
|
|
|
* Define the location of bin repo
|
|
|
|
*********************************************************************************/
|
|
|
|
project.ext.GHIDRA_GROUP = "Z Ghidra"
|
|
|
|
project.ext.ROOT_PROJECT_DIR = projectDir.absolutePath
|
2021-04-07 14:51:05 +00:00
|
|
|
project.ext.BIN_REPO = file("${projectDir}/../ghidra.bin").absolutePath
|
|
|
|
project.ext.DEPS_DIR = file("${projectDir}/dependencies")
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Prevent forked Java processes from stealing focus
|
|
|
|
*********************************************************************************/
|
|
|
|
allprojects {
|
|
|
|
tasks.withType(JavaForkOptions) {
|
|
|
|
jvmArgs '-Djava.awt.headless=true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:05:42 +00:00
|
|
|
/*********************************************************************************
|
|
|
|
* Use flat directory-style repository if flatRepo directory is present.
|
|
|
|
*********************************************************************************/
|
2021-04-07 14:51:05 +00:00
|
|
|
def flatRepo = file("${DEPS_DIR}/flatRepo")
|
|
|
|
if (flatRepo.isDirectory()) {
|
2019-06-26 15:05:42 +00:00
|
|
|
allprojects {
|
|
|
|
repositories {
|
GT-3317
moved generic graph interfaces to features graph module
created graph service broker
first commit of program graph module adapted to new graph api
GT-3317 connected listeners, documented and prettied up code
changed GhidraGraph to preserve order of created graph. Removed edge
filtering from initial program graph display
GT-3317 added exporters for supported formats
GT-3317 fixed GhidraGraph bug where it lost edges
updates
changed to new action builder
removed icons, improved AttributeFilters
removed DialogComponentProviderBuilder
fixed generic alphabet soup
added vertex name updating.
GT-3317 added threading to sugiyama
adapted to take advantage of multi-threaded edge crossing reduction in
circle layout
eliminated parallel edges, improved sizing, updated jungrapht version
GT-3317 fixing AST graph and moving modules and packages
started help
GT-3317 updated min-cross and color selections
uses min-cross that optimizes for graph size
GT-3317 help, javadocs
changes from review comments and cleaning up warnings and simplifying
exporter code
fixing warnings, simplifying unnecessarily complicated code
more changes from review
more changes from review, simplifications. removed unnecessary
threading, renamed vertex, edge, etc
GT-3317 squashed many commits to make rebase easier. Mostly changes from
first code review.
2019-12-06 16:32:03 +00:00
|
|
|
mavenLocal()
|
2019-06-26 15:05:42 +00:00
|
|
|
mavenCentral()
|
|
|
|
jcenter()
|
2021-04-07 14:51:05 +00:00
|
|
|
flatDir name: "flat", dirs:["$flatRepo"]
|
2019-06-26 15:05:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 22:38:18 +00:00
|
|
|
else {
|
|
|
|
File f = file("ghidra.repos.config")
|
2019-08-13 22:50:11 +00:00
|
|
|
if (!f.exists()) {
|
2019-08-21 22:38:18 +00:00
|
|
|
throw new GradleException("\n\n\n\tUnable to find the local maven repo." +
|
2021-04-16 11:25:08 +00:00
|
|
|
" Ensure you have created the ${flatRepo.getName()} directory or ${f.getName()} file.\n\n\n");
|
2019-08-13 22:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 15:05:42 +00:00
|
|
|
|
2019-03-26 17:45:32 +00:00
|
|
|
/*********************************************************************************
|
|
|
|
* Imports
|
|
|
|
* For these tasks to be available on all subprojects, this MUST be placed
|
|
|
|
* after the "setupJava" configuration.
|
|
|
|
*
|
|
|
|
* Note: Distribution.gradle and distributionNew.gradle must not be applied at the
|
|
|
|
* same time; they have tasks with the same name. The former is the 'old' way
|
|
|
|
* of building (produces several zips) while the former produces only one.
|
|
|
|
* Eventually distribution.gradle will be removed entirely, but it is included
|
|
|
|
* here for the time being for those who need it.
|
|
|
|
*********************************************************************************/
|
2021-07-07 13:25:39 +00:00
|
|
|
apply from: "GPL/utils.gradle" // adds utilities used in both Ghidra and GPL projects
|
|
|
|
apply from: "GPL/nativePlatforms.gradle" // adds native platform support
|
|
|
|
apply from: "gradle/root/test.gradle" // adds tasks for running tests
|
|
|
|
apply from: "gradle/root/prepDev.gradle" // adds prepDev task for each subproject
|
|
|
|
apply from: 'gradle/root/distribution.gradle' // adds zip tasks
|
|
|
|
apply from: 'gradle/root/usage.gradle' // adds task documentation
|
|
|
|
apply from: "gradle/root/svg.gradle" // adds task to process svg files
|
|
|
|
apply from: "gradle/root/jacoco.gradle" // adds tasks for java code coverage
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
apply plugin: 'base'
|
|
|
|
clean {
|
|
|
|
delete "$buildDir"
|
|
|
|
}
|
|
|
|
|
2023-04-20 10:19:14 +00:00
|
|
|
/*********************************************************************************
|
|
|
|
* Throws a GradleException if the current Gradle version is outside of the supported
|
|
|
|
* Gradle version range defined in application.properties.
|
|
|
|
*
|
|
|
|
* NOTE: This function is duplicated in buildExtension.gradle
|
|
|
|
*********************************************************************************/
|
|
|
|
import org.gradle.util.GradleVersion;
|
|
|
|
def checkGradleVersion() {
|
|
|
|
GradleVersion min = null;
|
|
|
|
GradleVersion max = null;
|
|
|
|
try {
|
|
|
|
min = GradleVersion.version("${rootProject.GRADLE_MIN}")
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e) {
|
|
|
|
String defaultMin = "1.0"
|
|
|
|
println "Invalid minimum Gradle version specified in application.properties...using ${defaultMin}"
|
|
|
|
min = GradleVersion.version(defaultMin)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (rootProject.GRADLE_MAX) {
|
|
|
|
max = GradleVersion.version("${rootProject.GRADLE_MAX}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e) {
|
|
|
|
println "Invalid maximum Gradle version specified in application.properties...ignoring"
|
|
|
|
}
|
|
|
|
String gradleRange = "at least ${min}"
|
|
|
|
if (max) {
|
|
|
|
gradleRange += " and less than ${max}"
|
|
|
|
}
|
|
|
|
if (GradleVersion.current() < min || (max && GradleVersion.current() >= max)) {
|
|
|
|
throw new GradleException("Requires ${gradleRange}, but was run with $gradle.gradleVersion")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-01 13:56:08 +00:00
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Identifies supported python3 command to be used when building and checks for pip install.
|
|
|
|
* Although warnings may be produced no exception is thrown since python only required
|
|
|
|
* for specific build tasks and is not required for prepdev
|
|
|
|
*********************************************************************************/
|
|
|
|
def checkPythonVersion(String pyCmd) {
|
|
|
|
try {
|
|
|
|
def stdout = new ByteArrayOutputStream()
|
|
|
|
exec {
|
|
|
|
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
|
|
|
|
standardOutput = stdout
|
|
|
|
errorOutput = OutputStream.nullOutputStream()
|
|
|
|
}
|
|
|
|
def version = "$stdout".strip()
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
return "ABSENT"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def checkPip(String pyCmd) {
|
|
|
|
try {
|
|
|
|
def stdout = new ByteArrayOutputStream()
|
|
|
|
exec {
|
|
|
|
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
|
|
|
|
standardOutput = stdout
|
|
|
|
errorOutput = OutputStream.nullOutputStream()
|
|
|
|
}
|
|
|
|
def version = "$stdout".strip();
|
|
|
|
if (version.length() == 0) {
|
|
|
|
println("Warning: Python3 pip not installed (required for build)")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println("Python3 pip version: ${version}")
|
|
|
|
}
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
println("Warning: Python3 pip not installed (required for build)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def findPython3() {
|
|
|
|
for (pyCmd in ['py', 'python3', 'python']) {
|
|
|
|
def pyVer = checkPythonVersion(pyCmd)
|
|
|
|
if (pyVer in SUPPORTED_PY_VERSIONS) {
|
|
|
|
println("Python3 command: ${pyCmd} (version ${pyVer})")
|
|
|
|
checkPip(pyCmd)
|
|
|
|
return pyCmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (pyVer in SUPPORTED_PY_VERSIONS) {
|
|
|
|
def pyCmd = "python${pyVer}"
|
|
|
|
if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) {
|
|
|
|
println("Python3 command: ${pyCmd}")
|
|
|
|
checkPip(pyCmd)
|
|
|
|
return pyCmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Don't fail until task execution. Just let "python3" fail.
|
2024-05-22 21:40:21 +00:00
|
|
|
// Force use of non-existent python3.7 instead of unsupported python version
|
2024-05-01 13:56:08 +00:00
|
|
|
// which should fail if a python build is performed.
|
|
|
|
println("Warning: Python3 command not found (required for build)")
|
2024-05-22 21:40:21 +00:00
|
|
|
return 'python3.7'
|
2024-05-01 13:56:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 17:45:32 +00:00
|
|
|
/******************************************************************************************
|
|
|
|
*
|
|
|
|
* Utility methods used by multiple build.gradle files
|
|
|
|
*
|
|
|
|
*****************************************************************************************/
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Returns a relative path from the root (ghidra) to the project's directory.
|
|
|
|
* This is used to determine where inside a zip file to place a particular artifact
|
|
|
|
* (we want them to all start at "Ghidra/...."
|
|
|
|
*
|
|
|
|
* ie: If we have the following:
|
|
|
|
* project dir = /Users/<blah>/git/ghidra.master/ghidra/Ghidra/Features/Base
|
|
|
|
* root project = /Users/<blah>/git/ghidra.master/ghidra/Ghidra
|
|
|
|
*
|
|
|
|
* Then the returned value will be:
|
|
|
|
* Ghidra/Features/Base
|
|
|
|
*
|
|
|
|
* There are two special cases - Projects that live outside ghidra and projects
|
|
|
|
* that are extension projects. Projects that live outside ghidra will
|
|
|
|
* have zip paths that make the project appear as if it did live in ghidra.
|
|
|
|
* Projects that extend other projects will appear as though they live in the project
|
|
|
|
* that they extend. See the note at the top of the distribution.gradle file for more details.
|
|
|
|
*********************************************************************************/
|
|
|
|
def getZipPath(Project p) {
|
|
|
|
|
|
|
|
String path = getGhidraRelativePath(p)
|
|
|
|
|
|
|
|
// if the project has been defined as an "extension" to another project, change its
|
|
|
|
// zip path to the path of its "base" project. A project is an extension if it has
|
|
|
|
// defined an "extendsFromProject" property.
|
|
|
|
|
|
|
|
if (p.hasProperty('extendsFromProject')) {
|
|
|
|
Project baseProject = p.extendsFromProject
|
|
|
|
path = getGhidraRelativePath(baseProject);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p.hasProperty("pathExtension")) {
|
|
|
|
path = path + "/" + p.pathExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
def getBaseProjectName(Project p) {
|
|
|
|
if (p.hasProperty('extendsFromProject')) {
|
|
|
|
Project baseProject = p.extendsFromProject
|
|
|
|
return baseProject.name
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.name
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Returns the current date formatted as yyyyMMdd.
|
|
|
|
*********************************************************************************/
|
|
|
|
def getCurrentDate() {
|
|
|
|
|
|
|
|
def date = new Date()
|
|
|
|
def formattedDate = date.format('yyyyMMdd')
|
|
|
|
return formattedDate
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Returns the current date/time formatted as yyyyMMdd-HHmm.
|
|
|
|
*********************************************************************************/
|
|
|
|
def getCurrentDateTime() {
|
|
|
|
|
|
|
|
def date = new Date()
|
|
|
|
def formattedDate = date.format('yyyyMMdd-HHmm')
|
|
|
|
return formattedDate
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Returns the current date/time formatted as yyyy-MMM-dd HHmm z.
|
|
|
|
*********************************************************************************/
|
|
|
|
def getCurrentDateTimeLong() {
|
|
|
|
|
|
|
|
def date = new Date()
|
|
|
|
def formattedDate = date.format('yyyy-MMM-dd HHmm z')
|
|
|
|
return formattedDate
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
2022-03-23 16:33:02 +00:00
|
|
|
* Returns a list of all the external library paths declared as dependencies for the
|
|
|
|
* given project
|
2019-03-26 17:45:32 +00:00
|
|
|
*
|
|
|
|
*********************************************************************************/
|
2022-03-23 16:33:02 +00:00
|
|
|
List<String> getExternalRuntimeDependencies(Project project) {
|
|
|
|
List<String> list = new ArrayList<String>()
|
2019-03-26 17:45:32 +00:00
|
|
|
|
2021-04-12 15:07:06 +00:00
|
|
|
if (project.configurations.find { it.name == 'api' }) {
|
2022-03-23 16:33:02 +00:00
|
|
|
list.addAll(getExternalRuntimeDependencies(project, project.configurations.api));
|
2021-04-12 15:07:06 +00:00
|
|
|
}
|
|
|
|
if (project.configurations.find { it.name == 'implementation' }) {
|
2022-03-23 16:33:02 +00:00
|
|
|
list.addAll(getExternalRuntimeDependencies(project, project.configurations.implementation));
|
2021-04-12 15:07:06 +00:00
|
|
|
}
|
|
|
|
if (project.configurations.find { it.name == 'runtimeOnly' }) {
|
2022-03-23 16:33:02 +00:00
|
|
|
list.addAll(getExternalRuntimeDependencies(project, project.configurations.runtimeOnly));
|
2021-04-12 15:07:06 +00:00
|
|
|
}
|
2020-12-08 18:03:36 +00:00
|
|
|
|
2022-03-23 16:33:02 +00:00
|
|
|
return list
|
2020-12-08 18:03:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 16:33:02 +00:00
|
|
|
List<String> getExternalRuntimeDependencies(Project project, Configuration configuration) {
|
|
|
|
List<String> list = new ArrayList<>();
|
2020-12-08 18:03:36 +00:00
|
|
|
configuration.dependencies.each { dep ->
|
2020-12-10 22:40:37 +00:00
|
|
|
|
2019-12-20 20:02:40 +00:00
|
|
|
// if the dependency is an external jar
|
2020-12-08 18:03:36 +00:00
|
|
|
if (dep instanceof ExternalDependency) {
|
2020-12-10 22:40:37 +00:00
|
|
|
String name = dep.getName()
|
|
|
|
Set<String> classifiers = dep.artifacts.classifier
|
|
|
|
String group = dep.getGroup()
|
|
|
|
String version = dep.getVersion()
|
|
|
|
String searchString = name
|
|
|
|
|
|
|
|
if (version != null) {
|
|
|
|
searchString = name+"-"+version;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!classifiers.empty) {
|
|
|
|
String cls = classifiers.first()
|
|
|
|
if (cls != null) {
|
|
|
|
searchString+= "-$cls"
|
|
|
|
}
|
|
|
|
}
|
2021-05-24 20:11:40 +00:00
|
|
|
// search for the dependency in the runtime class path
|
|
|
|
String depPath = project.configurations.runtimeClasspath.find {
|
|
|
|
it.name.contains(searchString)
|
2020-12-10 22:40:37 +00:00
|
|
|
}
|
2021-05-24 20:11:40 +00:00
|
|
|
|
2020-12-10 22:40:37 +00:00
|
|
|
if (depPath == null) {
|
|
|
|
println("****************DID NOT FIND DEPENDENCY: name = "+name+" version = "+version)
|
2019-12-20 20:02:40 +00:00
|
|
|
}
|
|
|
|
// if we found the path, then add it to the list
|
2020-12-08 18:03:36 +00:00
|
|
|
if (depPath) {
|
2022-03-23 16:33:02 +00:00
|
|
|
list.add(depPath)
|
2019-12-20 20:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 16:33:02 +00:00
|
|
|
return list;
|
2020-12-08 18:03:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 20:11:40 +00:00
|
|
|
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
*
|
|
|
|
* Creates a file that lists the libraries used by each module.
|
|
|
|
*
|
|
|
|
******************************************************************************************/
|
|
|
|
String generateLibraryDependencyMapping() {
|
|
|
|
File libsFile = file("$buildDir/libraryDependencies.txt")
|
|
|
|
|
|
|
|
// Check to make sure the build folder exists - if it doesn't, the 'libsFile.withWriter'
|
|
|
|
// call (below) will fail miserably.
|
|
|
|
def buildFolder = file ("$buildDir")
|
|
|
|
if (!buildFolder.exists()) {
|
|
|
|
buildFolder.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
libsFile.withWriter { out ->
|
|
|
|
subprojects { p ->
|
2019-04-09 15:59:17 +00:00
|
|
|
p.plugins.withType(JavaPlugin) {
|
2022-03-23 16:33:02 +00:00
|
|
|
List<String> libs = getExternalRuntimeDependencies(p);
|
2019-04-09 15:59:17 +00:00
|
|
|
if (libs != null) {
|
|
|
|
out.println "Module: $p.name"
|
2022-03-23 16:33:02 +00:00
|
|
|
libs.each { path ->
|
2019-04-09 15:59:17 +00:00
|
|
|
out.println "\t$path"
|
|
|
|
}
|
2019-03-26 17:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return libsFile.absolutePath
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:59:17 +00:00
|
|
|
task allSleighCompile {
|
2019-03-26 17:45:32 +00:00
|
|
|
}
|