mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GT-3341_emteere_RTTIPerformance Code Review changes
This commit is contained in:
parent
b51a9d7ff4
commit
edfff3a267
5 changed files with 15 additions and 56 deletions
|
@ -22,7 +22,8 @@ import ghidra.app.cmd.data.CreateDataCmd;
|
||||||
import ghidra.app.services.*;
|
import ghidra.app.services.*;
|
||||||
import ghidra.app.util.importer.MessageLog;
|
import ghidra.app.util.importer.MessageLog;
|
||||||
import ghidra.framework.options.Options;
|
import ghidra.framework.options.Options;
|
||||||
import ghidra.program.model.address.*;
|
import ghidra.program.model.address.Address;
|
||||||
|
import ghidra.program.model.address.AddressSetView;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.listing.BookmarkType;
|
import ghidra.program.model.listing.BookmarkType;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
|
@ -56,7 +57,10 @@ public class EmbeddedMediaAnalyzer extends AbstractAnalyzer {
|
||||||
|
|
||||||
Memory memory = program.getMemory();
|
Memory memory = program.getMemory();
|
||||||
AddressSetView validMemorySet = memory.getLoadedAndInitializedAddressSet();
|
AddressSetView validMemorySet = memory.getLoadedAndInitializedAddressSet();
|
||||||
AddressSet searchSet = set.intersect(validMemorySet);
|
if (validMemorySet.isEmpty()) {
|
||||||
|
return false; // valid addresses to search
|
||||||
|
}
|
||||||
|
AddressSetView searchSet = set.intersect(validMemorySet);
|
||||||
|
|
||||||
MemoryBytePatternSearcher searcher = new MemoryBytePatternSearcher("Embedded Media");
|
MemoryBytePatternSearcher searcher = new MemoryBytePatternSearcher("Embedded Media");
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class MemoryBytePatternSearcher {
|
||||||
* Call associated action for each pattern matched.
|
* Call associated action for each pattern matched.
|
||||||
*
|
*
|
||||||
* @param program to be searched
|
* @param program to be searched
|
||||||
* @param searchSet set of bytes to restrict search to
|
* @param searchSet set of bytes to restrict search, if null or empty then search all memory blocks
|
||||||
* @param monitor allow canceling and reporting of progress
|
* @param monitor allow canceling and reporting of progress
|
||||||
*
|
*
|
||||||
* @throws CancelledException if canceled
|
* @throws CancelledException if canceled
|
||||||
|
|
|
@ -716,43 +716,13 @@ public class FunctionStartAnalyzer extends AbstractAnalyzer implements PatternFa
|
||||||
*/
|
*/
|
||||||
private boolean checkForExecuteBlock(Program program) {
|
private boolean checkForExecuteBlock(Program program) {
|
||||||
MemoryBlock[] blocks = program.getMemory().getBlocks();
|
MemoryBlock[] blocks = program.getMemory().getBlocks();
|
||||||
boolean hasExecutable = false;
|
|
||||||
|
|
||||||
for (MemoryBlock block : blocks) {
|
for (MemoryBlock block : blocks) {
|
||||||
if (block.isExecute()) {
|
if (block.isExecute()) {
|
||||||
hasExecutable = true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hasExecutable;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get rid of any blocks from the address set that shouldn't be searched.
|
|
||||||
* Non-executable and non-initialized.
|
|
||||||
*
|
|
||||||
* @param program program
|
|
||||||
* @param bset current set of restricted address ranges
|
|
||||||
* @return return new set with blocks not to be searched removed
|
|
||||||
*/
|
|
||||||
private AddressSet removeNotSearchedAddresses(Program program, AddressSetView bset) {
|
|
||||||
AddressSet restrictedSet = new AddressSet(bset);
|
|
||||||
MemoryBlock[] blocks = program.getMemory().getBlocks();
|
|
||||||
boolean hasExecutable = checkForExecuteBlock(program);
|
|
||||||
|
|
||||||
for (MemoryBlock block : blocks) {
|
|
||||||
if (!block.isInitialized()) {
|
|
||||||
restrictedSet.deleteRange(block.getStart(), block.getEnd());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if
|
|
||||||
if (executableBlocksOnly && hasExecutable) {
|
|
||||||
if (!block.isExecute()) {
|
|
||||||
restrictedSet.deleteRange(block.getStart(), block.getEnd());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return restrictedSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.cmd.data.rtti;
|
package ghidra.app.cmd.data.rtti;
|
||||||
|
|
||||||
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getAbsoluteAddress;
|
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.*;
|
||||||
|
|
||||||
import ghidra.app.cmd.data.*;
|
import ghidra.app.cmd.data.*;
|
||||||
import ghidra.app.util.datatype.microsoft.DataApplyOptions;
|
import ghidra.app.util.datatype.microsoft.DataApplyOptions;
|
||||||
|
@ -172,9 +172,8 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
|
||||||
if (rtti0Model != null) {
|
if (rtti0Model != null) {
|
||||||
|
|
||||||
// Plate Comment
|
// Plate Comment
|
||||||
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
|
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
|
||||||
RttiUtil.CONST_PREFIX + RttiUtil.getDescriptorTypeNamespace(rtti0Model) +
|
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
|
||||||
Namespace.DELIMITER,
|
|
||||||
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
|
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
|
||||||
|
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
|
@ -188,7 +187,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
|
||||||
|
|
||||||
// Create functions that are referred to by the vf table.
|
// Create functions that are referred to by the vf table.
|
||||||
if (applyOptions.shouldCreateFunction()) {
|
if (applyOptions.shouldCreateFunction()) {
|
||||||
int elementCount = model.getElementCount();
|
int elementCount = model.getCount();
|
||||||
for (int tableElementIndex = 0; tableElementIndex < elementCount; tableElementIndex++) {
|
for (int tableElementIndex = 0; tableElementIndex < elementCount; tableElementIndex++) {
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
Address vfPointer = model.getVirtualFunctionPointer(tableElementIndex);
|
Address vfPointer = model.getVirtualFunctionPointer(tableElementIndex);
|
||||||
|
|
|
@ -40,7 +40,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
|
||||||
|
|
||||||
private DataType dataType;
|
private DataType dataType;
|
||||||
private Rtti4Model rtti4Model;
|
private Rtti4Model rtti4Model;
|
||||||
private int elementCount = -1;
|
|
||||||
|
|
||||||
private Program lastProgram;
|
private Program lastProgram;
|
||||||
private DataType lastDataType;
|
private DataType lastDataType;
|
||||||
|
@ -57,8 +56,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
|
||||||
DataValidationOptions validationOptions) {
|
DataValidationOptions validationOptions) {
|
||||||
super(program, RttiUtil.getVfTableCount(program, vfTableAddress), vfTableAddress,
|
super(program, RttiUtil.getVfTableCount(program, vfTableAddress), vfTableAddress,
|
||||||
validationOptions);
|
validationOptions);
|
||||||
// super's count will hold the number of valid address elements from getVfTableCount()
|
|
||||||
elementCount = getCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,7 +79,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
|
||||||
long entrySize = individualEntryDataType.getLength();
|
long entrySize = individualEntryDataType.getLength();
|
||||||
|
|
||||||
// Each entry is a pointer to where a function can possibly be created.
|
// Each entry is a pointer to where a function can possibly be created.
|
||||||
long numEntries = getElementCount();
|
long numEntries = getCount();
|
||||||
if (numEntries == 0) {
|
if (numEntries == 0) {
|
||||||
throw new InvalidDataTypeException(
|
throw new InvalidDataTypeException(
|
||||||
getName() + " data type at " + getAddress() + " doesn't have a valid vf table.");
|
getName() + " data type at " + getAddress() + " doesn't have a valid vf table.");
|
||||||
|
@ -125,7 +122,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
|
||||||
lastDataType = null;
|
lastDataType = null;
|
||||||
lastElementCount = -1;
|
lastElementCount = -1;
|
||||||
|
|
||||||
lastElementCount = getElementCount();
|
lastElementCount = getCount();
|
||||||
if (lastElementCount > 0) {
|
if (lastElementCount > 0) {
|
||||||
DataTypeManager dataTypeManager = program.getDataTypeManager();
|
DataTypeManager dataTypeManager = program.getDataTypeManager();
|
||||||
PointerDataType pointerDt = new PointerDataType(dataTypeManager);
|
PointerDataType pointerDt = new PointerDataType(dataTypeManager);
|
||||||
|
@ -170,17 +167,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
|
||||||
return getAbsoluteAddress(getProgram(), address);
|
return getAbsoluteAddress(getProgram(), address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of elements in the vf table. Returns 0 if this model isn't for a valid vf table.
|
|
||||||
* @return the number of vf table elements or 0.
|
|
||||||
*/
|
|
||||||
public int getElementCount() {
|
|
||||||
if (elementCount == -1) {
|
|
||||||
elementCount = RttiUtil.getVfTableCount(getProgram(), getAddress());
|
|
||||||
}
|
|
||||||
return elementCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type descriptor (RTTI 0) model associated with this vf table.
|
* Gets the type descriptor (RTTI 0) model associated with this vf table.
|
||||||
* @return the type descriptor (RTTI 0) model or null.
|
* @return the type descriptor (RTTI 0) model or null.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue