Ghidra is a software reverse engineering (SRE) framework
GT-2845 - Checksums - fix for potential concurrent mod exception
dragonmacher61b1f7b5ed6f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ChecksumTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ChecksumTableModel.javaindex b4e7079fc7..0ebbe18daa 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ChecksumTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ChecksumTableModel.java@@ -25,8 +25,7 @@ import ghidra.framework.plugintool.ServiceProvider;/*** This class is used to model the table in the ComputeChecksumsProvider.*/-public class ChecksumTableModel- extends GDynamicColumnTableModel<ChecksumAlgorithm, List<ChecksumAlgorithm>> {+public class ChecksumTableModel extends GDynamicColumnTableModel<ChecksumAlgorithm, Object> {final public static int NAME_COL = 0;final public static int VALUE_COL = 1;@@ -49,10 +48,6 @@ public class ChecksumTableModelreturn "Checksum";}- /**- * Returns a list of all of the checksums in this table model.- * @return a list of all of the checksums in this table model.- */@Overridepublic List<ChecksumAlgorithm> getModelData() {return checksumList;@@ -62,7 +57,7 @@ public class ChecksumTableModel* Method used to update the display options for the applicable checksums.* @param asHex True if the applicable checksums should be displayed in hex, otherwise false.*/- public void formatOptions(boolean asHex) {+ void setFormatOptions(boolean asHex) {this.isHex = asHex;}@@ -71,7 +66,7 @@ public class ChecksumTableModel* @param checksumName the name of the checksum to get.* @return the checksum with the given name, or null if there isn't one.*/- public ChecksumAlgorithm getChecksumFor(String checksumName) {+ ChecksumAlgorithm getChecksumFor(String checksumName) {for (ChecksumAlgorithm res : checksumList) {if (res.getName().equals(checksumName)) {return res;@@ -90,13 +85,9 @@ public class ChecksumTableModelreturn descriptor;}- /**- * Returns a list of the checksums.- * @return a list of the checksums.- */@Override- public List<ChecksumAlgorithm> getDataSource() {- return checksumList;+ public Object getDataSource() {+ return null;}private class ChecksumNameColumndiff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumTask.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumTask.javaindex d659ad0337..2b03284d32 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumTask.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumTask.java@@ -59,7 +59,7 @@ public class ComputeChecksumTask extends Task {@Overridepublic void run(TaskMonitor monitor) {- AddressSet addrs = new AddressSet(set != null ? set : memory); //null ok here+ AddressSet addrs = new AddressSet(set != null ? set : memory);for (MemoryBlock block : memory.getBlocks()) {if (!block.isInitialized()) {addrs.deleteRange(block.getStart(), block.getEnd());diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsPlugin.javaindex 978a0a2a43..e221430f0f 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsPlugin.java@@ -107,33 +107,22 @@ public class ComputeChecksumsPlugin extends ProgramPlugin {*/@Overrideprotected void selectionChanged(ProgramSelection selection) {- super.selectionChanged(selection);- if (provider != null) {- provider.setSelection(hasSelection());- }- }-- /**- * Get's the provider associated with this plugin.- * @return the provider associated with this plugin.- */- public ComputeChecksumsProvider getProvider() {- return provider;+ provider.setSelection(hasSelection());}/**- * Returns the current program selection.- * @return the current program selection.+ * Returns the current program selection+ * @return the current program selection*/- public ProgramSelection getSelection() {+ ProgramSelection getSelection() {return currentSelection;}/**- * Returns true if the current program has a selection.- * @return true if the current program has a selection.+ * Returns true if the current program has a selection+ * @return true if the current program has a selection*/- public boolean hasSelection() {+ boolean hasSelection() {ProgramSelection selection = getSelection();return selection != null && !selection.isEmpty();}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsProvider.javaindex d5f33e75d5..09efe3ecdc 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/ComputeChecksumsProvider.java@@ -17,8 +17,7 @@ package ghidra.app.plugin.core.checksums;import java.awt.BorderLayout;import java.awt.Color;-import java.util.ArrayList;-import java.util.List;+import java.util.*;import javax.swing.*;@@ -64,15 +63,16 @@ public class ComputeChecksumsProvider extends ComponentProviderAdapter {super(plugin.getTool(), "Checksum Generator", plugin.getName(), ProgramContextAction.class);setHelpLocation(new HelpLocation("ComputeChecksumsPlugin", "Generate_Checksum_Help"));- ClassSearcher.getInstances(ChecksumAlgorithm.class).forEach(- alg -> addChecksumAlgorithm(alg));+ Set<ChecksumAlgorithm> algorithms = ClassSearcher.getInstances(ChecksumAlgorithm.class);+ checksums.addAll(algorithms);this.plugin = plugin;this.mainPanel = createWorkPanel();- setSelection(false);addToTool();createActions();++ setSelection(false);}@Override@@ -135,9 +135,7 @@ public class ComputeChecksumsProvider extends ComponentProviderAdapter {*/void setSelection(boolean state) {setErrorMessage("");- if (selectionAction == null) {- return;- }+selectionAction.setSelected(state);selectionAction.setEnabled(state);if (state) {@@ -184,39 +182,17 @@ public class ComputeChecksumsProvider extends ComponentProviderAdapter {return carryAction.isSelected();}- /**- * Returns the model that's being used by the table.- * @return the model that's being used by the table.- */- public ChecksumTableModel getModel() {+ ChecksumTableModel getModel() {return model;}/**- * Returns the checksum algorithm table that's being used in the provider.- * @return the checksums algorithm table that's being used in the provider.- */- public GhidraTable getTable() {- return table;- }-- /**- * Returns a list of the checksums currently being used by the table model.- * @return a list of the checksums currently being used by the table model.+ * Returns a list of the checksums currently being used by the table model+ * @return a list of the checksums currently being used by the table model*/- public List<ChecksumAlgorithm> getChecksums() {- return checksums;- }-- /**- * Adds a checksum algorithm to the table model.- * @param checksumAlgorithm the algorithm to add to the table model.- */- public void addChecksumAlgorithm(ChecksumAlgorithm checksumAlgorithm) {- checksums.add(checksumAlgorithm);- if (model != null) {- model.fireTableDataChanged();- }+ List<ChecksumAlgorithm> getChecksums() {+ // send out a copy so that nobody can modify the list while it is being used+ return new ArrayList<>(checksums);}/**@@ -228,19 +204,17 @@ public class ComputeChecksumsProvider extends ComponentProviderAdapter {table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);}- void updateFields() {+ private void updateFields() {if (!hasResults) {return;}- model.formatOptions(showHexAction.isSelected());+ model.setFormatOptions(showHexAction.isSelected());model.fireTableDataChanged();}private void clearFields() {- if (checksums != null) {- checksums.stream().forEach(checkResult -> checkResult.reset());- }+ checksums.forEach(checkResult -> checkResult.reset());model.fireTableDataChanged();}