Ghidra is a software reverse engineering (SRE) framework
Test fixes
dragonmacherf81300e2aa2c
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.javaindex 155fd8d4f3..1e701b4432 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java@@ -934,9 +934,14 @@ public class ProgramBuilder {}public void createComment(String address, String comment, int commentType) {+ CommentType type = CommentType.values()[commentType];+ createComment(address, comment, type);+ }++ public void createComment(String address, String comment, CommentType type) {tx(() -> {Listing listing = program.getListing();- listing.setComment(addr(address), commentType, comment);+ listing.setComment(addr(address), type, comment);});}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/data/DataManagerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/data/DataManagerTest.javaindex 2cd724917c..1c81a4e210 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/data/DataManagerTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/data/DataManagerTest.java@@ -26,7 +26,6 @@ import ghidra.program.database.ProgramDB;import ghidra.program.model.data.*;import ghidra.test.AbstractGhidraHeadedIntegrationTest;import ghidra.util.InvalidNameException;-import ghidra.util.Msg;import ghidra.util.task.TaskMonitor;public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {@@ -49,10 +48,8 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testSetName() throws InvalidNameException {- String oldName = dataMgr.getName();String newName = "NewName";- dataMgr.setName("NewName");-+ dataMgr.setName(newName);assertEquals(newName, dataMgr.getName());}@@ -99,16 +96,12 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null);dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null);- dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "zEnum", 2), null);- dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "zEnum2", 2), null);-List<DataType> list = new ArrayList<DataType>();dataMgr.findDataTypes("Enum", list);assertEquals(3, list.size());list.clear();dataMgr.findDataTypes("Enum1", list);- Msg.debug(this, "dts: " + list);Category c1 = root.createCategory("c1");dataMgr.resolve(new EnumDataType(c1.getCategoryPath(), "Enum", 2), null);@@ -468,25 +461,20 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testResolveDataType() {-- DataTypeManager dtm = new StandAloneDataTypeManager("Test");+ StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");int id = dtm.startTransaction("");- try {- DataType byteDT = dtm.resolve(new ByteDataType(), null);-- DataType myByteDT = dataMgr.resolve(byteDT, null);- assertTrue(myByteDT == dataMgr.getDataType("/byte"));- assertNotNull(myByteDT);- assertEquals(myByteDT.getCategoryPath(), CategoryPath.ROOT);- }- finally {- dtm.endTransaction(id, true);- }+ DataType byteDT = dtm.resolve(new ByteDataType(), null);+ DataType myByteDT = dataMgr.resolve(byteDT, null);+ assertTrue(myByteDT == dataMgr.getDataType("/byte"));+ assertNotNull(myByteDT);+ assertEquals(myByteDT.getCategoryPath(), CategoryPath.ROOT);+ dtm.endTransaction(id, true);+ dtm.close();}@Testpublic void testResolveDataType2() throws Exception {- DataTypeManager dtm = new StandAloneDataTypeManager("Test");+ StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");int id = dtm.startTransaction("");Category otherRoot = dataMgr.getRootCategory();Category subc = otherRoot.createCategory("subc");@@ -501,7 +489,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testResolveDataType3() throws Exception {- DataTypeManager dtm = new StandAloneDataTypeManager("Test");+ StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");int id = dtm.startTransaction("");Category otherRoot = dataMgr.getRootCategory();Category subc = otherRoot.createCategory("subc");diff --git a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.javaindex ae3723456a..9dd0681895 100644--- a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java+++ b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java@@ -459,10 +459,10 @@ public class DiffTest extends DiffTestAdapter {programBuilderDiffTest1.createMemory("d4", "0x400", 0x100);programBuilderDiffTest2.createMemory("d2", "0x200", 0x100);- programBuilderDiffTest2.createComment("0x01008000", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x01008607", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x01008a99", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x0100a001", "My comment", CodeUnit.EOL_COMMENT);+ programBuilderDiffTest2.createComment("0x01008000", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x01008607", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x01008a99", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x0100a001", "My comment", CommentType.EOL);openDiff(diffTestP1, diffTestP2);JTree tree = getProgramTree();@@ -528,10 +528,10 @@ public class DiffTest extends DiffTestAdapter {programBuilderDiffTest1.createMemory("d4", "0x400", 0x100);programBuilderDiffTest2.createMemory("d2", "0x200", 0x100);- programBuilderDiffTest2.createComment("0x01008000", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x01008607", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x01009943", "My comment", CodeUnit.EOL_COMMENT);- programBuilderDiffTest2.createComment("0x0100a001", "My comment", CodeUnit.EOL_COMMENT);+ programBuilderDiffTest2.createComment("0x01008000", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x01008607", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x01009943", "My comment", CommentType.EOL);+ programBuilderDiffTest2.createComment("0x0100a001", "My comment", CommentType.EOL);openDiff(diffTestP1, diffTestP2);JTree tree = getProgramTree();diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CodeUnit.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CodeUnit.javaindex 95de9f9c5a..214c5118b8 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CodeUnit.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CodeUnit.java@@ -71,11 +71,6 @@ public interface CodeUnit extends MemBuffer, PropertySet {@Deprecatedpublic static final int REPEATABLE_COMMENT = 4;-// /**-// * Property type for fall through property-// */-// public static final int FALL_THROUGH = 4;-/*** Any comment property.*/@@ -105,11 +100,13 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get the label for this code unit.+ * @return the label for this code unit.*/public String getLabel();/*** Get the Symbols for this code unit.+ * @return the Symbols for this code unit.* @throws ConcurrentModificationException if this object is no* longer valid.*/@@ -117,6 +114,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get the Primary Symbol for this code unit.+ * @return the Primary Symbol for this code unit.* @throws ConcurrentModificationException if this object is no* longer valid.*/@@ -124,16 +122,19 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get the starting address for this code unit.+ * @return the starting address for this code unit.*/public Address getMinAddress();/*** Get the ending address for this code unit.+ * @return the ending address for this code unit.*/public Address getMaxAddress();/*** Get the mnemonic for this code unit, e.g., MOV, JMP+ * @return the mnemonic for this code unit, e.g., MOV, JMP*/public String getMnemonicString();@@ -143,7 +144,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {* @param commentType either EOL_COMMENT, PRE_COMMENT,* POST_COMMENT, or REPEATABLE_COMMENT* @return the comment string of the appropriate type or null if no comment of- * that type exists for this codeunit+ * that type exists for this code unit* @throws IllegalArgumentException if type is not one of the* three types of comments supported* @deprecated use {@link #getComment(CommentType)} instead@@ -250,7 +251,8 @@ public interface CodeUnit extends MemBuffer, PropertySet {public byte[] getBytes() throws MemoryAccessException;/**- * Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.+ * Copies max(buffer.length, code unit length) bytes into buffer starting at the given offset in+ * {@code buffer}.* @param buffer byte array to copy into* @param bufferOffset offset in byte array the copy will start* @throws MemoryAccessException if the full number of bytes could not be read.@@ -260,6 +262,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Returns true if address is contained in the range of this codeUnit* @param testAddr the address to test.+ * @return true if address is contained in the range of this codeUnit*/public boolean contains(Address testAddr);@@ -297,12 +300,14 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get the references for the operand index.* @param index operand index (0 is the first operand)+ * @return the references for the operand index.*/public Reference[] getOperandReferences(int index);/*** Get the primary reference for the operand index.* @param index operand index (0 is the first operand)+ * @return the primary reference for the operand index.*/public Reference getPrimaryReference(int index);@@ -332,15 +337,16 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get an iterator over all references TO this code unit.+ * @return an iterator over all references TO this code unit.*/public ReferenceIterator getReferenceIteratorTo();/*** Returns the program that generated this CodeUnit.+ * @return the program that generated this CodeUnit.*/public Program getProgram();- ///////////////////////////////////////////////////////////////////////////*** Gets the external reference (if any) at the opIndex* @param opIndex the operand index to look for external references@@ -351,6 +357,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Remove external reference (if any) at the given opIndex* opIndex the index of the operand from which to remove any external reference.+ * @param opIndex the op index*/public void removeExternalReference(int opIndex);@@ -397,6 +404,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {/*** Get the number of operands for this code unit.+ * @return the number of operands for this code unit.*/public int getNumOperands();@@ -404,7 +412,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {* Get the Address for the given operand index if one exists. Data* objects have one operand (the value).* @param opIndex index of the operand.- * @return An addres if the operand represents a fully qualified+ * @return An address if the operand represents a fully qualified* address (given the context), or if the operand is a Scalar treated* as an address. Null is returned if no address or scalar exists on that* operand.