Skip to content

Commit 9478888

Browse files
committed
[ghidra2cpg] Add support for loading Ghidra projects
1 parent e6df189 commit 9478888

File tree

1 file changed

+17
-5
lines changed
  • joern-cli/frontends/ghidra2cpg/src/main/scala/io/joern/ghidra2cpg

1 file changed

+17
-5
lines changed

joern-cli/frontends/ghidra2cpg/src/main/scala/io/joern/ghidra2cpg/Ghidra2Cpg.scala

+17-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@ class Ghidra2Cpg extends X2CpgFrontend[Config] {
4343
var project: GhidraProject = null;
4444

4545
try {
46-
// The 'true' parameter indicates this is a temporary project
47-
project =
48-
GhidraProject.createProject(tempWorkingDir.absolutePathAsString, CommandLineConfig.projectName, true)
49-
program = project.importProgram(inputFile)
50-
addProgramToCpg(program, inputFile.getCanonicalPath, cpg)
46+
// .gpr is the extension of Ghidra projects
47+
if (inputFile.getName().endsWith(".gpr")) {
48+
project = GhidraProject.openProject(inputFile.getParent(), inputFile.getName())
49+
if (!project.getRootFolder().isEmpty()) {
50+
// In the current implementation we use the first domain file
51+
// It is the user's responsibility to provide a Ghidra project with one domain file
52+
val domainFile = project.getRootFolder().getFiles().head
53+
program = project.openProgram("/", domainFile.getName(), true)
54+
addProgramToCpg(program, inputFile.getCanonicalPath, cpg)
55+
}
56+
} else {
57+
// The 'true' parameter indicates this is a temporary project
58+
project =
59+
GhidraProject.createProject(tempWorkingDir.absolutePathAsString, CommandLineConfig.projectName, true)
60+
program = project.importProgram(inputFile)
61+
addProgramToCpg(program, inputFile.getCanonicalPath, cpg)
62+
}
5163
} catch {
5264
case e: Exception =>
5365
e.printStackTrace()

0 commit comments

Comments
 (0)