@@ -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