Skip to content

Ghidra is a software reverse engineering (SRE) framework

7.9 KB
Raw Blame
/* ###
 * 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.
 */
apply from: "$rootProject.projectDir/gradle/javaProject.gradle"
apply from: "$rootProject.projectDir/gradle/javaTestProject.gradle"
apply from: "$rootProject.projectDir/gradle/nativeProject.gradle"
apply plugin: 'eclipse'
eclipse.project.name = '_Debugger Integration Test'


/*********************************************************************************
 * Build dependencies
 *********************************************************************************/

processIntegrationTestResources {
	duplicatesStrategy = 'exclude'
}

dependencies {
	// integrationtest module may depend on other projects in this repo; add them
	// here 
	def ghidraPath = projectDir.getParentFile().getParentFile().path.replace(File.separator, "/") + "/";
	
	rootProject.subprojects { p ->
		def projectPath = p.projectDir.path.replace(File.separator, "/")
		if (projectPath.startsWith(ghidraPath) && (
			projectPath.contains("/Framework/") ||
			projectPath.contains("/Features/") ||
			projectPath.contains("/Debug/") ||
			projectPath.contains("/Processors/"))) {

			evaluationDependsOn(p.path)

			p.plugins.withType(JavaPlugin) {
				api p
			}
		}
	}

	// some tests use classes in Base, FunctionGraph and PDB
	testImplementation project(path: ':Pty', configuration: 'testArtifacts')
	testImplementation project(path: ':Base', configuration: 'testArtifacts')
	testImplementation project(path: ':Base', configuration: 'integrationTestArtifacts')	
	testImplementation project(path: ':FunctionGraph', configuration: 'testArtifacts')	
	testImplementation project(path: ':PDB', configuration: 'testArtifacts')
	testImplementation project(path: ':GnuDemangler', configuration: 'testArtifacts')

	testImplementation project(path: ':ProposedUtils', configuration: 'testArtifacts')
	testImplementation project(path: ':Framework-TraceModeling', configuration: 'testArtifacts')
	testImplementation project(path: ':Debugger', configuration: 'testArtifacts')
	testImplementation project(path: ':Debugger-rmi-trace', configuration: 'testArtifacts')

	testImplementation project(path: ':GhidraDocs', configuration: 'ghidraClassArtifacts')
}

// For Java 9, we must explicitly export references to the internal classes we are using.
// We export them to all "unnamed" modules, which are modules that don't define themselves
// as a new Java 9 style module.  Ghidra is currently using unnamed modules everywhere.
ext.addExports([
	'java.desktop/sun.awt=ALL-UNNAMED',
	'java.desktop/sun.swing=ALL-UNNAMED',
	'java.desktop/sun.java2d=ALL-UNNAMED'
])

task testSpecimenWin_x86_64 {
	dependsOn 'expCreateProcessWin_x86_64Executable'
	dependsOn 'expCreateThreadExitWin_x86_64Executable'
	//dependsOn 'expCreateThreadSpinWin_x86_64Executable'
	dependsOn 'expPrintWin_x86_64Executable'
	dependsOn 'expSpinWin_x86_64Executable'
	dependsOn 'expReadWin_x86_64Executable'
	dependsOn 'expRegistersWin_x86_64Executable'
	dependsOn 'expStackWin_x86_64Executable'
}

task testSpecimenLinux_x86_64 {
	dependsOn 'expCloneExecExecutable'//Linux_x86_64Executable'
	dependsOn 'expCloneExitLinux_x86_64Executable'
	//dependsOn 'expCloneSpinExecutable'//Linux_x86_64Executable'
	dependsOn 'expForkExecutable'//Linux_x86_64Executable'
	dependsOn 'expPrintLinux_x86_64Executable'
	dependsOn 'expReadLinux_x86_64Executable'
	dependsOn 'expSpinLinux_x86_64Executable'
	dependsOn 'expRegistersLinux_x86_64Executable'
	dependsOn 'expStackLinux_x86_64Executable'
	dependsOn 'expTraceableSleepExecutable'//Linux_x86_64Executable'

	doLast {
		providers.exec {
			workingDir { file("build/os/linux_x86_64") }
			commandLine "strip", "-o", "expSpin.stripped", "expSpin"
		}.result.get()
	}
}

task testSpecimenMac_arm_64 {
	dependsOn 'expCloneExitMac_arm_64Executable'
	dependsOn 'expPrintMac_arm_64Executable'
	dependsOn 'expReadMac_arm_64Executable'
}

// TODO: testSpecimenMac_x86_64 (Intel)
//   will likely need to codesign them to grant debugee-entitlement

model {
	components {
		expCreateProcess(NativeExecutableSpec) {
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expCreateThreadExit(NativeExecutableSpec) {
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expCreateThreadSpin(NativeExecutableSpec) {
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expCloneExec(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
		}
		expCloneExit(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
			targetPlatform "mac_arm_64"
		}
		expCloneSpin(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
		}
		expFork(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
		}
		expPrint(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
			targetPlatform "mac_arm_64"
		}
		expRead(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			targetPlatform "win_x86_64"
			targetPlatform "mac_arm_64"
		}
		expSpin(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expRegisters(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expStack(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
			//targetPlatform "linux_x86_32" // TODO: Test on these
			targetPlatform "win_x86_64"
			targetPlatform "win_x86_32" // TODO: Test on these
		}
		expTraceableSleep(NativeExecutableSpec) {
			targetPlatform "linux_x86_64"
		}
	}

	binaries {
		withType(NativeExecutableBinarySpec) {
			if (toolChain in Gcc) {
				cCompiler.args("-std=c99")
				linker.args("-lpthread")
				linker.args("-lutil")
			}
			if (toolChain in VisualCpp) {
				cCompiler.args("/ZI")
				cppCompiler.define("VS_PROJECT")
				// NB. No /SUBSYSTEM:CONSOLE
				// that creates a subprocess
				linker.args("/SUBSYSTEM:windows", "/DYNAMICBASE", "/NXCOMPAT")
				linker.args("shell32.lib");
			}
			if (rootProject.isWindows(targetPlatform.name)) {
				cppCompiler.define("WIN32")
				cCompiler.define("WIN32")

				cppCompiler.define("_WINDOWS")
				cCompiler.define("_WINDOWS")

				cppCompiler.define("UNICODE")
				cCompiler.define("_UNICODE")

				cppCompiler.define("_UNICODE")
				cCompiler.define("UNICODE")
			}
		}
	}
}

integrationTest {
	dependsOn { project(':Debugger-rmi-trace').assemblePyPackage }
	dependsOn { project(':Debugger-agent-gdb').assemblePyPackage }
	dependsOn { project(':Debugger-agent-lldb').assemblePyPackage }
	dependsOn { project(':Debugger-agent-dbgeng').assemblePyPackage }
	dependsOn { project(':Debugger-agent-drgn').assemblePyPackage }
	dependsOn { project(':Debugger-agent-x64dbg').assemblePyPackage }

	if ("linux_x86_64".equals(rootProject.getCurrentPlatformName())) {
		dependsOn("testSpecimenLinux_x86_64")
	}
	if ("mac_x86_64".equals(rootProject.getCurrentPlatformName())) {
		dependsOn("testSpecimenMac_x86_64")
	}
	if ("win_x86_64".equals(rootProject.getCurrentPlatformName())) {
		dependsOn("testSpecimenWin_x86_64")
	}
}