GT-0 fixed miscellaneous tests failing

This commit is contained in:
ghidravore 2019-12-03 16:42:49 -05:00
parent 0109c9e8d8
commit 20f5f53778
6 changed files with 140 additions and 146 deletions

View file

@ -173,17 +173,14 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
} }
private void updateChangedState() { private void updateChangedState() {
boolean hasChanges = !undoStack.isEmpty(); boolean hasChanges = hasChanges();
if (saveAction != null && !isReadOnly(scriptSourceFile)) {
saveAction.setEnabled(hasChanges);
}
if (hasChanges) { if (hasChanges) {
setTitle("*" + title); setTitle("*" + title);
} }
else { else {
setTitle(title); setTitle(title);
} }
contextChanged();
} }
private void clearChanges() { private void clearChanges() {
@ -268,7 +265,15 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
@Override @Override
public boolean isEnabledForContext(ActionContext context) { public boolean isEnabledForContext(ActionContext context) {
Object contextObject = context.getContextObject(); Object contextObject = context.getContextObject();
return contextObject == GhidraScriptEditorComponentProvider.this; if (contextObject != GhidraScriptEditorComponentProvider.this) {
return false;
}
if (isReadOnly(scriptSourceFile)) {
return false;
}
return hasChanges();
} }
}; };
saveAction.setDescription("Save"); saveAction.setDescription("Save");
@ -276,7 +281,7 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
new ToolBarData(ResourceManager.loadImage("images/disk.png"), "Save")); new ToolBarData(ResourceManager.loadImage("images/disk.png"), "Save"));
saveAction.setKeyBindingData(new KeyBindingData( saveAction.setKeyBindingData(new KeyBindingData(
KeyStroke.getKeyStroke(KeyEvent.VK_S, DockingUtils.CONTROL_KEY_MODIFIER_MASK))); KeyStroke.getKeyStroke(KeyEvent.VK_S, DockingUtils.CONTROL_KEY_MODIFIER_MASK)));
saveAction.setEnabled(false);
plugin.getTool().addLocalAction(this, saveAction); plugin.getTool().addLocalAction(this, saveAction);
DockingAction refreshAction = new DockingAction("Refresh Script", plugin.getName()) { DockingAction refreshAction = new DockingAction("Refresh Script", plugin.getName()) {
@ -607,8 +612,6 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
writer.print(str); writer.print(str);
writer.close(); writer.close();
saveAction.setEnabled(false);
provider.switchEditor(scriptSourceFile, saveAsFile); provider.switchEditor(scriptSourceFile, saveAsFile);
scriptSourceFile = saveAsFile; scriptSourceFile = saveAsFile;
@ -664,7 +667,7 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
//================================================================================================== //==================================================================================================
/** /**
* Special JTextArea that knows how to properly handle it's key events. * Special JTextArea that knows how to properly handle it's key events.
* @see {@link #processKeyBinding(KeyStroke, KeyEvent, int, boolean)} * See {@link #processKeyBinding(KeyStroke, KeyEvent, int, boolean)}
*/ */
private class KeyMasterTextArea extends JTextArea { private class KeyMasterTextArea extends JTextArea {
@ -713,7 +716,7 @@ public class GhidraScriptEditorComponentProvider extends ComponentProvider {
return true; return true;
} }
return SwingUtilities.notifyAction(action, ks, e, this, e.getModifiers()); return SwingUtilities.notifyAction(action, ks, e, this, e.getModifiersEx());
} }
} }
return false; return false;

View file

