mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-31 09:26:32 +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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
createData();
|
boolean didCreate = createData();
|
||||||
|
|
||||||
boolean success = true;
|
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 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;
|
success = false;
|
||||||
}
|
}
|
||||||
setStatusMsg(getName() + " completed successfully!");
|
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.
|
* 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(),
|
* <br>If you need to create data other than by using the data type returned from getDataType(),
|
||||||
* you should override this method.
|
* you should override this method.
|
||||||
|
* @return true if had to create, false otherwise
|
||||||
* @throws CodeUnitInsertionException if the data can't be created.
|
* @throws CodeUnitInsertionException if the data can't be created.
|
||||||
* @throws CancelledException if the user cancels this task.
|
* @throws CancelledException if the user cancels this task.
|
||||||
*/
|
*/
|
||||||
protected void createData() throws CodeUnitInsertionException, CancelledException {
|
protected boolean createData() throws CodeUnitInsertionException, CancelledException {
|
||||||
|
|
||||||
Program program = model.getProgram();
|
Program program = model.getProgram();
|
||||||
Memory memory = program.getMemory();
|
Memory memory = program.getMemory();
|
||||||
@@ -230,13 +231,15 @@ public abstract class AbstractCreateDataBackgroundCmd<T extends AbstractCreateDa
|
|||||||
|
|
||||||
// Is the data type already applied at the address?
|
// Is the data type already applied at the address?
|
||||||
if (matchingDataExists(dt, program, address)) {
|
if (matchingDataExists(dt, program, address)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
// Create data at the address using the datatype.
|
// Create data at the address using the datatype.
|
||||||
DataUtilities.createData(program, address, dt, dt.getLength(), false, getClearDataMode());
|
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
|
* 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
|
* be applied as a sized character array immediately following the structure whose size does not include
|
||||||
* the char array bytes.
|
* the char array bytes.
|
||||||
|
* @return true if the data type needed to be created
|
||||||
* @throws CodeUnitInsertionException
|
* @throws CodeUnitInsertionException
|
||||||
* @throws CancelledException
|
* @throws CancelledException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void createData() throws CodeUnitInsertionException, CancelledException {
|
protected boolean createData() throws CodeUnitInsertionException, CancelledException {
|
||||||
super.createData(); // create the TypeDesciptor structure
|
super.createData(); // create the TypeDesciptor structure
|
||||||
|
|
||||||
// Determine the size of the flexible char array storage and create properly sized array
|
// 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);
|
Msg.error(this, "Failed to create TypeDescriptor name at " + arrayAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,14 +140,14 @@ public class CreateTypeDescriptorBackgroundCmd
|
|||||||
String prefix = demangledName + " ";
|
String prefix = demangledName + " ";
|
||||||
|
|
||||||
// Plate Comment
|
// Plate Comment
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program, prefix, RTTI_0_NAME, null, getDataAddress(),
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program, prefix, RTTI_0_NAME, null,
|
||||||
applyOptions);
|
getDataAddress(), applyOptions);
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
EHDataTypeUtilities.createSymbolIfNeeded(program, prefix, RTTI_0_NAME, null, getDataAddress(),
|
EHDataTypeUtilities.createSymbolIfNeeded(program, prefix, RTTI_0_NAME, null,
|
||||||
applyOptions);
|
getDataAddress(), applyOptions);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-5
@@ -71,7 +71,7 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
|||||||
@Override
|
@Override
|
||||||
protected boolean createAssociatedData() throws CancelledException {
|
protected boolean createAssociatedData() throws CancelledException {
|
||||||
|
|
||||||
return createRtti0();
|
return createRtti0() | createRtti3();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean createRtti0() throws CancelledException {
|
private boolean createRtti0() throws CancelledException {
|
||||||
@@ -83,6 +83,15 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
|||||||
return cmd.applyTo(model.getProgram(), monitor);
|
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
|
@Override
|
||||||
protected boolean createMarkup() throws CancelledException {
|
protected boolean createMarkup() throws CancelledException {
|
||||||
|
|
||||||
@@ -101,14 +110,15 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
|||||||
}
|
}
|
||||||
catch (InvalidDataTypeException e) {
|
catch (InvalidDataTypeException e) {
|
||||||
// Couldn't get pmd and attributes so leave it off and simply log the error.
|
// 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);
|
handleError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plate Comment
|
// Plate Comment
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_1_NAME,
|
||||||
RTTI_1_NAME, suffix, getDataAddress(), applyOptions);
|
suffix, getDataAddress(), applyOptions);
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
@@ -116,7 +126,8 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
|||||||
if (applyOptions.shouldCreateLabel()) {
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
String rtti1Suffix = RTTI_1_NAME + suffix;
|
String rtti1Suffix = RTTI_1_NAME + suffix;
|
||||||
rtti1Suffix = SymbolUtilities.replaceInvalidChars(rtti1Suffix, true);
|
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;
|
package ghidra.app.cmd.data.rtti;
|
||||||
|
|
||||||
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getAlignedPack4Structure;
|
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.*;
|
||||||
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getReferencedAddress;
|
|
||||||
|
|
||||||
import ghidra.app.cmd.data.EHDataTypeUtilities;
|
import ghidra.app.cmd.data.EHDataTypeUtilities;
|
||||||
import ghidra.app.cmd.data.TypeDescriptorModel;
|
import ghidra.app.cmd.data.TypeDescriptorModel;
|
||||||
@@ -402,4 +401,17 @@ public class Rtti1Model extends AbstractCreateRttiDataModel {
|
|||||||
return rtti0Model;
|
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;
|
package ghidra.app.cmd.data.rtti;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -166,7 +165,7 @@ public class RttiCreateCmdTest extends AbstractRttiTest {
|
|||||||
|
|
||||||
// ---- check Base ----
|
// ---- check Base ----
|
||||||
checkNoData(program, 0x01003340L);
|
checkNoData(program, 0x01003340L);
|
||||||
checkNoData(program, 0x01003368L);
|
checkRtti3Data(program, 0x01003368L);
|
||||||
checkRtti2Data(program, 0x01003390L, 1);
|
checkRtti2Data(program, 0x01003390L, 1);
|
||||||
checkRtti1Data(program, 0x010033a8L);
|
checkRtti1Data(program, 0x010033a8L);
|
||||||
checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
|
checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
|
||||||
@@ -202,8 +201,8 @@ public class RttiCreateCmdTest extends AbstractRttiTest {
|
|||||||
|
|
||||||
// ---- check Base ----
|
// ---- check Base ----
|
||||||
checkNoData(program, 0x01003340L);
|
checkNoData(program, 0x01003340L);
|
||||||
checkNoData(program, 0x01003368L);
|
checkRtti3Data(program, 0x01003368L);
|
||||||
checkNoData(program, 0x01003390L);
|
checkRtti2Data(program, 0x01003390L, 1);
|
||||||
checkRtti1Data(program, 0x010033a8L);
|
checkRtti1Data(program, 0x010033a8L);
|
||||||
checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
|
checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
|
||||||
checkNoData(program, 0x010032f0L);
|
checkNoData(program, 0x010032f0L);
|
||||||
@@ -384,7 +383,7 @@ public class RttiCreateCmdTest extends AbstractRttiTest {
|
|||||||
|
|
||||||
// ---- check Base ----
|
// ---- check Base ----
|
||||||
checkNoData(program, 0x101003340L);
|
checkNoData(program, 0x101003340L);
|
||||||
checkNoData(program, 0x101003368L);
|
checkRtti3Data(program, 0x101003368L);
|
||||||
checkRtti2Data(program, 0x101003390L, 1);
|
checkRtti2Data(program, 0x101003390L, 1);
|
||||||
checkRtti1Data(program, 0x1010033a8L);
|
checkRtti1Data(program, 0x1010033a8L);
|
||||||
checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
|
checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
|
||||||
@@ -420,8 +419,8 @@ public class RttiCreateCmdTest extends AbstractRttiTest {
|
|||||||
|
|
||||||
// ---- check Base ----
|
// ---- check Base ----
|
||||||
checkNoData(program, 0x101003340L);
|
checkNoData(program, 0x101003340L);
|
||||||
checkNoData(program, 0x101003368L);
|
checkRtti3Data(program, 0x101003368L);
|
||||||
checkNoData(program, 0x101003390L);
|
checkRtti2Data(program, 0x101003390L, 1);
|
||||||
checkRtti1Data(program, 0x1010033a8L);
|
checkRtti1Data(program, 0x1010033a8L);
|
||||||
checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
|
checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
|
||||||
checkNoData(program, 0x1010032f0L);
|
checkNoData(program, 0x1010032f0L);
|
||||||
|
|||||||
Reference in New Issue
Block a user