From edfff3a2675119ba70a41131b50f98c3c4105e1c Mon Sep 17 00:00:00 2001 From: emteere <47253321+emteere@users.noreply.github.com> Date: Tue, 18 Feb 2020 21:11:37 +0000 Subject: [PATCH] GT-3341_emteere_RTTIPerformance Code Review changes --- .../core/analysis/EmbeddedMediaAnalyzer.java | 8 +++-- .../bytesearch/MemoryBytePatternSearcher.java | 2 +- .../app/analyzers/FunctionStartAnalyzer.java | 34 ++----------------- .../data/rtti/CreateVfTableBackgroundCmd.java | 9 +++-- .../app/cmd/data/rtti/VfTableModel.java | 18 ++-------- 5 files changed, 15 insertions(+), 56 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/EmbeddedMediaAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/EmbeddedMediaAnalyzer.java index a49b3438a3..117e39f7ca 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/EmbeddedMediaAnalyzer.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/EmbeddedMediaAnalyzer.java @@ -22,7 +22,8 @@ import ghidra.app.cmd.data.CreateDataCmd; import ghidra.app.services.*; import ghidra.app.util.importer.MessageLog; 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.listing.BookmarkType; import ghidra.program.model.listing.Program; @@ -56,7 +57,10 @@ public class EmbeddedMediaAnalyzer extends AbstractAnalyzer { Memory memory = program.getMemory(); 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"); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/bytesearch/MemoryBytePatternSearcher.java b/Ghidra/Features/Base/src/main/java/ghidra/util/bytesearch/MemoryBytePatternSearcher.java index d65bece053..5249bc9c69 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/util/bytesearch/MemoryBytePatternSearcher.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/util/bytesearch/MemoryBytePatternSearcher.java @@ -94,7 +94,7 @@ public class MemoryBytePatternSearcher { * Call associated action for each pattern matched. * * @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 * * @throws CancelledException if canceled diff --git a/Ghidra/Features/BytePatterns/src/main/java/ghidra/app/analyzers/FunctionStartAnalyzer.java b/Ghidra/Features/BytePatterns/src/main/java/ghidra/app/analyzers/FunctionStartAnalyzer.java index 908293450b..81e44397fe 100644 --- a/Ghidra/Features/BytePatterns/src/main/java/ghidra/app/analyzers/FunctionStartAnalyzer.java +++ b/Ghidra/Features/BytePatterns/src/main/java/ghidra/app/analyzers/FunctionStartAnalyzer.java @@ -716,43 +716,13 @@ public class FunctionStartAnalyzer extends AbstractAnalyzer implements PatternFa */ private boolean checkForExecuteBlock(Program program) { MemoryBlock[] blocks = program.getMemory().getBlocks(); - boolean hasExecutable = false; for (MemoryBlock block : blocks) { if (block.isExecute()) { - hasExecutable = true; + return true; } } - return hasExecutable; - } - - /** - * 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; + return false; } @Override diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateVfTableBackgroundCmd.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateVfTableBackgroundCmd.java index 3408bfe8ae..7d4e5c1cc8 100644 --- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateVfTableBackgroundCmd.java +++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/CreateVfTableBackgroundCmd.java @@ -15,7 +15,7 @@ */ 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.util.datatype.microsoft.DataApplyOptions; @@ -172,9 +172,8 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd< if (rtti0Model != null) { // Plate Comment - EHDataTypeUtilities.createPlateCommentIfNeeded(program, - RttiUtil.CONST_PREFIX + RttiUtil.getDescriptorTypeNamespace(rtti0Model) + - Namespace.DELIMITER, + EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX + + RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER, VF_TABLE_LABEL, null, vfTableAddress, applyOptions); monitor.checkCanceled(); @@ -188,7 +187,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd< // Create functions that are referred to by the vf table. if (applyOptions.shouldCreateFunction()) { - int elementCount = model.getElementCount(); + int elementCount = model.getCount(); for (int tableElementIndex = 0; tableElementIndex < elementCount; tableElementIndex++) { monitor.checkCanceled(); Address vfPointer = model.getVirtualFunctionPointer(tableElementIndex); diff --git a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/VfTableModel.java b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/VfTableModel.java index fb0975ec9f..844933af14 100644 --- a/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/VfTableModel.java +++ b/Ghidra/Features/MicrosoftCodeAnalyzer/src/main/java/ghidra/app/cmd/data/rtti/VfTableModel.java @@ -40,7 +40,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel { private DataType dataType; private Rtti4Model rtti4Model; - private int elementCount = -1; private Program lastProgram; private DataType lastDataType; @@ -57,8 +56,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel { DataValidationOptions validationOptions) { super(program, RttiUtil.getVfTableCount(program, vfTableAddress), vfTableAddress, validationOptions); - // super's count will hold the number of valid address elements from getVfTableCount() - elementCount = getCount(); } @Override @@ -82,7 +79,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel { long entrySize = individualEntryDataType.getLength(); // Each entry is a pointer to where a function can possibly be created. - long numEntries = getElementCount(); + long numEntries = getCount(); if (numEntries == 0) { throw new InvalidDataTypeException( getName() + " data type at " + getAddress() + " doesn't have a valid vf table."); @@ -125,7 +122,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel { lastDataType = null; lastElementCount = -1; - lastElementCount = getElementCount(); + lastElementCount = getCount(); if (lastElementCount > 0) { DataTypeManager dataTypeManager = program.getDataTypeManager(); PointerDataType pointerDt = new PointerDataType(dataTypeManager); @@ -170,17 +167,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel { 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. * @return the type descriptor (RTTI 0) model or null.