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

program
This commit is contained in:
emteere 2023-07-05 23:53:10 +00:00
parent 76c52ba9a4
commit 081f1a6338
2 changed files with 25 additions and 15 deletions

View file

@ -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);
}

View file

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