@ -15,7 +15,7 @@
*/ */
package ghidra.app.merge.listing; package ghidra.app.merge.listing;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import java.util.List; import java.util.List;
@ -211,7 +211,8 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
Address addr = addr(program, address); Address addr = addr(program, address);
Equate oldEquate = equateTab.getEquate(addr, opIndex, value); Equate oldEquate = equateTab.getEquate(addr, opIndex, value);
if (oldEquate.getName().equals(newName)) { if (oldEquate.getName().equals(newName)) {
Assert.fail("Equate '" + oldEquate.getName() + "' already exists with value=" + value + "."); Assert.fail(
"Equate '" + oldEquate.getName() + "' already exists with value=" + value + ".");
} }
oldEquate.removeReference(addr, opIndex); oldEquate.removeReference(addr, opIndex);
try { try {
@ -220,8 +221,8 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
newEquate = equateTab.createEquate(newName, value); newEquate = equateTab.createEquate(newName, value);
} }
if (newEquate.getValue() != value) { if (newEquate.getValue() != value) {
Assert.fail("Can't create equate '" + newEquate.getName() + "' with value=" + value + Assert.fail("Can't create equate '" + newEquate.getName() + "' with value=" +
". It already exists with value=" + newEquate.getValue() + "."); value + ". It already exists with value=" + newEquate.getValue() + ".");
} }
newEquate.addReference(addr, opIndex); newEquate.addReference(addr, opIndex);
} }
@ -344,53 +345,56 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
@Test @Test
public void testAddNameDiffOnWordDataUpperBit0PickMy() throws Exception { public void testAddNameDiffOnWordDataUpperBit0PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new WordDataType(), new byte[] { (byte) 0x5f, runTestAddNameDiffPickIndicated("0x1002d24", new WordDataType(),
(byte) 0x5f }, 0x5f5f, true); new byte[] { (byte) 0x5f, (byte) 0x5f }, 0x5f5f, true);
} }
@Test @Test
public void testAddNameDiffOnWordDataUpperBit1PickMy() throws Exception { public void testAddNameDiffOnWordDataUpperBit1PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new WordDataType(), new byte[] { (byte) 0xad, runTestAddNameDiffPickIndicated("0x1002d24", new WordDataType(),
(byte) 0xad }, 0xadad, true); new byte[] { (byte) 0xad, (byte) 0xad }, 0xadad, true);
} }
@Test @Test
public void testAddNameDiffOnSignedWordDataUpperBit0PickMy() throws Exception { public void testAddNameDiffOnSignedWordDataUpperBit0PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(),
(byte) 0x5f, (byte) 0x5f }, 0x5f5fL, true); new byte[] { (byte) 0x5f, (byte) 0x5f }, 0x5f5fL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedWordDataUpperBit1PickMy() throws Exception { public void testAddNameDiffOnSignedWordDataUpperBit1PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(),
(byte) 0xad, (byte) 0xad }, 0xffffffffffffadadL, true); new byte[] { (byte) 0xad, (byte) 0xad }, 0xffffffffffffadadL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedQWordDataUpperBit0PickMy() throws Exception { public void testAddNameDiffOnSignedQWordDataUpperBit0PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedQWordDataType(), new byte[] { runTestAddNameDiffPickIndicated(
(byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, "0x1002d24", new SignedQWordDataType(), new byte[] { (byte) 0x5f, (byte) 0x5f,
(byte) 0x5f, (byte) 0x5f }, 0x5f5f5f5f5f5f5f5fL, true); (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f },
0x5f5f5f5f5f5f5f5fL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedQWordDataUpperBit1PickMy() throws Exception { public void testAddNameDiffOnSignedQWordDataUpperBit1PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedQWordDataType(), new byte[] { runTestAddNameDiffPickIndicated(
(byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, "0x1002d24", new SignedQWordDataType(), new byte[] { (byte) 0xad, (byte) 0xad,
(byte) 0xad, (byte) 0xad }, 0xadadadadadadadadL, true); (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad },
0xadadadadadadadadL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedInt5DataUpperBit0PickMy() throws Exception { public void testAddNameDiffOnSignedInt5DataUpperBit0PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new Integer5DataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new Integer5DataType(),
(byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f }, 0x5f5f5f5f5fL, true); new byte[] { (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f },
0x5f5f5f5f5fL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedInt5DataUpperBit1PickMy() throws Exception { public void testAddNameDiffOnSignedInt5DataUpperBit1PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new Integer5DataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new Integer5DataType(),
(byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad }, 0xffffffadadadadadL, new byte[] { (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad },
true); 0xffffffadadadadadL, true);
} }
@Test @Test
@ -409,43 +413,48 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
@Test @Test
public void testAddNameDiffOnSignedInt7DataUpperBit0PickMy() throws Exception { public void testAddNameDiffOnSignedInt7DataUpperBit0PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new Integer7DataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new Integer7DataType(),
(byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, new byte[] { (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f,
(byte) 0x5f }, 0x5f5f5f5f5f5f5fL, true); (byte) 0x5f, (byte) 0x5f },
0x5f5f5f5f5f5f5fL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedInt7DataUpperBit1PickMy() throws Exception { public void testAddNameDiffOnSignedInt7DataUpperBit1PickMy() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new Integer7DataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new Integer7DataType(),
(byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, new byte[] { (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad,
(byte) 0xad }, 0xffadadadadadadadL, true); (byte) 0xad, (byte) 0xad },
0xffadadadadadadadL, true);
} }
@Test @Test
public void testAddNameDiffOnSignedWordDataUpperBit0PickLatest() throws Exception { public void testAddNameDiffOnSignedWordDataUpperBit0PickLatest() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(), new byte[] { runTestAddNameDiffPickIndicated("0x1002d24", new SignedWordDataType(),
(byte) 0x5f, (byte) 0x5f }, 0x5f5fL, false); new byte[] { (byte) 0x5f, (byte) 0x5f }, 0x5f5fL, false);
} }
@Test @Test
public void testAddNameDiffOnSignedQWordDataUpperBit0PickLatest() throws Exception { public void testAddNameDiffOnSignedQWordDataUpperBit0PickLatest() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedQWordDataType(), new byte[] { runTestAddNameDiffPickIndicated(
(byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, "0x1002d24", new SignedQWordDataType(), new byte[] { (byte) 0x5f, (byte) 0x5f,
(byte) 0x5f, (byte) 0x5f }, 0x5f5f5f5f5f5f5f5fL, false); (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f, (byte) 0x5f },
0x5f5f5f5f5f5f5f5fL, false);
} }
@Test @Test
public void testAddNameDiffOnSignedQWordDataUpperBit1PickLatest() throws Exception { public void testAddNameDiffOnSignedQWordDataUpperBit1PickLatest() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new SignedQWordDataType(), new byte[] { runTestAddNameDiffPickIndicated(
(byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, "0x1002d24", new SignedQWordDataType(), new byte[] { (byte) 0xad, (byte) 0xad,
(byte) 0xad, (byte) 0xad }, 0xadadadadadadadadL, false); (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad },
0xadadadadadadadadL, false);
} }
@Test @Test
public void testAddNameDiffOnSignedInt5DataUpperBit1PickLatest() throws Exception { public void testAddNameDiffOnSignedInt5DataUpperBit1PickLatest() throws Exception {
runTestAddNameDiffPickIndicated("0x1002d24", new Integer5DataType(), new byte[] { runTestAddNameDiffPickIndicated(
(byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, "0x1002d24", new Integer5DataType(), new byte[] { (byte) 0xad, (byte) 0xad, (byte) 0xad,
(byte) 0xad, (byte) 0xad }, 0xffffffadadadadadL, false); (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad, (byte) 0xad },
0xffffffadadadadadL, false);
} }
@Test @Test
@ -476,10 +485,9 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
try { try {
Listing listing = program.getListing(); Listing listing = program.getListing();
Address startAddr = addr(program, "0x1002d20"); Address startAddr = addr(program, "0x1002d20");
program.getMemory().setBytes( program.getMemory()
startAddr, .setBytes(startAddr, new byte[] { (byte) 0x8d, (byte) 0x04, (byte) 0x8d,
new byte[] { (byte) 0x8d, (byte) 0x04, (byte) 0x8d, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0 }); //LEA EAX,[0x0 + ECX*0x4]
(byte) 0x0, (byte) 0x0 }); //LEA EAX,[0x0 + ECX*0x4]
createInstruction(program, startAddr); createInstruction(program, startAddr);
Instruction instruction = listing.getInstructionAt(startAddr); Instruction instruction = listing.getInstructionAt(startAddr);
Assert.assertTrue(instruction != null); Assert.assertTrue(instruction != null);
@ -571,19 +579,19 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
setupAddNameDiffOnSubOperand(); setupAddNameDiffOnSubOperand();
executeMerge(ASK_USER); executeMerge(ASK_USER);
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x4 Order seems to have been switched
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x0 chooseEquate("0x1002d20", 1, KEEP_MY); // 0x0
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x4
waitForMergeCompletion(); waitForMergeCompletion();
EquateTable equateTab = resultProgram.getEquateTable(); EquateTable equateTab = resultProgram.getEquateTable();
List<Equate> equates = equateTab.getEquates(addr("0x1002d20"), 1); List<Equate> equates = equateTab.getEquates(addr("0x1002d20"), 1);
assertEquals(2, equates.size()); assertEquals(2, equates.size());
Equate eq = equates.get(0); Equate eq = equates.get(0);
assertEquals("ZERO", eq.getName());
assertEquals(0L, eq.getValue());
eq = equates.get(1);
assertEquals("QUAD", eq.getName()); assertEquals("QUAD", eq.getName());
assertEquals(4L, eq.getValue()); assertEquals(4L, eq.getValue());
eq = equates.get(1);
assertEquals("ZERO", eq.getName());
assertEquals(0L, eq.getValue());
} }
@Test @Test
@ -595,33 +603,8 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
setupAddNameDiffOnSubOperand(); setupAddNameDiffOnSubOperand();
executeMerge(ASK_USER); executeMerge(ASK_USER);
chooseEquate("0x1002d20", 1, KEEP_LATEST); // 0x0
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x4
waitForMergeCompletion();
EquateTable equateTab = resultProgram.getEquateTable();
List<Equate> equates = equateTab.getEquates(addr("0x1002d20"), 1);
assertEquals(2, equates.size());
Equate eq;
eq = equates.get(0);
assertEquals("NADA", eq.getName());
assertEquals(0L, eq.getValue());
eq = equates.get(1);
assertEquals("QUAD", eq.getName());
assertEquals(4L, eq.getValue());
}
@Test
public void testAddNameDiffOnSubOperandPickMyLatest() throws Exception {
// 0x1002d20 LEA EAX,[0x0 + ECX*0x4]
//
// LATEST 0x0=NADA 0x4=FOUR
// MY 0x0=ZERO 0x4=QUAD
setupAddNameDiffOnSubOperand();
executeMerge(ASK_USER);
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x0
chooseEquate("0x1002d20", 1, KEEP_LATEST); // 0x4 chooseEquate("0x1002d20", 1, KEEP_LATEST); // 0x4
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x0
waitForMergeCompletion(); waitForMergeCompletion();
EquateTable equateTab = resultProgram.getEquateTable(); EquateTable equateTab = resultProgram.getEquateTable();
@ -636,6 +619,31 @@ public class EquateMergeManager1Test extends AbstractListingMergeManagerTest {
assertEquals(0L, eq.getValue()); assertEquals(0L, eq.getValue());
} }
@Test
public void testAddNameDiffOnSubOperandPickMyLatest() throws Exception {
// 0x1002d20 LEA EAX,[0x0 + ECX*0x4]
//
// LATEST 0x0=NADA 0x4=FOUR
// MY 0x0=ZERO 0x4=QUAD
setupAddNameDiffOnSubOperand();
executeMerge(ASK_USER);
chooseEquate("0x1002d20", 1, KEEP_MY); // 0x4
chooseEquate("0x1002d20", 1, KEEP_LATEST); // 0x0
waitForMergeCompletion();
EquateTable equateTab = resultProgram.getEquateTable();
List<Equate> equates = equateTab.getEquates(addr("0x1002d20"), 1);
assertEquals(2, equates.size());
Equate eq;
eq = equates.get(0);
assertEquals("NADA", eq.getName());
assertEquals(0L, eq.getValue());
eq = equates.get(1);
assertEquals("QUAD", eq.getName());
assertEquals(4L, eq.getValue());
}
@Test @Test
public void testAddSameNameDiffValue() throws Exception { public void testAddSameNameDiffValue() throws Exception {
mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() { mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {

View file

@ -421,7 +421,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
// more incoming calls. // more incoming calls.
// //
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
GTreeNode rootNode = getRootNode(incomingTree); GTreeNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -430,7 +430,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeNode child0 = children.get(0); GTreeNode child0 = children.get(0);
incomingTree.expandPath(child0); incomingTree.expandPath(child0);
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
List<GTreeNode> grandChildren = child0.getChildren(); List<GTreeNode> grandChildren = child0.getChildren();
assertTrue("Incoming tree child does not have callers as expected for child: " + child0, assertTrue("Incoming tree child does not have callers as expected for child: " + child0,
@ -441,7 +441,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
public void testOutgoingCalls() { public void testOutgoingCalls() {
setProviderFunction("0x5000"); setProviderFunction("0x5000");
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
GTreeNode rootNode = getRootNode(outgoingTree); GTreeNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -450,7 +450,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeNode child1 = children.get(1); GTreeNode child1 = children.get(1);
outgoingTree.expandPath(child1); outgoingTree.expandPath(child1);
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
List<GTreeNode> grandChildren = child1.getChildren(); List<GTreeNode> grandChildren = child1.getChildren();
assertTrue("Outgoing tree child does not have callers as expected for child: " + child1, assertTrue("Outgoing tree child does not have callers as expected for child: " + child1,
@ -461,7 +461,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
public void testGoToFromNode() { public void testGoToFromNode() {
setProviderFunction("0x5000"); setProviderFunction("0x5000");
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
GTreeNode rootNode = getRootNode(outgoingTree); GTreeNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -472,7 +472,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeNode child1 = children.get(1);// skip the first child--it is an external function GTreeNode child1 = children.get(1);// skip the first child--it is an external function
outgoingTree.setSelectedNode(child1); outgoingTree.setSelectedNode(child1);
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
ActionContext actionContext = new ActionContext(provider, outgoingTree); ActionContext actionContext = new ActionContext(provider, outgoingTree);
DockingActionIf goToAction = getAction("Go To Destination"); DockingActionIf goToAction = getAction("Go To Destination");
@ -502,7 +502,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
ProgramSelection currentSelection = codeBrowserPlugin.getCurrentSelection(); ProgramSelection currentSelection = codeBrowserPlugin.getCurrentSelection();
assertTrue(currentSelection.isEmpty()); assertTrue(currentSelection.isEmpty());
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
GTreeNode rootNode = getRootNode(outgoingTree); GTreeNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -587,7 +587,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
performAction(filterDuplicatesAction, true); performAction(filterDuplicatesAction, true);
} }
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
GTreeNode rootNode = getRootNode(outgoingTree); GTreeNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -598,6 +598,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
// no duplicates // no duplicates
boolean shouldHaveDuplicates = false; boolean shouldHaveDuplicates = false;
Map<String, Integer> nameCountMap = createNameCountMap(rootNode); Map<String, Integer> nameCountMap = createNameCountMap(rootNode);
System.out.println("nameCountMap: before: = " + nameCountMap);
assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates); assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates);
performAction(filterDuplicatesAction, true);// deselect performAction(filterDuplicatesAction, true);// deselect
@ -607,6 +608,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
rootNode = getRootNode(outgoingTree); rootNode = getRootNode(outgoingTree);
nameCountMap = createNameCountMap(rootNode); nameCountMap = createNameCountMap(rootNode);
shouldHaveDuplicates = true; shouldHaveDuplicates = true;
System.out.println("nameCountMap: after: = " + nameCountMap);
assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates); assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates);
} }
@ -627,7 +629,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
performAction(navigateAction, true); performAction(navigateAction, true);
} }
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
GTreeNode rootNode = getRootNode(outgoingTree); GTreeNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -697,7 +699,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
setProviderFunction(addrString); setProviderFunction(addrString);
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
GTreeNode rootNode = getRootNode(incomingTree); GTreeNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue("Incoming tree does not have callers as expected for function: " + addrString, assertTrue("Incoming tree does not have callers as expected for function: " + addrString,
@ -712,7 +714,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
// //
setProviderFunction("0x5000"); setProviderFunction("0x5000");
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
GTreeNode rootNode = getRootNode(incomingTree); GTreeNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -743,7 +745,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
public void testRenamingIncomingRootFunction() { public void testRenamingIncomingRootFunction() {
setProviderFunction("0x5000"); setProviderFunction("0x5000");
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
GTreeNode rootNode = getRootNode(incomingTree); GTreeNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren(); List<GTreeNode> children = rootNode.getChildren();
assertTrue( assertTrue(
@ -804,7 +806,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
} }
private GTreeNode getRootNode(final GTree tree, boolean filtered) { private GTreeNode getRootNode(final GTree tree, boolean filtered) {
myWaitForTree(tree, provider); waitForTree(tree);
final AtomicReference<GTreeNode> ref = new AtomicReference<>(); final AtomicReference<GTreeNode> ref = new AtomicReference<>();
runSwing(() -> ref.set(filtered ? tree.getViewRoot() : tree.getModelRoot())); runSwing(() -> ref.set(filtered ? tree.getViewRoot() : tree.getModelRoot()));
return ref.get(); return ref.get();
@ -874,7 +876,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private void setOutgoingFilter(final String text) { private void setOutgoingFilter(final String text) {
runSwing(() -> provider.setOutgoingFilter(text)); runSwing(() -> provider.setOutgoingFilter(text));
myWaitForTree(outgoingTree, provider); waitForTree(outgoingTree);
} }
private void setProviderFunction(String address) { private void setProviderFunction(String address) {
@ -1040,7 +1042,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private void setIncomingFilter(final String text) { private void setIncomingFilter(final String text) {
runSwing(() -> provider.setIncomingFilter(text)); runSwing(() -> provider.setIncomingFilter(text));
myWaitForTree(incomingTree, provider); waitForTree(incomingTree);
} }
private void setDepth(final int depth) { private void setDepth(final int depth) {
@ -1114,32 +1116,6 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return action; return action;
} }
private void myWaitForTree(GTree gTree, CallTreeProvider treeProvider) {
waitForSwing();
boolean didWait = false;
while (gTree.isBusy()) {
didWait = true;
try {
Thread.sleep(50);
}
catch (Exception e) {
// who cares?
}
}
waitForSwing();
if (didWait) {
// The logic here is that if we ever had to wait for the tree, then some other events
// may have been buffered while we were allowing the work to happen. Just to be sure
// that there are no buffered actions, lets try to wait again. If things are really
// settled down, then the extra call to wait should not have any effect. This 'try
// again' approach is an effort to catch update calls that can be schedule by actions
// from the Swing thread, which the test thread does not handle flawlessly.
myWaitForTree(gTree, treeProvider);
}
}
/** /**
* Shows and returns a provider for the specified address. * Shows and returns a provider for the specified address.
*/ */

View file

@ -772,7 +772,7 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
private void setOptionToAllowNavigationToOtherOpenPrograms() throws Exception { private void setOptionToAllowNavigationToOtherOpenPrograms() throws Exception {
runSwing(() -> { runSwing(() -> {
ToolOptions options = tool.getOptions("Navigation"); ToolOptions options = tool.getOptions("Navigation");
options.setBoolean("'Go To' in current program only", false); options.setBoolean("'Go To' in Current Program Only", false);
}); });
} }

View file

@ -1072,13 +1072,13 @@ public abstract class AbstractGhidraScriptMgrPluginTest
protected void assertSaveButtonEnabled() { protected void assertSaveButtonEnabled() {
waitForSwing(); waitForSwing();
DockingActionIf saveAction = getAction(plugin, "Save Script"); DockingActionIf saveAction = getAction(plugin, "Save Script");
assertTrue(saveAction.isEnabled()); assertTrue(saveAction.isEnabledForContext(editor.getActionContext(null)));
} }
protected void assertSaveButtonDisabled() { protected void assertSaveButtonDisabled() {
waitForSwing(); waitForSwing();
DockingActionIf saveAction = getAction(plugin, "Save Script"); DockingActionIf saveAction = getAction(plugin, "Save Script");
assertFalse(saveAction.isEnabled()); assertFalse(saveAction.isEnabledForContext(editor.getActionContext(null)));
assertEditorHasNoChanges(); assertEditorHasNoChanges();
} }

View file

@ -662,7 +662,7 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
} }
Symbol s = (Symbol) obj; Symbol s = (Symbol) obj;
if (getID() == s.getID()) { if (hasSameId(s)) {
return true; return true;
} }
@ -682,6 +682,13 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
return SystemUtilities.isEqual(myParent, otherParent); return SystemUtilities.isEqual(myParent, otherParent);
} }
private boolean hasSameId(Symbol s) {
if (getID() == s.getID()) {
return getProgram() == s.getProgram();
}
return false;
}
@Override @Override
public int hashCode() { public int hashCode() {
return (int) key; return (int) key;