Ghidra is a software reverse engineering (SRE) framework
GP-111_emteere_RTTI3_CreationFix
emteere655b3a5a2555
diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/AbstractCreateDataBackgroundCmd.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/AbstractCreateDataBackgroundCmd.javaindex 76c3c1a213..02b3147e43 100644--- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/AbstractCreateDataBackgroundCmd.java+++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/AbstractCreateDataBackgroundCmd.java@@ -167,7 +167,7 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDareturn false;}- createData();+ boolean didCreate = createData();boolean success = true;@@ -183,7 +183,7 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDa}// If following data when applying, create any data referred to by the data just created.- if (applyOptions.shouldFollowData() && !createAssociatedData()) {+ if (didCreate && applyOptions.shouldFollowData() && !createAssociatedData()) {success = false;}setStatusMsg(getName() + " completed successfully!");@@ -200,10 +200,11 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDa* Creates data at this command's address using the data type obtained from the model.* <br>If you need to create data other than by using the data type returned from getDataType(),* you should override this method.+ * @return true if had to create, false otherwise* @throws CodeUnitInsertionException if the data can't be created.* @throws CancelledException if the user cancels this task.*/- protected void createData() throws CodeUnitInsertionException, CancelledException {+ protected boolean createData() throws CodeUnitInsertionException, CancelledException {Program program = model.getProgram();Memory memory = program.getMemory();@@ -230,13 +231,15 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDa// Is the data type already applied at the address?if (matchingDataExists(dt, program, address)) {- return;+ return false;}monitor.checkCanceled();// Create data at the address using the datatype.DataUtilities.createData(program, address, dt, dt.getLength(), false, getClearDataMode());++ return true;}/**diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/CreateTypeDescriptorBackgroundCmd.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/CreateTypeDescriptorBackgroundCmd.javaindex 21ede2193f..55ad6b8b16 100644--- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/CreateTypeDescriptorBackgroundCmd.java+++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/CreateTypeDescriptorBackgroundCmd.java@@ -90,11 +90,12 @@ public class CreateTypeDescriptorBackgroundCmd* as its last component ( char[0] name ). The string data associated with this flexible char array will* be applied as a sized character array immediately following the structure whose size does not include* the char array bytes.+ * @return true if the data type needed to be created* @throws CodeUnitInsertionException* @throws CancelledException*/@Override- protected void createData() throws CodeUnitInsertionException, CancelledException {+ protected boolean createData() throws CodeUnitInsertionException, CancelledException {super.createData(); // create the TypeDesciptor structure// Determine the size of the flexible char array storage and create properly sized array@@ -116,6 +117,7 @@ public class CreateTypeDescriptorBackgroundCmdMsg.error(this, "Failed to create TypeDescriptor name at " + arrayAddr);}+ return true;}@Override@@ -138,14 +140,14 @@ public class CreateTypeDescriptorBackgroundCmdString prefix = demangledName + " ";// Plate Comment- EHDataTypeUtilities.createPlateCommentIfNeeded(program, prefix, RTTI_0_NAME, null, getDataAddress(),- applyOptions);+ EHDataTypeUtilities.createPlateCommentIfNeeded(program, prefix, RTTI_0_NAME, null,+ getDataAddress(), applyOptions);monitor.checkCanceled();// Label- EHDataTypeUtilities.createSymbolIfNeeded(program, prefix, RTTI_0_NAME, null, getDataAddress(),- applyOptions);+ EHDataTypeUtilities.createSymbolIfNeeded(program, prefix, RTTI_0_NAME, null,+ getDataAddress(), applyOptions);return true;}diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateRtti1BackgroundCmd.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateRtti1BackgroundCmd.javaindex dbcb03afc9..5c490aceaa 100644--- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateRtti1BackgroundCmd.java+++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateRtti1BackgroundCmd.java@@ -71,7 +71,7 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt@Overrideprotected boolean createAssociatedData() throws CancelledException {- return createRtti0();+ return createRtti0() | createRtti3();}private boolean createRtti0() throws CancelledException {@@ -83,6 +83,15 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rtreturn cmd.applyTo(model.getProgram(), monitor);}+ private boolean createRtti3() throws CancelledException {++ monitor.checkCanceled();++ CreateRtti3BackgroundCmd cmd =+ new CreateRtti3BackgroundCmd(model.getRtti3Model(), applyOptions);+ return cmd.applyTo(model.getProgram(), monitor);+ }+@Overrideprotected boolean createMarkup() throws CancelledException {@@ -101,14 +110,15 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt}catch (InvalidDataTypeException e) {// Couldn't get pmd and attributes so leave it off and simply log the error.- String message = "Unable to get PMD and attributes for RTTI1 at " + getDataAddress() + ".";+ String message =+ "Unable to get PMD and attributes for RTTI1 at " + getDataAddress() + ".";handleError(message);}// Plate CommentEHDataTypeUtilities.createPlateCommentIfNeeded(program,- RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,- RTTI_1_NAME, suffix, getDataAddress(), applyOptions);+ RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_1_NAME,+ suffix, getDataAddress(), applyOptions);monitor.checkCanceled();@@ -116,7 +126,8 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rtif (applyOptions.shouldCreateLabel()) {String rtti1Suffix = RTTI_1_NAME + suffix;rtti1Suffix = SymbolUtilities.replaceInvalidChars(rtti1Suffix, true);- RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model, rtti1Suffix);+ RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model,+ rtti1Suffix);}}diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/Rtti1Model.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/Rtti1Model.javaindex 4d01686cfb..4dfea16da2 100644--- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/Rtti1Model.java+++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/Rtti1Model.java@@ -15,8 +15,7 @@*/package ghidra.app.cmd.data.rtti;-import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getAlignedPack4Structure;-import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getReferencedAddress;+import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.*;import ghidra.app.cmd.data.EHDataTypeUtilities;import ghidra.app.cmd.data.TypeDescriptorModel;@@ -402,4 +401,17 @@ public class Rtti1Model extends AbstractCreateRttiDataModel {return rtti0Model;}+ /**+ * Gets the BaseClassDescriptor (RTTI 3) model associated with this RTTI 1.+ * @return the BaseClassDescriptor (RTTI 3) model or null.+ */+ public Rtti3Model getRtti3Model() {+ try {+ checkValidity();+ }+ catch (InvalidDataTypeException e) {+ return null;+ }+ return rtti3Model;+ }}diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/test/java/ghidra/app/cmd/data/rtti/RttiCreateCmdTest.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/test/java/ghidra/app/cmd/data/rtti/RttiCreateCmdTest.javaindex 5547c195e3..a2dce46032 100644--- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/test/java/ghidra/app/cmd/data/rtti/RttiCreateCmdTest.java+++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/test/java/ghidra/app/cmd/data/rtti/RttiCreateCmdTest.java@@ -15,8 +15,7 @@*/package ghidra.app.cmd.data.rtti;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertTrue;+import static org.junit.Assert.*;import java.util.List;@@ -166,7 +165,7 @@ public class RttiCreateCmdTest extends AbstractRttiTest {// ---- check Base ----checkNoData(program, 0x01003340L);- checkNoData(program, 0x01003368L);+ checkRtti3Data(program, 0x01003368L);checkRtti2Data(program, 0x01003390L, 1);checkRtti1Data(program, 0x010033a8L);checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");@@ -202,8 +201,8 @@ public class RttiCreateCmdTest extends AbstractRttiTest {// ---- check Base ----checkNoData(program, 0x01003340L);- checkNoData(program, 0x01003368L);- checkNoData(program, 0x01003390L);+ checkRtti3Data(program, 0x01003368L);+ checkRtti2Data(program, 0x01003390L, 1);checkRtti1Data(program, 0x010033a8L);checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");checkNoData(program, 0x010032f0L);@@ -384,7 +383,7 @@ public class RttiCreateCmdTest extends AbstractRttiTest {// ---- check Base ----checkNoData(program, 0x101003340L);- checkNoData(program, 0x101003368L);+ checkRtti3Data(program, 0x101003368L);checkRtti2Data(program, 0x101003390L, 1);checkRtti1Data(program, 0x1010033a8L);checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");@@ -420,8 +419,8 @@ public class RttiCreateCmdTest extends AbstractRttiTest {// ---- check Base ----checkNoData(program, 0x101003340L);- checkNoData(program, 0x101003368L);- checkNoData(program, 0x101003390L);+ checkRtti3Data(program, 0x101003368L);+ checkRtti2Data(program, 0x101003390L, 1);checkRtti1Data(program, 0x1010033a8L);checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");checkNoData(program, 0x1010032f0L);