Skip to content

Ghidra is a software reverse engineering (SRE) framework

review fixes

dragonmacher4062681a86cb
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
index fee298ccfa..9ce12258c8 100644
--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
@@ -36,13 +36,11 @@ import ghidra.util.task.TaskMonitor;
import help.screenshot.GhidraScreenShotGenerator;
public class DebuggerBreakpointMarkerPluginScreenShots extends GhidraScreenShotGenerator {
- DebuggerLogicalBreakpointService breakpointService;
- DebuggerBreakpointMarkerPlugin breakpointMarkerPlugin;
- ProgramManager programManager;
+ private DebuggerLogicalBreakpointService breakpointService;
+ private DebuggerBreakpointMarkerPlugin breakpointMarkerPlugin;
+ private ProgramManager programManager;
- CodeViewerProvider listing;
-
- Program program;
+ private CodeViewerProvider listing;
protected static Address addr(Program program, long offset) {
return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);
@@ -94,7 +92,8 @@ public class DebuggerBreakpointMarkerPluginScreenShots extends GhidraScreenShotG
@Test
public void testCaptureDebuggerPlaceBreakpointDialog() throws Throwable {
- listing.goTo(program, new ProgramLocation(program, addr(program, 0x00401c63)));
+ runSwing(
+ () -> listing.goTo(program, new ProgramLocation(program, addr(program, 0x00401c63))));
performAction(breakpointMarkerPlugin.actionSetSoftwareBreakpoint, false);
DebuggerPlaceBreakpointDialog dialog =
waitForDialogComponent(DebuggerPlaceBreakpointDialog.class);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/AbstractCodeBrowserPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/AbstractCodeBrowserPlugin.java
index 5a725d0372..241463af08 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/AbstractCodeBrowserPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/AbstractCodeBrowserPlugin.java
@@ -21,7 +21,6 @@ import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
@@ -61,8 +60,8 @@ import ghidra.util.*;
import resources.ResourceManager;
public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> extends Plugin
- implements CodeViewerService, CodeFormatService, OptionsChangeListener,
- FormatModelListener, DomainObjectListener, CodeBrowserPluginInterface {
+ implements CodeViewerService, CodeFormatService, OptionsChangeListener, FormatModelListener,
+ DomainObjectListener, CodeBrowserPluginInterface {
private static final Color CURSOR_LINE_COLOR = GhidraOptions.DEFAULT_CURSOR_LINE_COLOR;
private static final String CURSOR_COLOR = "Cursor.Cursor Color - Focused";
@@ -668,7 +667,7 @@ public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> ex
/**
* Positions the cursor to the given location
- *
+ *
* @param address the address to goto
* @param fieldName the name of the field to
* @param row the row within the given field
@@ -681,7 +680,7 @@ public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> ex
/**
* Positions the cursor to the given location
- *
+ *
* @param addr the address to goto
* @param fieldName the name of the field to
* @param occurrence specifies the which occurrence for multiple fields of same type
@@ -707,9 +706,7 @@ public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> ex
public boolean goToField(Address a, String fieldName, int occurrence, int row, int col,
boolean scroll) {
- boolean result = SystemUtilities
- .runSwingNow(() -> doGoToField(a, fieldName, occurrence, row, col, scroll));
- return result;
+ return Swing.runNow(() -> doGoToField(a, fieldName, occurrence, row, col, scroll));
}
private boolean doGoToField(Address a, String fieldName, int occurrence, int row, int col,
@@ -798,12 +795,8 @@ public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> ex
@Override
public boolean goTo(ProgramLocation location, boolean centerOnScreen) {
- AtomicBoolean didGoTo = new AtomicBoolean();
- SystemUtilities.runSwingNow(() -> {
- boolean success = connectedProvider.getListingPanel().goTo(location, centerOnScreen);
- didGoTo.set(success);
- });
- return didGoTo.get();
+ return Swing
+ .runNow(() -> connectedProvider.getListingPanel().goTo(location, centerOnScreen));
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java
index 03d4b85c03..018cb50e94 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java
@@ -168,7 +168,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
@Override
public boolean isSnapshot() {
- // we are a snapshot when we are 'disconnected'
+ // we are a snapshot when we are 'disconnected'
return !isConnected();
}
@@ -183,7 +183,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
* TODO: Remove or rename this to something that accommodates redirecting writes, e.g., to a
* debug target process, particularly for assembly, which may involve code unit modification
* after a successful write, reported asynchronously :/ .
- *
+ *
* @return true if this listing represents a read-only view
*/
public boolean isReadOnly() {
@@ -707,7 +707,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
/**
* Extension point to specify titles when dual panels are active
- *
+ *
* @param panelProgram the program assigned to the panel whose title is requested
* @return the title of the panel for the given program
*/
@@ -993,11 +993,29 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
return null;
}
+ /**
+ * Add the {@link AddressSetDisplayListener} to the listing panel
+ *
+ * @param listener the listener to add
+ */
+ public void addDisplayListener(AddressSetDisplayListener listener) {
+ listingPanel.addDisplayListener(listener);
+ }
+
+ /**
+ * Remove the {@link AddressSetDisplayListener} from the listing panel
+ *
+ * @param listener the listener to remove
+ */
+ public void removeDisplayListener(AddressSetDisplayListener listener) {
+ listingPanel.removeDisplayListener(listener);
+ }
+
//==================================================================================================
// Inner Classes
//==================================================================================================
- class ToggleHeaderAction extends ToggleDockingAction {
+ private class ToggleHeaderAction extends ToggleDockingAction {
ToggleHeaderAction() {
super("Toggle Header", plugin.getName());
setEnabled(true);
@@ -1074,22 +1092,4 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
return list.toArray(new Highlight[list.size()]);
}
}
-
- /**
- * Add the {@link AddressSetDisplayListener} to the listing panel
- *
- * @param listener the listener to add
- */
- public void addDisplayListener(AddressSetDisplayListener listener) {
- listingPanel.addDisplayListener(listener);
- }
-
- /**
- * Remove the {@link AddressSetDisplayListener} from the listing panel
- *
- * @param listener the listener to remove
- */
- public void removeDisplayListener(AddressSetDisplayListener listener) {
- listingPanel.removeDisplayListener(listener);
- }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ProgramBigListingModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ProgramBigListingModel.java
index 4f2ffbc224..46e7d8be4d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ProgramBigListingModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ProgramBigListingModel.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/assembler/AssemblerPluginTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/assembler/AssemblerPluginTest.java
index 8d485e7561..d4ec382869 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/assembler/AssemblerPluginTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/assembler/AssemblerPluginTest.java
@@ -97,9 +97,7 @@ public class AssemblerPluginTest extends AbstractGhidraHeadedIntegrationTest {
@After
public void tearDownAssemblerPluginTest() {
- if (program != null) {
- program.release(this);
- }
+ env.dispose();
}
protected void assertDualFields() {
@@ -117,11 +115,15 @@ public class AssemblerPluginTest extends AbstractGhidraHeadedIntegrationTest {
});
}
+ private void goTo(Address address) {
+ runSwing(() -> codeViewer.goTo(program, new ProgramLocation(program, address)));
+ waitForSwing();
+ }
+
@Test
public void testActionPatchInstructionNoExisting() throws Exception {
Address address = space.getAddress(0x00400000);
- codeViewer.goTo(program, new ProgramLocation(program, address));
- waitForSwing();
+ goTo(address);
performAction(assemblerPlugin.patchInstructionAction, codeViewer, true);
assertDualFields();
@@ -149,8 +151,7 @@ public class AssemblerPluginTest extends AbstractGhidraHeadedIntegrationTest {
trans.commit();
}
- codeViewer.goTo(program, new ProgramLocation(program, address));
- waitForSwing();
+ goTo(address);
performAction(assemblerPlugin.patchInstructionAction, codeViewer, true);
assertDualFields();
@@ -173,8 +174,7 @@ public class AssemblerPluginTest extends AbstractGhidraHeadedIntegrationTest {
// TODO: Test disabled on read-only listings
protected Data doPatchAt(Address address, String expText, String newText) {
- codeViewer.goTo(program, new ProgramLocation(program, address));
- waitForSwing();
+ goTo(address);
performAction(assemblerPlugin.patchDataAction, codeViewer, true);
assertTrue(dataInput.isVisible());
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/LRUMap.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/LRUMap.java
index 77b812fb71..4461529e9a 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/LRUMap.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/LRUMap.java
@@ -21,23 +21,25 @@ import ghidra.util.SystemUtilities;
/**
* A LRU (Least Recently Used) map that maintains <i>access-order</i> (newest to oldest)
- * iteration over the elements.
- * This map is limited to the given size.
+ * iteration over the elements.
+ * This map is limited to the given size.
* As new items are added, the older items will be removed from this map.
* <p>
- * If you need to be notified of removals, then you can override
+ * If you need to be notified of removals, then you can override
* {@link #eldestEntryRemoved(java.util.Map.Entry)}.
* <p>
- * If you don't want the eldest removed, override
+ * If you don't want the eldest removed, override
* {@link #removeEldestEntry(java.util.Map.Entry)} and return false;
* <p>
- * If you would like to have the iteration order of your LRU structure be based upon access,
+ * If you would like to have the iteration order of your LRU structure be based upon access,
* but want it to iterate from least recently used to most recently used, then you should see
* {@link FixedSizeHashMap}.
- *
- * @param <K> the key type
+ * <p>
+ * Note: this class is not thread safe.
+ *
+ * @param <K> the key type
* @param <V> the value type
- *
+ *
* @see LinkedHashMap
* @see FixedSizeHashMap
*/
@@ -76,7 +78,7 @@ public class LRUMap<K, V> implements Map<K, V> {
@Override
public boolean containsValue(Object value) {
for (V mapValue : values()) {
- if (SystemUtilities.isEqual(value, mapValue)) {
+ if (Objects.equals(value, mapValue)) {
return true;
}
}
diff --git a/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/LRUMapTest.java b/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/LRUMapTest.java
index 14db1a35d2..b5221a118e 100644
--- a/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/LRUMapTest.java
+++ b/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/LRUMapTest.java
@@ -29,10 +29,6 @@ public class LRUMapTest extends AbstractGenericTest {
private LRUMap<String, String> map;
- public LRUMapTest() {
- super();
- }
-
@Before
public void setUp() throws Exception {
int size = 3;
@@ -45,7 +41,7 @@ public class LRUMapTest extends AbstractGenericTest {
}
@Test
- public void testMultiplePointsDoesntIncreaseSize() {
+ public void testMultiplePutsDoesntIncreaseSize() {
map = new LRUMap<String, String>(3);
map.put("key1", "value1");