GP-3883 added source file manager

This commit is contained in:
James 2023-10-13 14:57:59 +00:00
parent 420dd7ce0c
commit 9aeeaa4397
52 changed files with 8432 additions and 306 deletions

View file

@ -462,6 +462,9 @@
<li>Function tags differ.</li>
</ul>
</blockquote>
<p><b>Source Map<a name="ExecuteDiffDialog_DoDifferencesOn_SourceMap"></a></b>
- detect any addresses where the source map information is different.
</p>
</blockquote>
<p>When the <i>Determine Program Differences</i> dialog is initially
displayed, all the Differences check boxes are checked. This indicates
@ -1305,6 +1308,15 @@
Can be: <i>Ignore</i>, <i>Replace</i>, or <i>Merge</i>.<br>
</td>
</tr>
<tr>
<td align="left" nowrap="nowrap" valign="top" width="180">
Source Map<br>
</td>
<td align="left" valign="top" width="100">
Controls whether Source Map differences will be applied.
Can be: <i>Ignore</i> (the default) or <i>Replace</i>.<br>
</td>
</tr>
</tbody>
</table>
</center>

View file

@ -43,35 +43,38 @@ class DiffApplySettingsOptionManager {
private static final int PROPERTIES = 1 << 11;
private static final int FUNCTIONS = 1 << 12;
private static final int FUNCTION_TAGS = 1 << 13;
private static final int SOURCE_MAP = 1 << 14;
private static final String OPTION_PROGRAM_CONTEXT = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Program Context";
private static final String OPTION_BYTES = DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER +
"Bytes";
private static final String OPTION_CODE_UNITS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Code Units";
private static final String OPTION_REFERENCES = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "References";
private static final String OPTION_PLATE_COMMENTS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Plate Comments";
private static final String OPTION_PRE_COMMENTS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Pre Comments";
private static final String OPTION_EOL_COMMENTS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "End Of Line Comments";
private static final String OPTION_REPEATABLE_COMMENTS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Repeatable Comments";
private static final String OPTION_POST_COMMENTS = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Post Comments";
private static final String OPTION_SYMBOLS = DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER +
"Labels";
private static final String OPTION_BOOKMARKS = DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER +
"Bookmarks";
private static final String OPTION_PROPERTIES = DIFF_APPLY_SETTINGS_OPTIONS +
Options.DELIMITER + "Properties";
private static final String OPTION_FUNCTIONS = DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER +
"Functions";
private static final String OPTION_PROGRAM_CONTEXT =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Program Context";
private static final String OPTION_BYTES =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Bytes";
private static final String OPTION_CODE_UNITS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Code Units";
private static final String OPTION_REFERENCES =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "References";
private static final String OPTION_PLATE_COMMENTS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Plate Comments";
private static final String OPTION_PRE_COMMENTS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Pre Comments";
private static final String OPTION_EOL_COMMENTS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "End Of Line Comments";
private static final String OPTION_REPEATABLE_COMMENTS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Repeatable Comments";
private static final String OPTION_POST_COMMENTS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Post Comments";
private static final String OPTION_SYMBOLS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Labels";
private static final String OPTION_BOOKMARKS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Bookmarks";
private static final String OPTION_PROPERTIES =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Properties";
private static final String OPTION_FUNCTIONS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Functions";
private static final String OPTION_FUNCTION_TAGS =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Function Tags";
private static final String OPTION_SOURCE_MAP =
DIFF_APPLY_SETTINGS_OPTIONS + Options.DELIMITER + "Source Map";
// public static final String MERGE = "Merge";
// public static final String MERGE_SYMBOLS_1 = "Merge";
@ -79,6 +82,7 @@ class DiffApplySettingsOptionManager {
public static enum REPLACE_CHOICE {
IGNORE("Ignore"), REPLACE("Replace");
private String description;
REPLACE_CHOICE(String description) {
@ -93,6 +97,7 @@ class DiffApplySettingsOptionManager {
public static enum MERGE_CHOICE {
IGNORE("Ignore"), REPLACE("Replace"), MERGE("Merge");
private String description;
MERGE_CHOICE(String description) {
@ -111,6 +116,7 @@ class DiffApplySettingsOptionManager {
REPLACE("Replace"),
MERGE_DONT_SET_PRIMARY("Merge"),
MERGE_AND_SET_PRIMARY("Merge & Set Primary");
private String description;
SYMBOL_MERGE_CHOICE(String description) {
@ -146,10 +152,7 @@ class DiffApplySettingsOptionManager {
options.setOptionsHelpLocation(help);
// Set the help strings
options.registerOption(
OPTION_PROGRAM_CONTEXT,
REPLACE_CHOICE.REPLACE,
help,
options.registerOption(OPTION_PROGRAM_CONTEXT, REPLACE_CHOICE.REPLACE, help,
getReplaceDescription("program context register value",
"program context register values"));
options.registerOption(OPTION_BYTES, REPLACE_CHOICE.REPLACE, help,
@ -180,6 +183,8 @@ class DiffApplySettingsOptionManager {
getReplaceDescription("function", "functions"));
options.registerOption(OPTION_FUNCTION_TAGS, MERGE_CHOICE.MERGE, help,
getReplaceDescription("function tag", "function tags"));
options.registerOption(OPTION_SOURCE_MAP, REPLACE_CHOICE.IGNORE, help,
getReplaceDescription("source map", "source map"));
getDefaultApplyFilter();
}
@ -218,6 +223,7 @@ class DiffApplySettingsOptionManager {
REPLACE_CHOICE properties = options.getEnum(OPTION_PROPERTIES, REPLACE_CHOICE.REPLACE);
REPLACE_CHOICE functions = options.getEnum(OPTION_FUNCTIONS, REPLACE_CHOICE.REPLACE);
MERGE_CHOICE functionTags = options.getEnum(OPTION_FUNCTION_TAGS, MERGE_CHOICE.MERGE);
REPLACE_CHOICE sourceMap = options.getEnum(OPTION_SOURCE_MAP, REPLACE_CHOICE.IGNORE);
// Convert the options to a merge filter.
ProgramMergeFilter filter = new ProgramMergeFilter();
@ -238,6 +244,7 @@ class DiffApplySettingsOptionManager {
filter.setFilter(ProgramMergeFilter.FUNCTION_TAGS, functionTags.ordinal());
filter.setFilter(ProgramMergeFilter.PRIMARY_SYMBOL,
convertSymbolMergeChoiceToReplaceChoiceForPrimay(symbols).ordinal());
filter.setFilter(ProgramMergeFilter.SOURCE_MAP, sourceMap.ordinal());
return filter;
}
@ -293,6 +300,7 @@ class DiffApplySettingsOptionManager {
saveReplaceOption(options, newDefaultApplyFilter, BOOKMARKS);
saveReplaceOption(options, newDefaultApplyFilter, PROPERTIES);
saveReplaceOption(options, newDefaultApplyFilter, FUNCTIONS);
saveReplaceOption(options, newDefaultApplyFilter, SOURCE_MAP);
saveMergeOption(options, newDefaultApplyFilter, PLATE_COMMENTS);
saveMergeOption(options, newDefaultApplyFilter, PRE_COMMENTS);
@ -311,8 +319,9 @@ class DiffApplySettingsOptionManager {
private void saveCodeUnitReplaceOption(Options options, ProgramMergeFilter defaultApplyFilter,
int setting) {
int filter =
(defaultApplyFilter.getFilter(ProgramMergeFilter.INSTRUCTIONS) >= defaultApplyFilter.getFilter(ProgramMergeFilter.DATA)) ? ProgramMergeFilter.INSTRUCTIONS
: ProgramMergeFilter.DATA;
(defaultApplyFilter.getFilter(ProgramMergeFilter.INSTRUCTIONS) >= defaultApplyFilter
.getFilter(ProgramMergeFilter.DATA)) ? ProgramMergeFilter.INSTRUCTIONS
: ProgramMergeFilter.DATA;
REPLACE_CHOICE defaultSetting = REPLACE_CHOICE.REPLACE;
REPLACE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
REPLACE_CHOICE diffSetting = convertTypeToReplaceEnum(defaultApplyFilter, filter);
@ -332,7 +341,8 @@ class DiffApplySettingsOptionManager {
}
}
private void saveMergeOption(Options options, ProgramMergeFilter defaultApplyFilter, int setting) {
private void saveMergeOption(Options options, ProgramMergeFilter defaultApplyFilter,
int setting) {
MERGE_CHOICE defaultSetting = MERGE_CHOICE.MERGE;
MERGE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
MERGE_CHOICE diffSetting =
@ -507,7 +517,8 @@ class DiffApplySettingsOptionManager {
* @param type the ProgramMergeFilter filter type
* @return the StringEnum
*/
private REPLACE_CHOICE convertTypeToReplaceEnum(ProgramMergeFilter defaultApplyFilter, int type) {
private REPLACE_CHOICE convertTypeToReplaceEnum(ProgramMergeFilter defaultApplyFilter,
int type) {
int filter = defaultApplyFilter.getFilter(type);
return REPLACE_CHOICE.values()[filter];
}

View file

@ -34,6 +34,7 @@ import ghidra.framework.plugintool.ComponentProviderAdapter;
import ghidra.framework.plugintool.Plugin;
import ghidra.program.util.ProgramMergeFilter;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
/**
* The DiffSettingsDialog is used to change the types of differences currently
@ -63,6 +64,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
private Choice propertiesCB;
private Choice functionsCB;
private Choice functionTagsCB;
private Choice sourceMapCB;
private int applyProgramContext;
private int applyBytes;
@ -78,6 +80,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
private int applyProperties;
private int applyFunctions;
private int applyFunctionTags;
private int applySourceMap;
private int replacePrimary;
private ProgramMergeFilter applyFilter;
@ -107,8 +110,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
public void addActions() {
plugin.getTool()
.addLocalAction(this,
new SaveApplySettingsAction(this, plugin.applySettingsMgr));
.addLocalAction(this, new SaveApplySettingsAction(this, plugin.applySettingsMgr));
plugin.getTool().addLocalAction(this, new DiffIgnoreAllAction(this));
plugin.getTool().addLocalAction(this, new DiffReplaceAllAction(this));
plugin.getTool().addLocalAction(this, new DiffMergeAllAction(this));
@ -152,7 +154,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(refsCB);
plateCommentsCB = new Choice("Plate Comments", true);
plateCommentsCB = new Choice("Comments, Plate", true);
plateCommentsCB.addActionListener(e -> {
applyPlateComments = plateCommentsCB.getSelectedIndex();
applyFilter.setFilter(ProgramMergeFilter.PLATE_COMMENTS, applyPlateComments);
@ -160,7 +162,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(plateCommentsCB);
preCommentsCB = new Choice("Pre Comments", true);
preCommentsCB = new Choice("Comments, Pre", true);
preCommentsCB.addActionListener(e -> {
applyPreComments = preCommentsCB.getSelectedIndex();
applyFilter.setFilter(ProgramMergeFilter.PRE_COMMENTS, applyPreComments);
@ -168,7 +170,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(preCommentsCB);
eolCommentsCB = new Choice("Eol Comments", true);
eolCommentsCB = new Choice("Comments, EOL", true);
eolCommentsCB.addActionListener(e -> {
applyEolComments = eolCommentsCB.getSelectedIndex();
applyFilter.setFilter(ProgramMergeFilter.EOL_COMMENTS, applyEolComments);
@ -176,7 +178,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(eolCommentsCB);
repeatableCommentsCB = new Choice("Repeatable Comments", true);
repeatableCommentsCB = new Choice("Comments, Repeatable", true);
repeatableCommentsCB.addActionListener(e -> {
applyRepeatableComments = repeatableCommentsCB.getSelectedIndex();
applyFilter.setFilter(ProgramMergeFilter.REPEATABLE_COMMENTS, applyRepeatableComments);
@ -184,7 +186,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(repeatableCommentsCB);
postCommentsCB = new Choice("Post Comments", true);
postCommentsCB = new Choice("Comments, Post", true);
postCommentsCB.addActionListener(e -> {
applyPostComments = postCommentsCB.getSelectedIndex();
applyFilter.setFilter(ProgramMergeFilter.POST_COMMENTS, applyPostComments);
@ -240,6 +242,25 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
});
choices.add(functionTagsCB);
sourceMapCB = new Choice("Source Map", false);
if (!plugin.getFirstProgram().hasExclusiveAccess()) {
sourceMapCB.setSelectedIndex(ProgramMergeFilter.IGNORE);
}
sourceMapCB.addActionListener(e -> {
applySourceMap = sourceMapCB.getSelectedIndex();
if (!plugin.getFirstProgram().hasExclusiveAccess()) {
if (applySourceMap != ProgramMergeFilter.IGNORE) {
Msg.showWarn(this, null, "Exclusive Access Required",
"Exclusive access required to change source map information");
sourceMapCB.setSelectedIndex(ProgramMergeFilter.IGNORE);
applySourceMap = ProgramMergeFilter.IGNORE;
}
}
applyFilter.setFilter(ProgramMergeFilter.SOURCE_MAP, applySourceMap);
applyFilterChanged();
});
choices.add(sourceMapCB);
int maxLabelWidth = 0;
int maxComboWidth = 0;
for (Choice choice : choices) {
@ -294,6 +315,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
propertiesCB.setSelectedIndex(applyProperties);
functionsCB.setSelectedIndex(applyFunctions);
functionTagsCB.setSelectedIndex(applyFunctionTags);
sourceMapCB.setSelectedIndex(applySourceMap);
}
finally {
adjustingApplyFilter = false;
@ -340,6 +362,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
applyFunctions = applyFilter.getFilter(ProgramMergeFilter.FUNCTIONS);
applyFunctionTags = applyFilter.getFilter(ProgramMergeFilter.FUNCTION_TAGS);
replacePrimary = applyFilter.getFilter(ProgramMergeFilter.PRIMARY_SYMBOL);
applySourceMap = applyFilter.getFilter(ProgramMergeFilter.SOURCE_MAP);
adjustApplyFilter();
}
@ -402,11 +425,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
new GComboBox<>(allowMerge ? DiffApplySettingsOptionManager.MERGE_CHOICE.values()
: DiffApplySettingsOptionManager.REPLACE_CHOICE.values());
applyCB.setName(type + " Diff Apply CB");
String typeName = type;
if (typeName.endsWith(" Comments")) {
typeName = "Comments, " + typeName.substring(0, typeName.length() - 9);
}
label = new GDLabel(" " + typeName + " ");
label = new GDLabel(" " + type + " ");
label.setHorizontalAlignment(SwingConstants.RIGHT);
add(applyCB, BorderLayout.EAST);
add(label, BorderLayout.CENTER);
@ -438,7 +457,7 @@ public class DiffApplySettingsProvider extends ComponentProviderAdapter {
@Override
public int compareTo(Choice o) {
return label.toString().compareTo(o.label.toString());
return type.compareTo(o.type);
}
}

View file

@ -52,6 +52,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
private JCheckBox diffBookmarksCB;
private JCheckBox diffPropertiesCB;
private JCheckBox diffFunctionsCB;
private JCheckBox diffSourceMapCB;
private JButton selectAllButton = new JButton("Select All");
private JButton deselectAllButton = new JButton("Deselect All");
private JCheckBox limitToSelectionCB;
@ -66,6 +67,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
private boolean diffBookmarks;
private boolean diffProperties;
private boolean diffFunctions;
private boolean diffSourceMap;
private ProgramDiffFilter diffFilter;
private JPanel diffPanel;
@ -191,9 +193,8 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
*/
private JPanel createDiffFilterPanel() {
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setToolTipText(
"Check the types of differences between the two " +
"programs that you want detected and highlighted.");
checkBoxPanel.setToolTipText("Check the types of differences between the two " +
"programs that you want detected and highlighted.");
createBytesCheckBox();
createLabelsCheckBox();
@ -204,17 +205,19 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
createBookmarksCheckBox();
createPropertiesCheckBox();
createFunctionsCheckBox();
createSourceMapCheckBox();
checkBoxPanel.setLayout(new GridLayout(3, 3, 5, 0));
checkBoxPanel.add(diffBytesCB);
checkBoxPanel.add(diffLabelsCB);
checkBoxPanel.add(diffCodeUnitsCB);
checkBoxPanel.add(diffReferencesCB);
checkBoxPanel.add(diffProgramContextCB);
checkBoxPanel.add(diffCommentsCB);
checkBoxPanel.setLayout(new GridLayout(2, 5, 5, 0));
checkBoxPanel.add(diffBookmarksCB);
checkBoxPanel.add(diffPropertiesCB);
checkBoxPanel.add(diffBytesCB);
checkBoxPanel.add(diffCodeUnitsCB);
checkBoxPanel.add(diffCommentsCB);
checkBoxPanel.add(diffFunctionsCB);
checkBoxPanel.add(diffLabelsCB);
checkBoxPanel.add(diffProgramContextCB);
checkBoxPanel.add(diffPropertiesCB);
checkBoxPanel.add(diffReferencesCB);
checkBoxPanel.add(diffSourceMapCB);
JPanel buttonPanel = new JPanel();
createSelectAllButton();
@ -254,8 +257,8 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
private void createCodeUnitsCheckBox() {
diffCodeUnitsCB = new GCheckBox("Code Units", diffCodeUnits);
diffCodeUnitsCB.setName("CodeUnitsDiffCB");
diffCodeUnitsCB.setToolTipText(
"Highlight the instruction, data, " + "and equate differences.");
diffCodeUnitsCB
.setToolTipText("Highlight the instruction, data, " + "and equate differences.");
diffCodeUnitsCB.addItemListener(event -> {
diffCodeUnits = (event.getStateChange() == ItemEvent.SELECTED);
diffFilter.setFilter(ProgramDiffFilter.CODE_UNIT_DIFFS, diffCodeUnits);
@ -334,6 +337,17 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
});
}
private void createSourceMapCheckBox() {
diffSourceMapCB = new GCheckBox("Source Map", diffSourceMap);
diffSourceMapCB.setName("SourceMapDiffCB");
diffSourceMapCB.setToolTipText("Highlight Source Map Differences");
diffSourceMapCB.addItemListener(event -> {
diffSourceMap = (event.getStateChange() == ItemEvent.SELECTED);
diffFilter.setFilter(ProgramDiffFilter.SOURCE_MAP_DIFFS, diffSourceMap);
clearStatusText();
});
}
private void createSelectAllButton() {
selectAllButton.addActionListener(e -> setSelectAll(true));
selectAllButton.setMnemonic('S');
@ -354,6 +368,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
diffBookmarksCB.setSelected(selected);
diffPropertiesCB.setSelected(selected);
diffFunctionsCB.setSelected(selected);
diffSourceMapCB.setSelected(selected);
}
private void adjustDiffFilter() {
@ -366,7 +381,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
diffBookmarksCB.setSelected(diffBookmarks);
diffPropertiesCB.setSelected(diffProperties);
diffFunctionsCB.setSelected(diffFunctions);
diffSourceMapCB.setSelected(diffSourceMap);
}
void setPgmContextEnabled(boolean enable) {
@ -402,6 +417,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
diffBookmarks = diffFilter.getFilter(ProgramDiffFilter.BOOKMARK_DIFFS);
diffProperties = diffFilter.getFilter(ProgramDiffFilter.USER_DEFINED_DIFFS);
diffFunctions = diffFilter.getFilter(ProgramDiffFilter.FUNCTION_DIFFS);
diffSourceMap = diffFilter.getFilter(ProgramDiffFilter.SOURCE_MAP_DIFFS);
adjustDiffFilter();
}
@ -469,7 +485,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
*/
boolean hasDiffSelection() {
return (diffBytes || diffLabels || diffCodeUnits || diffProgramContext || diffReferences ||
diffComments || diffBookmarks || diffProperties || diffFunctions);
diffComments || diffBookmarks || diffProperties || diffFunctions || diffSourceMap);
}
/**
@ -478,7 +494,7 @@ public class ExecuteDiffDialog extends ReusableDialogComponentProvider {
boolean isMarkingAllDiffs() {
return (diffBytes && diffLabels && diffCodeUnits &&
((!pgmContextEnabled) || diffProgramContext) && diffReferences && diffComments &&
diffBookmarks && diffProperties && diffFunctions);
diffBookmarks && diffProperties && diffFunctions && diffSourceMap);
}
}