@@ -43,11 +43,24 @@ 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+ // "/" is the project root for both Windows and Linux
54+ program = project.openProgram(" /" , domainFile.getName(), true )
55+ addProgramToCpg(program, inputFile.getCanonicalPath, cpg)
56+ }
57+ } else {
58+ // The 'true' parameter indicates this is a temporary project
59+ project =
60+ GhidraProject .createProject(tempWorkingDir.absolutePathAsString, CommandLineConfig .projectName, true )
61+ program = project.importProgram(inputFile)
62+ addProgramToCpg(program, inputFile.getCanonicalPath, cpg)
63+ }
5164 } catch {
5265 case e : Exception =>
5366 e.printStackTrace()
0 commit comments