From 1df49afa5522d73d509d20db9588294fe259085f Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Thu, 11 Jan 2018 17:10:34 -0500 Subject: API Temporary Object Elimination. --- binaryview.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index 50011a0f..00cd294f 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -82,10 +82,7 @@ void BinaryDataNotification::DataVariableAddedCallback(void* ctxt, BNBinaryView* { BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; Ref view = new BinaryView(BNNewViewReference(object)); - DataVariable varObj; - varObj.address = var->address; - varObj.type = Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence); - varObj.autoDiscovered = var->autoDiscovered; + DataVariable varObj(var->address, Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered); notify->OnDataVariableAdded(view, varObj); } @@ -94,10 +91,7 @@ void BinaryDataNotification::DataVariableRemovedCallback(void* ctxt, BNBinaryVie { BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; Ref view = new BinaryView(BNNewViewReference(object)); - DataVariable varObj; - varObj.address = var->address; - varObj.type = Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence); - varObj.autoDiscovered = var->autoDiscovered; + DataVariable varObj(var->address, Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered); notify->OnDataVariableRemoved(view, varObj); } @@ -106,10 +100,7 @@ void BinaryDataNotification::DataVariableUpdatedCallback(void* ctxt, BNBinaryVie { BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; Ref view = new BinaryView(BNNewViewReference(object)); - DataVariable varObj; - varObj.address = var->address; - varObj.type = Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence); - varObj.autoDiscovered = var->autoDiscovered; + DataVariable varObj(var->address, Confidence>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered); notify->OnDataVariableUpdated(view, varObj); } @@ -965,11 +956,8 @@ map BinaryView::GetDataVariables() map result; for (size_t i = 0; i < count; i++) { - DataVariable var; - var.address = vars[i].address; - var.type = Confidence>(new Type(BNNewTypeReference(vars[i].type)), vars[i].typeConfidence); - var.autoDiscovered = vars[i].autoDiscovered; - result[var.address] = var; + result.emplace(piecewise_construct, forward_as_tuple(vars[i].address), + forward_as_tuple(vars[i].address, Confidence>(new Type(BNNewTypeReference(vars[i].type)), vars[i].typeConfidence), vars[i].autoDiscovered)); } BNFreeDataVariables(vars, count); -- cgit v1.3.1 From 0cc77206c79257d49013c3a3ed1bf889c85b10d1 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Sun, 14 Jan 2018 03:42:04 -0500 Subject: Container Memory Reservations. --- architecture.cpp | 11 +++++++++++ backgroundtask.cpp | 1 + basicblock.cpp | 4 ++++ binaryview.cpp | 20 ++++++++++++++++++++ binaryviewtype.cpp | 2 ++ function.cpp | 11 +++++++++-- functiongraph.cpp | 2 ++ functiongraphblock.cpp | 3 +++ lowlevelil.cpp | 8 ++++---- lowlevelilinstruction.cpp | 7 ++++--- mediumlevelil.cpp | 9 +++++---- mediumlevelilinstruction.cpp | 6 +++--- metadata.cpp | 1 + platform.cpp | 6 ++++++ plugin.cpp | 1 + settings.cpp | 1 + transform.cpp | 2 ++ type.cpp | 12 ++++++------ update.cpp | 2 ++ 19 files changed, 87 insertions(+), 22 deletions(-) (limited to 'binaryview.cpp') diff --git a/architecture.cpp b/architecture.cpp index 821f4c7b..7b74e43b 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -507,6 +507,7 @@ vector> Architecture::GetList() archs = BNGetArchitectureList(&count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreArchitecture(archs[i])); @@ -703,6 +704,7 @@ vector Architecture::GetModifiedRegistersOnWrite(uint32_t reg) uint32_t* regs = BNGetModifiedArchitectureRegistersOnWrite(m_object, reg, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); @@ -814,6 +816,7 @@ vector> Architecture::GetCallingConventions() BNCallingConvention** list = BNGetArchitectureCallingConventions(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreCallingConvention(BNNewCallingConventionReference(list[i]))); @@ -957,6 +960,7 @@ bool CoreArchitecture::GetInstructionText(const uint8_t* data, uint64_t addr, si if (!BNGetInstructionText(m_object, data, addr, &len, &tokens, &count)) return false; + result.reserve(count); for (size_t i = 0; i < count; i++) { result.emplace_back(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address, @@ -1007,6 +1011,7 @@ vector CoreArchitecture::GetFullWidthRegisters() uint32_t* regs = BNGetFullWidthArchitectureRegisters(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); @@ -1021,6 +1026,7 @@ vector CoreArchitecture::GetAllRegisters() uint32_t* regs = BNGetAllArchitectureRegisters(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); @@ -1035,6 +1041,7 @@ vector CoreArchitecture::GetAllFlags() uint32_t* regs = BNGetAllArchitectureFlags(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); @@ -1049,6 +1056,7 @@ vector CoreArchitecture::GetAllFlagWriteTypes() uint32_t* regs = BNGetAllArchitectureFlagWriteTypes(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); @@ -1069,6 +1077,7 @@ vector CoreArchitecture::GetFlagsRequiredForFlagCondition(BNLowLevelIL uint32_t* flags = BNGetArchitectureFlagsRequiredForFlagCondition(m_object, cond, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(flags[i]); @@ -1083,6 +1092,7 @@ vector CoreArchitecture::GetFlagsWrittenByFlagWriteType(uint32_t write uint32_t* flags = BNGetArchitectureFlagsWrittenByFlagWriteType(m_object, writeType, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(flags[i]); @@ -1129,6 +1139,7 @@ vector CoreArchitecture::GetGlobalRegisters() uint32_t* regs = BNGetArchitectureGlobalRegisters(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(regs[i]); diff --git a/backgroundtask.cpp b/backgroundtask.cpp index aebf980c..b2d4a738 100644 --- a/backgroundtask.cpp +++ b/backgroundtask.cpp @@ -67,6 +67,7 @@ vector> BackgroundTask::GetRunningTasks() BNBackgroundTask** tasks = BNGetRunningBackgroundTasks(&count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BackgroundTask(BNNewBackgroundTaskReference(tasks[i]))); diff --git a/basicblock.cpp b/basicblock.cpp index 89ace134..d42a1038 100644 --- a/basicblock.cpp +++ b/basicblock.cpp @@ -120,6 +120,7 @@ vector BasicBlock::GetOutgoingEdges() const BNBasicBlockEdge* array = BNGetBasicBlockOutgoingEdges(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { BasicBlockEdge edge; @@ -140,6 +141,7 @@ vector BasicBlock::GetIncomingEdges() const BNBasicBlockEdge* array = BNGetBasicBlockIncomingEdges(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { BasicBlockEdge edge; @@ -269,10 +271,12 @@ vector BasicBlock::GetDisassemblyText(DisassemblySettings* BNDisassemblyTextLine* lines = BNGetBasicBlockDisassemblyText(m_object, settings->GetObject(), &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { DisassemblyTextLine line; line.addr = lines[i].addr; + line.tokens.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; diff --git a/binaryview.cpp b/binaryview.cpp index 00cd294f..0ee428e1 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -670,6 +670,7 @@ vector BinaryView::GetModification(uint64_t offset, size_t len = BNGetModificationArray(m_object, offset, mod, len); vector result; + result.reserve(len); for (size_t i = 0; i < len; i++) result.push_back(mod[i]); @@ -988,6 +989,7 @@ vector> BinaryView::GetAnalysisFunctionList() BNFunction** list = BNGetAnalysisFunctionList(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Function(BNNewFunctionReference(list[i]))); @@ -1026,6 +1028,7 @@ vector> BinaryView::GetAnalysisFunctionsForAddress(uint64_t addr) BNFunction** list = BNGetAnalysisFunctionsForAddress(m_object, addr, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Function(BNNewFunctionReference(list[i]))); @@ -1058,6 +1061,7 @@ vector> BinaryView::GetBasicBlocksForAddress(uint64_t addr) BNBasicBlock** blocks = BNGetBasicBlocksForAddress(m_object, addr, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); @@ -1072,6 +1076,7 @@ vector> BinaryView::GetBasicBlocksStartingAtAddress(uint64_t add BNBasicBlock** blocks = BNGetBasicBlocksStartingAtAddress(m_object, addr, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); @@ -1086,6 +1091,7 @@ vector BinaryView::GetCodeReferences(uint64_t addr) BNReferenceSource* refs = BNGetCodeReferences(m_object, addr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { ReferenceSource src; @@ -1106,6 +1112,7 @@ vector BinaryView::GetCodeReferences(uint64_t addr, uint64_t le BNReferenceSource* refs = BNGetCodeReferencesInRange(m_object, addr, len, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { ReferenceSource src; @@ -1144,6 +1151,7 @@ vector> BinaryView::GetSymbolsByName(const string& name) BNSymbol** syms = BNGetSymbolsByName(m_object, name.c_str(), &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Symbol(BNNewSymbolReference(syms[i]))); @@ -1158,6 +1166,7 @@ vector> BinaryView::GetSymbols() BNSymbol** syms = BNGetSymbols(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Symbol(BNNewSymbolReference(syms[i]))); @@ -1172,6 +1181,7 @@ vector> BinaryView::GetSymbols(uint64_t start, uint64_t len) BNSymbol** syms = BNGetSymbolsInRange(m_object, start, len, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Symbol(BNNewSymbolReference(syms[i]))); @@ -1186,6 +1196,7 @@ vector> BinaryView::GetSymbolsOfType(BNSymbolType type) BNSymbol** syms = BNGetSymbolsOfType(m_object, type, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Symbol(BNNewSymbolReference(syms[i]))); @@ -1200,6 +1211,7 @@ vector> BinaryView::GetSymbolsOfType(BNSymbolType type, uint64_t sta BNSymbol** syms = BNGetSymbolsOfTypeInRange(m_object, type, start, len, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Symbol(BNNewSymbolReference(syms[i]))); @@ -1412,6 +1424,7 @@ vector BinaryView::GetPreviousLinearDisassemblyLines(Line settings ? settings->GetObject() : nullptr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { LinearDisassemblyLine line; @@ -1420,6 +1433,7 @@ vector BinaryView::GetPreviousLinearDisassemblyLines(Line line.block = lines[i].block ? new BasicBlock(BNNewBasicBlockReference(lines[i].block)) : nullptr; line.lineOffset = lines[i].lineOffset; line.contents.addr = lines[i].contents.addr; + line.contents.tokens.reserve(lines[i].contents.count); for (size_t j = 0; j < lines[i].contents.count; j++) { InstructionTextToken token; @@ -1458,6 +1472,7 @@ vector BinaryView::GetNextLinearDisassemblyLines(LinearDi settings ? settings->GetObject() : nullptr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { LinearDisassemblyLine line; @@ -1466,6 +1481,7 @@ vector BinaryView::GetNextLinearDisassemblyLines(LinearDi line.block = lines[i].block ? new BasicBlock(BNNewBasicBlockReference(lines[i].block)) : nullptr; line.lineOffset = lines[i].lineOffset; line.contents.addr = lines[i].contents.addr; + line.contents.tokens.reserve(lines[i].contents.count); for (size_t j = 0; j < lines[i].contents.count; j++) { InstructionTextToken token; @@ -1704,6 +1720,7 @@ vector BinaryView::GetSegments() BNSegment* segments = BNGetSegments(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { Segment segment; @@ -1777,6 +1794,7 @@ vector
BinaryView::GetSections() BNSection* sections = BNGetSections(m_object, &count); vector
result; + result.reserve(count); for (size_t i = 0; i < count; i++) { Section section; @@ -1804,6 +1822,7 @@ vector
BinaryView::GetSectionsAt(uint64_t addr) BNSection* sections = BNGetSectionsAt(m_object, addr, &count); vector
result; + result.reserve(count); for (size_t i = 0; i < count; i++) { Section section; @@ -1855,6 +1874,7 @@ vector BinaryView::GetUniqueSectionNames(const vector& names) char** outgoingNames = BNGetUniqueSectionNames(m_object, incomingNames, names.size()); vector result; + result.reserve(names.size()); for (size_t i = 0; i < names.size(); i++) result.push_back(outgoingNames[i]); diff --git a/binaryviewtype.cpp b/binaryviewtype.cpp index e23838f6..e8ef4f53 100644 --- a/binaryviewtype.cpp +++ b/binaryviewtype.cpp @@ -83,6 +83,7 @@ vector> BinaryViewType::GetViewTypes() types = BNGetBinaryViewTypes(&count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreBinaryViewType(types[i])); @@ -98,6 +99,7 @@ vector> BinaryViewType::GetViewTypesForData(BinaryView* data types = BNGetBinaryViewTypesForData(data->GetObject(), &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreBinaryViewType(types[i])); diff --git a/function.cpp b/function.cpp index 1226e399..cb4377b2 100644 --- a/function.cpp +++ b/function.cpp @@ -174,6 +174,7 @@ vector> Function::GetBasicBlocks() const BNBasicBlock** blocks = BNGetFunctionBasicBlockList(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); @@ -379,6 +380,7 @@ vector Function::GetStackVariablesReferencedByInstructio BNStackVariableReference* refs = BNGetStackVariablesReferencedByInstruction(m_object, arch->GetObject(), addr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { StackVariableReference ref; @@ -502,10 +504,9 @@ Confidence> Function::GetParameterVariables() const { BNParameterVariablesWithConfidence vars = BNGetFunctionParameterVariables(m_object); vector varList; + varList.reserve(vars.count); for (size_t i = 0; i < vars.count; i++) - { varList.emplace_back(vars.vars[i].type, vars.vars[i].index, vars.vars[i].storage); - } Confidence> result(varList, vars.confidence); BNFreeParameterVariables(&vars); return result; @@ -897,6 +898,7 @@ vector Function::GetIndirectBranches() BNIndirectBranchInfo* branches = BNGetIndirectBranches(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { IndirectBranchInfo b; @@ -919,6 +921,7 @@ vector Function::GetIndirectBranchesAt(Architecture* arch, u BNIndirectBranchInfo* branches = BNGetIndirectBranchesAt(m_object, arch->GetObject(), addr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { IndirectBranchInfo b; @@ -941,9 +944,11 @@ vector> Function::GetBlockAnnotations(Architecture* BNInstructionTextLine* lines = BNGetFunctionBlockAnnotations(m_object, arch->GetObject(), addr, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { vector line; + line.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; @@ -1155,10 +1160,12 @@ vector Function::GetTypeTokens(DisassemblySettings* setting settings ? settings->GetObject() : nullptr, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { DisassemblyTextLine line; line.addr = lines[i].addr; + line.tokens.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; diff --git a/functiongraph.cpp b/functiongraph.cpp index 7e5ec079..77754913 100644 --- a/functiongraph.cpp +++ b/functiongraph.cpp @@ -110,6 +110,7 @@ vector> FunctionGraph::GetBlocks() BNFunctionGraphBlock** blocks = BNGetFunctionGraphBlocks(m_graph, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { auto block = m_cachedBlocks.find(blocks[i]); @@ -148,6 +149,7 @@ vector> FunctionGraph::GetBlocksInRegion(int left, int t BNFunctionGraphBlock** blocks = BNGetFunctionGraphBlocksInRegion(m_graph, left, top, right, bottom, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { auto block = m_cachedBlocks.find(blocks[i]); diff --git a/functiongraphblock.cpp b/functiongraphblock.cpp index 20b2515b..06a35eee 100644 --- a/functiongraphblock.cpp +++ b/functiongraphblock.cpp @@ -89,10 +89,12 @@ const vector& FunctionGraphBlock::GetLines() BNDisassemblyTextLine* lines = BNGetFunctionGraphBlockLines(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { DisassemblyTextLine line; line.addr = lines[i].addr; + line.tokens.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; @@ -125,6 +127,7 @@ const vector& FunctionGraphBlock::GetOutgoingEdges() BNFunctionGraphEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { FunctionGraphEdge edge; diff --git a/lowlevelil.cpp b/lowlevelil.cpp index 6c59b704..5e985a8e 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -176,6 +176,7 @@ vector LowLevelILFunction::GetOperandList(ExprId expr, size_t listOper size_t count; uint64_t* operands = BNLowLevelILGetOperandList(m_object, expr, listOperand, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(operands[i]); BNLowLevelILFreeOperandList(operands); @@ -390,11 +391,10 @@ bool LowLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector> LowLevelILFunction::GetBasicBlocks() const BNBasicBlock** blocks = BNGetLowLevelILBasicBlockList(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index d85e4f17..53b1e390 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -178,15 +178,16 @@ unordered_map> }; -static unordered_map> - GetOperandIndexForOperandUsages() +static unordered_map> GetOperandIndexForOperandUsages() { unordered_map> result; + result.reserve(LowLevelILInstructionBase::operationOperandUsage.size()); for (auto& operation : LowLevelILInstructionBase::operationOperandUsage) { result[operation.first] = unordered_map(); size_t operand = 0; + result[operation.first].reserve(operation.second.size()); for (auto usage : operation.second) { result[operation.first][usage] = operand; @@ -377,7 +378,7 @@ uint64_t LowLevelILIntegerList::ListIterator::operator*() LowLevelILIntegerList::LowLevelILIntegerList(LowLevelILFunction* func, - const BNLowLevelILInstruction& instr, size_t count) +const BNLowLevelILInstruction& instr, size_t count) { m_start.function = func; #ifdef BINARYNINJACORE_LIBRARY diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp index 2cd5a233..0a28bd49 100644 --- a/mediumlevelil.cpp +++ b/mediumlevelil.cpp @@ -157,6 +157,7 @@ vector MediumLevelILFunction::GetOperandList(ExprId expr, size_t listO size_t count; uint64_t* operands = BNMediumLevelILGetOperandList(m_object, expr, listOperand, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(operands[i]); BNMediumLevelILFreeOperandList(operands); @@ -338,11 +339,10 @@ bool MediumLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector< return false; tokens.clear(); + tokens.reserve(count); for (size_t i = 0; i < count; i++) - { tokens.emplace_back(list[i].type, list[i].context, list[i].text, list[i].address, list[i].value, list[i].size, list[i].operand, list[i].confidence); - } BNFreeInstructionText(list, count); return true; @@ -359,11 +359,10 @@ bool MediumLevelILFunction::GetInstructionText(Function* func, Architecture* arc return false; tokens.clear(); + tokens.reserve(count); for (size_t i = 0; i < count; i++) - { tokens.emplace_back(list[i].type, list[i].context, list[i].text, list[i].address, list[i].value, list[i].size, list[i].operand, list[i].confidence); - } BNFreeInstructionText(list, count); return true; @@ -396,6 +395,7 @@ vector> MediumLevelILFunction::GetBasicBlocks() const BNBasicBlock** blocks = BNGetMediumLevelILBasicBlockList(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); @@ -680,6 +680,7 @@ unordered_map MediumLevelILFunction::GetAllBranchD BNILBranchInstructionAndDependence* deps = BNGetAllMediumLevelILBranchDependence(m_object, instr, &count); unordered_map result; + result.reserve(count); for (size_t i = 0; i < count; i++) result[deps[i].branch] = deps[i].dependence; diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index ec6aa1c6..bb4d205a 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -205,14 +205,14 @@ unordered_map> }; -static unordered_map> - GetOperandIndexForOperandUsages() +static unordered_map> GetOperandIndexForOperandUsages() { unordered_map> result; + result.reserve(MediumLevelILInstructionBase::operationOperandUsage.size()); for (auto& operation : MediumLevelILInstructionBase::operationOperandUsage) { result[operation.first] = unordered_map(); - + result[operation.first].reserve(operation.second.size()); size_t operand = 0; for (auto usage : operation.second) { diff --git a/metadata.cpp b/metadata.cpp index f9c48b04..c111233f 100644 --- a/metadata.cpp +++ b/metadata.cpp @@ -144,6 +144,7 @@ vector> Metadata::GetArray() size_t size = 0; BNMetadata** data = BNMetadataGetArray(m_object, &size); vector> result; + result.reserve(size); for (size_t i = 0; i < size; i++) result.push_back(new Metadata(data[i])); return result; diff --git a/platform.cpp b/platform.cpp index a9ab888f..724901fe 100644 --- a/platform.cpp +++ b/platform.cpp @@ -72,6 +72,7 @@ vector> Platform::GetList() BNPlatform** list = BNGetPlatformList(&count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Platform(BNNewPlatformReference(list[i]))); @@ -86,6 +87,7 @@ vector> Platform::GetList(Architecture* arch) BNPlatform** list = BNGetPlatformListByArchitecture(arch->GetObject(), &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Platform(BNNewPlatformReference(list[i]))); @@ -100,6 +102,7 @@ vector> Platform::GetList(const string& os) BNPlatform** list = BNGetPlatformListByOS(os.c_str(), &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Platform(BNNewPlatformReference(list[i]))); @@ -114,6 +117,7 @@ vector> Platform::GetList(const string& os, Architecture* arch) BNPlatform** list = BNGetPlatformListByOSAndArchitecture(os.c_str(), arch->GetObject(), &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new Platform(BNNewPlatformReference(list[i]))); @@ -128,6 +132,7 @@ vector Platform::GetOSList() char** list = BNGetPlatformOSList(&count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(list[i]); @@ -178,6 +183,7 @@ vector> Platform::GetCallingConventions() const BNCallingConvention** list = BNGetPlatformCallingConventions(m_object, &count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreCallingConvention(BNNewCallingConventionReference(list[i]))); diff --git a/plugin.cpp b/plugin.cpp index 2378fdab..972ce28b 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -211,6 +211,7 @@ vector PluginCommand::GetList() vector result; size_t count; BNPluginCommand* commands = BNGetAllPluginCommands(&count); + result.reserve(count); for (size_t i = 0; i < count; i++) result.emplace_back(commands[i]); BNFreePluginCommandList(commands); diff --git a/settings.cpp b/settings.cpp index 6b9c4e3a..b5899e38 100644 --- a/settings.cpp +++ b/settings.cpp @@ -51,6 +51,7 @@ std::vector Setting::GetStringList(const std::string& pluginName, char** outBuffer = (char**)BNSettingGetStringList(pluginName.c_str(), name.c_str(), (const char**)buffer, &size); vector result; + result.reserve(size); for (size_t i = 0; i < size; i++) result.emplace_back(outBuffer[i]); diff --git a/transform.cpp b/transform.cpp index 29a665d0..0a6fdfe6 100644 --- a/transform.cpp +++ b/transform.cpp @@ -157,6 +157,7 @@ vector> Transform::GetTransformTypes() BNTransform** list = BNGetTransformTypeList(&count); vector> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new CoreTransform(list[i])); @@ -229,6 +230,7 @@ vector CoreTransform::GetParameters() const BNTransformParameterInfo* list = BNGetTransformParameterList(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { TransformParameter param; diff --git a/type.cpp b/type.cpp index c158f53e..08b64713 100644 --- a/type.cpp +++ b/type.cpp @@ -355,6 +355,7 @@ vector Type::GetParameters() const BNFunctionParameter* types = BNGetTypeParameters(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { FunctionParameter param; @@ -474,11 +475,10 @@ vector Type::GetTokens(Platform* platform, uint8_t baseCon platform ? platform->GetObject() : nullptr, baseConfidence, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) - { result.emplace_back(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address, tokens[i].value, tokens[i].size, tokens[i].operand, tokens[i].confidence); - } BNFreeTokenList(tokens, count); return result; @@ -492,11 +492,10 @@ vector Type::GetTokensBeforeName(Platform* platform, uint8 platform ? platform->GetObject() : nullptr, baseConfidence, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) - { result.emplace_back(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address, tokens[i].value, tokens[i].size, tokens[i].operand, tokens[i].confidence); - } BNFreeTokenList(tokens, count); return result; @@ -510,11 +509,10 @@ vector Type::GetTokensAfterName(Platform* platform, uint8_ platform ? platform->GetObject() : nullptr, baseConfidence, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) - { result.emplace_back(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address, tokens[i].value, tokens[i].size, tokens[i].operand, tokens[i].confidence); - } BNFreeTokenList(tokens, count); return result; @@ -882,6 +880,7 @@ vector Structure::GetMembers() const BNStructureMember* members = BNGetStructureMembers(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { StructureMember member; @@ -1001,6 +1000,7 @@ vector Enumeration::GetMembers() const BNEnumerationMember* members = BNGetEnumerationMembers(m_object, &count); vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { EnumerationMember member; diff --git a/update.cpp b/update.cpp index 0ec69892..ecdf4162 100644 --- a/update.cpp +++ b/update.cpp @@ -53,6 +53,7 @@ vector UpdateChannel::GetList() } vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { UpdateChannel channel; @@ -149,6 +150,7 @@ vector UpdateVersion::GetChannelVersions(const string& channel) } vector result; + result.reserve(count); for (size_t i = 0; i < count; i++) { UpdateVersion version; -- cgit v1.3.1 From 80a5b6d9bca0b0ef4d2a7d33b632d558d6d9b0f0 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 22 Jan 2018 23:57:00 -0500 Subject: Add Access to Background Analysis Task. --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 1 + binaryview.cpp | 10 ++++++++++ 3 files changed, 13 insertions(+) (limited to 'binaryview.cpp') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index d357e5bc..d1b6f5f5 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -486,6 +486,7 @@ namespace BinaryNinja }; class Architecture; + class BackgroundTask; class Platform; class Type; class DataBuffer; @@ -1266,6 +1267,7 @@ namespace BinaryNinja Ref AddAnalysisCompletionEvent(const std::function& callback); BNAnalysisProgress GetAnalysisProgress(); + Ref GetBackgroundAnalysisTask(); uint64_t GetNextFunctionStartAfterAddress(uint64_t addr); uint64_t GetNextBasicBlockStartAfterAddress(uint64_t addr); diff --git a/binaryninjacore.h b/binaryninjacore.h index 245e6353..e9ef7c7a 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2232,6 +2232,7 @@ extern "C" BINARYNINJACOREAPI void BNCancelAnalysisCompletionEvent(BNAnalysisCompletionEvent* event); BINARYNINJACOREAPI BNAnalysisProgress BNGetAnalysisProgress(BNBinaryView* view); + BINARYNINJACOREAPI BNBackgroundTask* BNGetBackgroundAnalysisTask(BNBinaryView* view); BINARYNINJACOREAPI uint64_t BNGetNextFunctionStartAfterAddress(BNBinaryView* view, uint64_t addr); BINARYNINJACOREAPI uint64_t BNGetNextBasicBlockStartAfterAddress(BNBinaryView* view, uint64_t addr); diff --git a/binaryview.cpp b/binaryview.cpp index 0ee428e1..96fd161d 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1351,6 +1351,16 @@ BNAnalysisProgress BinaryView::GetAnalysisProgress() } +Ref BinaryView::GetBackgroundAnalysisTask() +{ + BNBackgroundTask* task = BNGetBackgroundAnalysisTask(m_object); + if (!task) + return nullptr; + + return new BackgroundTask(BNNewBackgroundTaskReference(task)); +} + + uint64_t BinaryView::GetNextFunctionStartAfterAddress(uint64_t addr) { return BNGetNextFunctionStartAfterAddress(m_object, addr); -- cgit v1.3.1