mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/GP-789_emteere_RTTIOrderFix' into patch
This commit is contained in:
commit
acf78878ce
6 changed files with 128 additions and 97 deletions
|
@ -100,36 +100,38 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||||
Program program = model.getProgram();
|
Program program = model.getProgram();
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
|
String suffix = "";
|
||||||
|
try {
|
||||||
|
suffix = " at " + getPMDAttrList(program);
|
||||||
|
}
|
||||||
|
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() + ".";
|
||||||
|
handleError(message);
|
||||||
|
}
|
||||||
|
|
||||||
if (rtti0Model != null) {
|
// Label
|
||||||
|
boolean shouldCreateComment = true;
|
||||||
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
|
String rtti1Suffix = RTTI_1_NAME + suffix;
|
||||||
|
rtti1Suffix = SymbolUtilities.replaceInvalidChars(rtti1Suffix, true);
|
||||||
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model,
|
||||||
|
rtti1Suffix);
|
||||||
|
}
|
||||||
|
|
||||||
String suffix = "";
|
// Plate Comment
|
||||||
try {
|
if (shouldCreateComment) {
|
||||||
suffix = " at " + getPMDAttrList(program);
|
// comment created if a label was created, or createLabel option off
|
||||||
}
|
|
||||||
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() + ".";
|
|
||||||
handleError(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plate Comment
|
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_1_NAME,
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_1_NAME,
|
||||||
suffix, getDataAddress(), applyOptions);
|
suffix, getDataAddress(), applyOptions);
|
||||||
|
|
||||||
monitor.checkCanceled();
|
|
||||||
|
|
||||||
// Label
|
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
|
||||||
String rtti1Suffix = RTTI_1_NAME + suffix;
|
|
||||||
rtti1Suffix = SymbolUtilities.replaceInvalidChars(rtti1Suffix, true);
|
|
||||||
RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model,
|
|
||||||
rtti1Suffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -112,20 +112,27 @@ public class CreateRtti2BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||||
|
|
||||||
Program program = model.getProgram();
|
Program program = model.getProgram();
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
monitor.checkCanceled();
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
// Plate Comment
|
}
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
|
||||||
RTTI_2_NAME, null, getDataAddress(), applyOptions);
|
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
|
boolean shouldCreateComment = true;
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model, RTTI_2_NAME);
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model, RTTI_2_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plate Comment
|
||||||
|
if (shouldCreateComment) {
|
||||||
|
// comment created if a label was created, or createLabel option off
|
||||||
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
||||||
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
||||||
|
RTTI_2_NAME, null, getDataAddress(), applyOptions);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,23 +98,27 @@ public class CreateRtti3BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||||
Program program = model.getProgram();
|
Program program = model.getProgram();
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
monitor.checkCanceled();
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
if (rtti0Model != null) {
|
|
||||||
|
|
||||||
// Plate Comment
|
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
|
||||||
RTTI_3_NAME, null, getDataAddress(), applyOptions);
|
|
||||||
|
|
||||||
monitor.checkCanceled();
|
|
||||||
|
|
||||||
// Label
|
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
|
||||||
RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model, RTTI_3_NAME);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor.checkCanceled();
|
||||||
|
|
||||||
|
// Label
|
||||||
|
boolean shouldCreateComment = true;
|
||||||
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model, RTTI_3_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plate Comment
|
||||||
|
if (shouldCreateComment) {
|
||||||
|
// comment created if a label was created, or createLabel option off
|
||||||
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
||||||
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
||||||
|
RTTI_3_NAME, null, getDataAddress(), applyOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,22 +244,25 @@ public class CreateRtti4BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
|
||||||
Program program = model.getProgram();
|
Program program = model.getProgram();
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
|
||||||
if (rtti0Model != null) {
|
// Label
|
||||||
|
boolean shouldCreateComment = true;
|
||||||
// Plate Comment
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
// Plate Comment
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model,
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
|
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_4_NAME,
|
|
||||||
null, getDataAddress(), applyOptions);
|
|
||||||
monitor.checkCanceled();
|
|
||||||
|
|
||||||
// Label
|
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
|
||||||
RttiUtil.createSymbolFromDemangledType(program, getDataAddress(), rtti0Model,
|
|
||||||
RTTI_4_NAME);
|
RTTI_4_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plate Comment
|
||||||
|
if (shouldCreateComment) {
|
||||||
|
// comment created if a label was created, or createLabel option off
|
||||||
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
|
||||||
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, RTTI_4_NAME,
|
||||||
|
null, getDataAddress(), applyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -169,20 +169,23 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
|
||||||
|
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
if (rtti0Model != null) {
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
// Plate Comment
|
}
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
|
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
// Label
|
||||||
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
|
boolean shouldCreateComment = true;
|
||||||
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
monitor.checkCanceled();
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, vfTableAddress, rtti0Model,
|
||||||
|
|
||||||
// Label
|
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
|
||||||
RttiUtil.createSymbolFromDemangledType(program, vfTableAddress, rtti0Model,
|
|
||||||
VF_TABLE_LABEL);
|
VF_TABLE_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plate Comment
|
||||||
|
if (shouldCreateComment) {
|
||||||
|
// comment created if a label was created, or createLabel option off
|
||||||
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
|
||||||
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
||||||
|
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create functions that are referred to by the vf table.
|
// Create functions that are referred to by the vf table.
|
||||||
|
@ -209,21 +212,26 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
|
||||||
|
|
||||||
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
TypeDescriptorModel rtti0Model = model.getRtti0Model();
|
||||||
|
|
||||||
if (rtti0Model != null) {
|
if (rtti0Model == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor.checkCanceled();
|
||||||
|
|
||||||
// Plate Comment
|
// Label
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(
|
boolean shouldCreateComment = true;
|
||||||
program, META_LABEL + " pointer for " +
|
if (applyOptions.shouldCreateLabel()) {
|
||||||
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
shouldCreateComment = RttiUtil.createSymbolFromDemangledType(program, metaAddress, rtti0Model,
|
||||||
VF_TABLE_LABEL, null, metaAddress, applyOptions);
|
|
||||||
|
|
||||||
monitor.checkCanceled();
|
|
||||||
|
|
||||||
// Label
|
|
||||||
if (applyOptions.shouldCreateLabel()) {
|
|
||||||
RttiUtil.createSymbolFromDemangledType(program, metaAddress, rtti0Model,
|
|
||||||
VF_TABLE_LABEL + NAME_SEPARATOR + META_LABEL + "_ptr");
|
VF_TABLE_LABEL + NAME_SEPARATOR + META_LABEL + "_ptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plate Comment
|
||||||
|
if (shouldCreateComment) {
|
||||||
|
// comment created if a label was created, or createLabel option off
|
||||||
|
EHDataTypeUtilities.createPlateCommentIfNeeded(
|
||||||
|
program, META_LABEL + " pointer for " +
|
||||||
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
||||||
|
VF_TABLE_LABEL, null, metaAddress, applyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -61,11 +61,11 @@ public class RttiUtil {
|
||||||
* @param rttiAddress Address of the RTTI datatype
|
* @param rttiAddress Address of the RTTI datatype
|
||||||
* @param typeDescriptorModel the model for the type descriptor structure
|
* @param typeDescriptorModel the model for the type descriptor structure
|
||||||
* @param rttiSuffix suffix name indicating which type of RTTI structure
|
* @param rttiSuffix suffix name indicating which type of RTTI structure
|
||||||
* @return the symbol or null.
|
* @return true if a symbol was created, false otherwise
|
||||||
*/
|
*/
|
||||||
static Symbol createSymbolFromDemangledType(Program program, Address rttiAddress,
|
static boolean createSymbolFromDemangledType(Program program, Address rttiAddress,
|
||||||
TypeDescriptorModel typeDescriptorModel, String rttiSuffix) {
|
TypeDescriptorModel typeDescriptorModel, String rttiSuffix) {
|
||||||
|
|
||||||
rttiSuffix = SymbolUtilities.replaceInvalidChars(rttiSuffix, true);
|
rttiSuffix = SymbolUtilities.replaceInvalidChars(rttiSuffix, true);
|
||||||
|
|
||||||
// Get or create the namespace for this RTTI's type descriptor.
|
// Get or create the namespace for this RTTI's type descriptor.
|
||||||
|
@ -94,25 +94,32 @@ public class RttiUtil {
|
||||||
// See if the symbol already exists for the RTTI data.
|
// See if the symbol already exists for the RTTI data.
|
||||||
Symbol matchingSymbol = symbolTable.getSymbol(rttiSuffix, rttiAddress, classNamespace);
|
Symbol matchingSymbol = symbolTable.getSymbol(rttiSuffix, rttiAddress, classNamespace);
|
||||||
if (matchingSymbol != null) {
|
if (matchingSymbol != null) {
|
||||||
return matchingSymbol;
|
return false;
|
||||||
}
|
}
|
||||||
// Don't create it if a similar symbol already exists at the address of the data.
|
// Don't create it if a similar symbol already exists at the address of the data.
|
||||||
Symbol[] symbols = symbolTable.getSymbols(rttiAddress);
|
Symbol[] symbols = symbolTable.getSymbols(rttiAddress);
|
||||||
for (Symbol symbol : symbols) {
|
for (Symbol symbol : symbols) {
|
||||||
String name = symbol.getName();
|
String name = symbol.getName();
|
||||||
if (name.contains(rttiSuffix)) {
|
if (name.contains(rttiSuffix)) {
|
||||||
return symbol; // Similar symbol already exists.
|
return false; // Similar symbol already exists.
|
||||||
|
}
|
||||||
|
// assume any imported symbol is better than what we would put down
|
||||||
|
// if mangled, it will get demangled later
|
||||||
|
SourceType source = symbol.getSource();
|
||||||
|
if (source == SourceType.IMPORTED) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Didn't find the symbol, so create it.
|
// Didn't find the symbol, so create it.
|
||||||
return symbolTable.createLabel(rttiAddress, rttiSuffix, classNamespace,
|
symbolTable.createLabel(rttiAddress, rttiSuffix, classNamespace,
|
||||||
SourceType.IMPORTED);
|
SourceType.IMPORTED);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
Msg.error(RttiUtil.class,
|
Msg.error(RttiUtil.class,
|
||||||
"Unable to create label for " + rttiSuffix + " at " + rttiAddress + ".", e);
|
"Unable to create label for " + rttiSuffix + " at " + rttiAddress + ".", e);
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue