Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0 Updated VT test javadocs to indicate unsupported use of Program.setLanguage method.

ghidra1b4a25b4c2de7
diff --git a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java
index 17aa8a8c94..b08847de43 100644
--- a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java
+++ b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java
@@ -1233,7 +1233,13 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg
throws Exception {
useMatch("0x00401040", "0x00401040");
- setLanguage(sourceFunction, "Toy:LE:32:default", "default");
+ // NOTE: This test is performing an unsupported operation when changing a
+ // Program's Language while it is in use. This is potentially very bad
+ // since a DomainObjectEvent.RESTORED will be triggered which requires
+ // all Program related objects to be discarded since there state is
+ // unreliable and error prone.
+
+ setLanguage(sourceProgram, "Toy:LE:32:default", "default");
setCallingConvention(sourceFunction, "__stdcall");
setCallingConvention(destinationFunction, "__cdecl");
@@ -1274,7 +1280,13 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg
throws Exception {
useMatch("0x00401040", "0x00401040");
- setLanguage(sourceFunction, "Toy:LE:32:default", "default");
+ // NOTE: This test is performing an unsupported operation when changing a
+ // Program's Language while it is in use. This is potentially very bad
+ // since a DomainObjectEvent.RESTORED will be triggered which requires
+ // all Program related objects to be discarded since there state is
+ // unreliable and error prone.
+
+ setLanguage(sourceProgram, "Toy:LE:32:default", "default");
setCallingConvention(sourceFunction, "__stdcall");
setCallingConvention(destinationFunction, "__cdecl");
@@ -2544,10 +2556,27 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg
}
}
- private void setLanguage(Function function, String languageID, String compilerSpecName)
+ /**
+ * Alter the Language and CompilerSpec used by a specified Program.
+ * <p>
+ * WARNING! Invoking this method requires all Program related objects to be discarded.
+ * Continued use of objects previously obtained from the specified program may have an
+ * invalid state.
+ *
+ * @param program program whose language is to be changed
+ * @param languageID new language ID
+ * @param compilerSpecName compiler space ID known to language
+ * @throws LanguageNotFoundException specified language could not be found
+ * @throws IllegalStateException thrown if any error occurs, including a cancelled monitor, which leaves this
+ * program object in an unusable state. The current transaction should be aborted and the program instance
+ * discarded.
+ * @throws IncompatibleLanguageException thrown if the new language is too different from the
+ * existing language.
+ * @throws LockException if the program is shared and not checked out exclusively.
+ */
+ private void setLanguage(Program program, String languageID, String compilerSpecName)
throws IllegalStateException, LockException, IncompatibleLanguageException,
LanguageNotFoundException {
- Program program = function.getProgram();
int transaction = -1;
try {
transaction =
diff --git a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionSignatureMarkupOptionsTest.java b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionSignatureMarkupOptionsTest.java
index c1aac22d7d..59fc317b22 100644
--- a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionSignatureMarkupOptionsTest.java
+++ b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionSignatureMarkupOptionsTest.java
@@ -120,6 +120,13 @@ public class FunctionSignatureMarkupOptionsTest extends AbstractFunctionSignatur
@Test
public void testNameMatchReplaceCallingConventionBothSpecified() throws Exception {
+
+ // NOTE: This test is performing an unsupported operation when changing a
+ // Program's Language while it is in use. This is potentially very bad
+ // since a DomainObjectEvent.RESTORED will be triggered which requires
+ // all Program related objects to be discarded since there state is
+ // unreliable and error prone.
+
setLanguage(destinationProgram, "Toy:LE:32:default", "default");
useMatch("0x00411860", "0x00411830");
@@ -167,6 +174,13 @@ public class FunctionSignatureMarkupOptionsTest extends AbstractFunctionSignatur
@Test
public void testNameMatchNotFoundCallingConventionBothSpecified() throws Exception {
+
+ // NOTE: This test is performing an unsupported operation when changing a
+ // Program's Language while it is in use. This is potentially very bad
+ // since a DomainObjectEvent.RESTORED will be triggered which requires
+ // all Program related objects to be discarded since there state is
+ // unreliable and error prone.
+
setLanguage(destinationProgram, "Toy:LE:32:default", "default");
useMatch("0x00411860", "0x00411830");
@@ -770,12 +784,24 @@ public class FunctionSignatureMarkupOptionsTest extends AbstractFunctionSignatur
checkMarkupStatus(functionSignatureMarkupItems, VTMarkupItemStatus.UNAPPLIED);
}
- // TODO
- // TODO
- // TODO this address needs to be updated: I think it is 00411da0/00411d80
- // TODO
- // TODO
-
+ /**
+ * Alter the Language and CompilerSpec used by a specified Program.
+ * <p>
+ * WARNING! Invoking this method requires all Program related objects to be discarded.
+ * Continued use of objects previously obtained from the specified program may have an
+ * invalid state.
+ *
+ * @param program program whose language is to be changed
+ * @param languageID new language ID
+ * @param compilerSpecName compiler space ID known to language
+ * @throws LanguageNotFoundException specified language could not be found
+ * @throws IllegalStateException thrown if any error occurs, including a cancelled monitor, which leaves this
+ * program object in an unusable state. The current transaction should be aborted and the program instance
+ * discarded.
+ * @throws IncompatibleLanguageException thrown if the new language is too different from the
+ * existing language.
+ * @throws LockException if the program is shared and not checked out exclusively.
+ */
private void setLanguage(Program program, String languageID, String compilerSpecName)
throws IllegalStateException, LockException, IncompatibleLanguageException,
LanguageNotFoundException {