mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-28 22:45:41 +08:00
GP-111_emteere_RTTI3_CreationFix
This commit is contained in:
+7
-4
@@ -167,7 +167,7 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDa
|
||||
return 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+7
-5
@@ -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 CreateTypeDescriptorBackgroundCmd
|
||||
Msg.error(this, "Failed to create TypeDescriptor name at " + arrayAddr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,14 +140,14 @@ public class CreateTypeDescriptorBackgroundCmd
|
||||
String 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;
|
||||
}
|
||||
|
||||
+16
-5
@@ -71,7 +71,7 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||
@Override
|
||||
protected boolean createAssociatedData() throws CancelledException {
|
||||
|
||||
return createRtti0();
|
||||
return createRtti0() | createRtti3();
|
||||
}
|
||||
|
||||
private boolean createRtti0() throws CancelledException {
|
||||
@@ -83,6 +83,15 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||
return 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected 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 Comment
|
||||
EHDataTypeUtilities.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<Rt
|
||||
if (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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-8
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user