Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3612 Always use program architecture when parsing header files to program

emteere081f1a6338c3
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/CParserPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/CParserPlugin.java
index bf55b2c8a1..e485c51c7a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/CParserPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/CParserPlugin.java
@@ -41,6 +41,7 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.database.data.ProgramDataTypeManager;
import ghidra.program.model.data.*;
+import ghidra.program.model.lang.LanguageCompilerSpecPair;
import ghidra.program.model.listing.Program;
import ghidra.util.*;
import ghidra.util.exception.CancelledException;
@@ -300,16 +301,25 @@ public class CParserPlugin extends ProgramPlugin {
/*
* Parse into the current programs data type manager
+ *
+ * Always uses the program's processor architecture
*/
- protected void parse(String[] filenames, String[] includePaths, String options,
- String languageIDString, String compilerIDString) {
+ protected void parse(String[] filenames, String[] includePaths, String options) {
if (currentProgram == null) {
Msg.showInfo(getClass(), parseDialog.getComponent(), "No Open Program",
"A program must be open to \"Parse to Program\"");
return;
}
+ /*
+ * always use the processor/compiler for the program when parsing to program
+ */
+ LanguageCompilerSpecPair languageCompilerSpecPair = currentProgram.getLanguageCompilerSpecPair();
+ String procID = languageCompilerSpecPair.languageID.getIdAsString();
+ String compilerID = languageCompilerSpecPair.compilerSpecID.getIdAsString();
+
int result = OptionDialog.showOptionDialog(parseDialog.getComponent(), "Confirm",
- "Parse C source to \"" + currentProgram.getDomainFile().getName() + "\"?", "Continue");
+ "Parse C source to \"" + currentProgram.getDomainFile().getName() + "\"?" + "\n\n" +
+ "Using program architecture: " + procID + " / " + compilerID, "Continue");
if (result == OptionDialog.CANCEL_OPTION) {
return;
@@ -320,8 +330,8 @@ public class CParserPlugin extends ProgramPlugin {
.setFileNames(filenames)
.setIncludePaths(includePaths)
.setOptions(options)
- .setLanguageID(languageIDString)
- .setCompilerID(compilerIDString);
+ .setLanguageID(procID)
+ .setCompilerID(compilerID);
tool.execute(parseTask);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/ParseDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/ParseDialog.java
index 298463fff2..043c9384b0 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/ParseDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/cparser/ParseDialog.java
@@ -804,22 +804,22 @@ class ParseDialog extends ReusableDialogComponentProvider {
paths = expandPaths(paths);
pathPanel.setPaths(paths);
- if (languageIDString == null || compilerIDString == null) {
- Msg.showWarn(getClass(), rootPanel, "Program Architecture not Specified",
- "A Program Architecture must be specified in order to parse to a file.");
- return;
- }
-
- if (parseToFile) {
+ if (parseToFile) {
+ if (languageIDString == null || compilerIDString == null) {
+ Msg.showWarn(getClass(), rootPanel, "Program Architecture not Specified",
+ "A Program Architecture must be specified in order to parse to a file.");
+ return;
+ }
+
File file = getSaveFile();
if (file != null) {
plugin.parse(paths, includePaths, options, languageIDString, compilerIDString,
file.getAbsolutePath());
}
+ return;
}
- else {
- plugin.parse(paths, includePaths, options, languageIDString, compilerIDString);
- }
+
+ plugin.parse(paths, includePaths, options);
}
private String[] expandPaths(String[] paths) {