From bc779f1e0140a933d65926b9af840a80636a6dd4 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 11 Jan 2018 13:52:12 -0500 Subject: get_valid_list is now a dict, as well as add documentation for plugin registration functions --- python/plugin.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/python/plugin.py b/python/plugin.py index f038d122..e0054d86 100644 --- a/python/plugin.py +++ b/python/plugin.py @@ -168,6 +168,17 @@ class PluginCommand(object): @classmethod def register(cls, name, description, action, is_valid = None): + """ + ``register`` Register a plugin + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` as an argument + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_action(view, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_is_valid(view, is_valid)) @@ -176,6 +187,17 @@ class PluginCommand(object): @classmethod def register_for_address(cls, name, description, action, is_valid = None): + """ + ``register_for_address`` Register a plugin to be called with an address argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and address as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_address`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_action(view, addr, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_is_valid(view, addr, is_valid)) @@ -184,6 +206,17 @@ class PluginCommand(object): @classmethod def register_for_range(cls, name, description, action, is_valid = None): + """ + ``register_for_range`` Register a plugin to be called with a range argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and ``AddressRange`` as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_range`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_action(view, addr, length, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_is_valid(view, addr, length, is_valid)) @@ -192,6 +225,17 @@ class PluginCommand(object): @classmethod def register_for_function(cls, name, description, action, is_valid = None): + """ + ``register_for_function`` Register a plugin to be called with a function argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and a ``Function`` as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_function`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_action(view, func, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_is_valid(view, func, is_valid)) @@ -200,11 +244,12 @@ class PluginCommand(object): @classmethod def get_valid_list(cls, context): + """Dict of registered plugins""" commands = cls.list - result = [] + result = {} for cmd in commands: if cmd.is_valid(context): - result.append(cmd) + result[cmd.name] = cmd return result def is_valid(self, context): -- cgit v1.3.1 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. --- architecture.cpp | 4 ++-- binaryninjaapi.h | 4 ++++ binaryview.cpp | 22 +++++----------------- function.cpp | 49 ++++++++++++++++++++++++------------------------- lowlevelil.cpp | 24 ++++-------------------- mediumlevelil.cpp | 24 ++++-------------------- plugin.cpp | 2 +- settings.cpp | 4 ++-- type.cpp | 36 ++++++------------------------------ 9 files changed, 52 insertions(+), 117 deletions(-) diff --git a/architecture.cpp b/architecture.cpp index 66372bcb..821f4c7b 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -959,8 +959,8 @@ bool CoreArchitecture::GetInstructionText(const uint8_t* data, uint64_t addr, si for (size_t i = 0; i < count; i++) { - result.push_back(InstructionTextToken(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address, - tokens[i].value, tokens[i].size, tokens[i].operand, tokens[i].confidence)); + 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); } BNFreeInstructionText(tokens, count); diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 72f74c5a..31bd2316 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1017,6 +1017,9 @@ namespace BinaryNinja struct DataVariable { + DataVariable() { } + DataVariable(uint64_t a, Type* t, bool d) : address(a), type(t), autoDiscovered(d) { } + uint64_t address; Confidence> type; bool autoDiscovered; @@ -1832,6 +1835,7 @@ namespace BinaryNinja { Variable(); Variable(BNVariableSourceType type, uint32_t index, uint64_t storage); + Variable(BNVariableSourceType type, uint64_t storage); Variable(const BNVariable& var); Variable& operator=(const Variable& var); 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); diff --git a/function.cpp b/function.cpp index 2d8db04c..1226e399 100644 --- a/function.cpp +++ b/function.cpp @@ -504,11 +504,7 @@ Confidence> Function::GetParameterVariables() const vector varList; for (size_t i = 0; i < vars.count; i++) { - Variable var; - var.type = vars.vars[i].type; - var.index = vars.vars[i].index; - var.storage = vars.vars[i].storage; - varList.push_back(var); + varList.emplace_back(vars.vars[i].type, vars.vars[i].index, vars.vars[i].storage); } Confidence> result(varList, vars.confidence); BNFreeParameterVariables(&vars); @@ -569,13 +565,14 @@ void Function::SetAutoCallingConvention(const Confidence> void Function::SetAutoParameterVariables(const Confidence>& vars) { BNParameterVariablesWithConfidence varConf; - varConf.vars = new BNVariable[vars.GetValue().size()]; - varConf.count = vars.GetValue().size(); - for (size_t i = 0; i < vars.GetValue().size(); i++) + varConf.vars = new BNVariable[vars->size()]; + varConf.count = vars->size(); + size_t i = 0; + for (auto it = vars->begin(); it != vars->end(); ++it, ++i) { - varConf.vars[i].type = vars.GetValue()[i].type; - varConf.vars[i].index = vars.GetValue()[i].index; - varConf.vars[i].storage = vars.GetValue()[i].storage; + varConf.vars[i].type = it->type; + varConf.vars[i].index = it->index; + varConf.vars[i].storage = it->storage; } varConf.confidence = vars.GetConfidence(); @@ -614,11 +611,12 @@ void Function::SetAutoStackAdjustment(const Confidence& stackAdjust) void Function::SetAutoClobberedRegisters(const Confidence>& clobbered) { BNRegisterSetWithConfidence regs; - regs.regs = new uint32_t[clobbered.GetValue().size()]; - regs.count = clobbered.GetValue().size(); + regs.regs = new uint32_t[clobbered->size()]; + regs.count = clobbered->size(); + size_t i = 0; - for (auto reg : clobbered.GetValue()) - regs.regs[i++] = reg; + for (auto it = clobbered->begin(); it != clobbered->end(); ++it, ++i) + regs.regs[i] = *it; regs.confidence = clobbered.GetConfidence(); BNSetAutoFunctionClobberedRegisters(m_object, ®s); delete[] regs.regs; @@ -652,13 +650,14 @@ void Function::SetCallingConvention(const Confidence>& co void Function::SetParameterVariables(const Confidence>& vars) { BNParameterVariablesWithConfidence varConf; - varConf.vars = new BNVariable[vars.GetValue().size()]; - varConf.count = vars.GetValue().size(); - for (size_t i = 0; i < vars.GetValue().size(); i++) + varConf.vars = new BNVariable[vars->size()]; + varConf.count = vars->size(); + size_t i = 0; + for (auto it = vars->begin(); it != vars->end(); ++it, ++i) { - varConf.vars[i].type = vars.GetValue()[i].type; - varConf.vars[i].index = vars.GetValue()[i].index; - varConf.vars[i].storage = vars.GetValue()[i].storage; + varConf.vars[i].type = it->type; + varConf.vars[i].index = it->index; + varConf.vars[i].storage = it->storage; } varConf.confidence = vars.GetConfidence(); @@ -697,11 +696,11 @@ void Function::SetStackAdjustment(const Confidence& stackAdjust) void Function::SetClobberedRegisters(const Confidence>& clobbered) { BNRegisterSetWithConfidence regs; - regs.regs = new uint32_t[clobbered.GetValue().size()]; - regs.count = clobbered.GetValue().size(); + regs.regs = new uint32_t[clobbered->size()]; + regs.count = clobbered->size(); size_t i = 0; - for (auto reg : clobbered.GetValue()) - regs.regs[i++] = reg; + for (auto it = clobbered->begin(); it != clobbered->end(); ++it, ++i) + regs.regs[i] = *it; regs.confidence = clobbered.GetConfidence(); BNSetUserFunctionClobberedRegisters(m_object, ®s); delete[] regs.regs; diff --git a/lowlevelil.cpp b/lowlevelil.cpp index 690f0b41..6c59b704 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -392,16 +392,8 @@ bool LowLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector PluginCommand::GetList() size_t count; BNPluginCommand* commands = BNGetAllPluginCommands(&count); for (size_t i = 0; i < count; i++) - result.push_back(PluginCommand(commands[i])); + result.emplace_back(commands[i]); BNFreePluginCommandList(commands); return result; } diff --git a/settings.cpp b/settings.cpp index 328cf0e3..6b9c4e3a 100644 --- a/settings.cpp +++ b/settings.cpp @@ -52,7 +52,7 @@ std::vector Setting::GetStringList(const std::string& pluginName, vector result; for (size_t i = 0; i < size; i++) - result.push_back(string(outBuffer[i])); + result.emplace_back(outBuffer[i]); for (size_t i = 0; i < defaultValue.size(); i++) BNFreeString(buffer[i]); @@ -171,4 +171,4 @@ bool Setting::RemoveSetting(const std::string& settingGroup, const std::string& bool Setting::FlushSettings() { return BNSettingFlushSettings(); -} \ No newline at end of file +} diff --git a/type.cpp b/type.cpp index 40a69ae2..c158f53e 100644 --- a/type.cpp +++ b/type.cpp @@ -476,16 +476,8 @@ vector Type::GetTokens(Platform* platform, uint8_t baseCon vector result; for (size_t i = 0; i < count; i++) { - InstructionTextToken token; - token.type = tokens[i].type; - token.text = tokens[i].text; - token.value = tokens[i].value; - token.size = tokens[i].size; - token.operand = tokens[i].operand; - token.context = tokens[i].context; - token.confidence = tokens[i].confidence; - token.address = tokens[i].address; - result.push_back(token); + 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); @@ -502,16 +494,8 @@ vector Type::GetTokensBeforeName(Platform* platform, uint8 vector result; for (size_t i = 0; i < count; i++) { - InstructionTextToken token; - token.type = tokens[i].type; - token.text = tokens[i].text; - token.value = tokens[i].value; - token.size = tokens[i].size; - token.operand = tokens[i].operand; - token.context = tokens[i].context; - token.confidence = tokens[i].confidence; - token.address = tokens[i].address; - result.push_back(token); + 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); @@ -528,16 +512,8 @@ vector Type::GetTokensAfterName(Platform* platform, uint8_ vector result; for (size_t i = 0; i < count; i++) { - InstructionTextToken token; - token.type = tokens[i].type; - token.text = tokens[i].text; - token.value = tokens[i].value; - token.size = tokens[i].size; - token.operand = tokens[i].operand; - token.context = tokens[i].context; - token.confidence = tokens[i].confidence; - token.address = tokens[i].address; - result.push_back(token); + 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); -- cgit v1.3.1 From 4866de9b9f0ef32dfa568aa38faafdfd4def4638 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 11 Jan 2018 20:49:32 -0500 Subject: fixes binaryninja-api #784 improper call to BNCreateEnumerationType --- python/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/types.py b/python/types.py index 2557db2c..49f1fdeb 100644 --- a/python/types.py +++ b/python/types.py @@ -515,10 +515,10 @@ class Type(object): return Type(core.BNCreateNamedTypeReferenceFromType(view.handle, name)) @classmethod - def enumeration_type(self, arch, e, width=None): + def enumeration_type(self, arch, e, width=None, sign=False): if width is None: width = arch.default_int_size - return Type(core.BNCreateEnumerationType(e.handle, width)) + return Type(core.BNCreateEnumerationType(arch.handle, e.handle, width, sign)) @classmethod def pointer(self, arch, t, const=None, volatile=None, ref_type=None): -- 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(-) 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 c351ac9c5c25b8d422648d97f96bebc263999cb6 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Sun, 14 Jan 2018 16:38:14 -0500 Subject: Add InstructionTextToken Constructor --- binaryninjaapi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 31bd2316..d357e5bc 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -968,6 +968,7 @@ namespace BinaryNinja uint64_t address; InstructionTextToken(); + InstructionTextToken(uint8_t confidence, BNInstructionTextTokenType t, const std::string& txt); InstructionTextToken(BNInstructionTextTokenType type, const std::string& text, uint64_t value = 0, size_t size = 0, size_t operand = BN_INVALID_OPERAND, uint8_t confidence = BN_FULL_CONFIDENCE); InstructionTextToken(BNInstructionTextTokenType type, BNInstructionTextTokenContext context, -- cgit v1.3.1 From 5c6b13a5576ccbf9c64ba51079d1a3625661cb50 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 15 Jan 2018 18:29:11 -0500 Subject: Fix 'demangled' typo. --- python/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/types.py b/python/types.py index 49f1fdeb..27b4828f 100644 --- a/python/types.py +++ b/python/types.py @@ -634,7 +634,7 @@ class Type(object): return core.BNGenerateAutoDemangledTypeId(name) @classmethod - def get_auto_demanged_type_id_source(self): + def get_auto_demangled_type_id_source(self): return core.BNGetAutoDemangledTypeIdSource() def with_confidence(self, confidence): -- cgit v1.3.1 From cd8903be01bee8f38833bbabca2b7ae31880abb7 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 15 Jan 2018 18:30:08 -0500 Subject: Add platform check and access correct autodefined field. --- python/binaryview.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/binaryview.py b/python/binaryview.py index 6eb59db1..fae98c14 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2095,6 +2095,8 @@ class BinaryView(object): """ if plat is None: plat = self.platform + if plat is None: + return None func = core.BNGetAnalysisFunction(self.handle, plat.handle, addr) if func is None: return None @@ -3398,7 +3400,7 @@ class BinaryView(object): return None result = Section(section.name, section.type, section.start, section.length, section.linkedSection, section.infoSection, section.infoData, section.align, section.entrySize, section.semantics, - section_list.autoDefined) + section.autoDefined) core.BNFreeSection(section) return result -- cgit v1.3.1 From bbf3e6901902fb4193eb8194d09675590cd7ba1c Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Tue, 16 Jan 2018 19:01:29 -0500 Subject: update open source documentation with qt 5.10 build information --- docs/about/open-source.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/about/open-source.md b/docs/about/open-source.md index 9f385633..a25fb24e 100644 --- a/docs/about/open-source.md +++ b/docs/about/open-source.md @@ -42,12 +42,12 @@ The previous tools are used in the generation of our documentation, but are not ## Building Qt -Binary Ninja uses [Qt 5.6] under an LGPLv3 license which requires that we host the original sources used to build Qt for our application along with instructions on how that source may be re-built and can replace the version of Qt shipped with Binary Ninja. +Binary Ninja uses [Qt 5.10] under an LGPLv3 license which requires that we host the original sources used to build Qt for our application along with instructions on how that source may be re-built and can replace the version of Qt shipped with Binary Ninja. Please note that we offer no support for running Binary Ninja with modified Qt libraries. 1. Follow the installation requirements on the [Building Qt 5 from Git] page. -2. Download the Qt 5.6.0 [tarball] from binary.ninja. (Note this is an unmodified 5.6 identical to that available from Qt's source control, but must be hosted locally according to the [Qt 5.6] terms.) +2. Download the Qt 5.10.0 [tarball] from binary.ninja. (Note this is an unmodified 5.10 identical to that available from Qt's source control, but must be hosted locally according to the [Qt 5.10] terms.) 3. Next, build QT using the aforementioned instructions. 4. On OS X, you will need to disable the code-signing signature since it would otherwise prevent changes to binaries or shared libraries. We recommend a tool such as [unsign]. 5. Finally, replace the built libraries: @@ -56,7 +56,7 @@ Please note that we offer no support for running Binary Ninja with modified Qt l - On Linux, replace the `libQt5Core.so.5`, `libQt5DBus.so.5`, `libQt5Gui.so.5`, `libQt5Network.so.5`, `libQt5Widgets.so.5`, `libQt5XcbQpa.so.5` files wherever Binary Ninja was extracted [Building Qt 5 from Git]: https://wiki.qt.io/Building-Qt-5-from-Git -[Qt 5.6]: https://www.qt.io/qt-licensing-terms/ +[Qt 5.10]: https://www.qt.io/qt-licensing-terms/ [capstone]: https://github.com/aquynh/capstone [capstone license]: https://github.com/aquynh/capstone/blob/master/LICENSE.TXT [breathe license]: https://github.com/michaeljones/breathe/blob/master/LICENSE @@ -97,7 +97,7 @@ Please note that we offer no support for running Binary Ninja with modified Qt l [sphinx]: http://www.sphinx-doc.org/en/stable/index.html [sqlite license]: https://www.sqlite.org/copyright.html [sqlite]: https://www.sqlite.org/index.html -[tarball]: https://binary.ninja/qt5.6.0.tar.xz +[tarball]: https://binary.ninja/qt5.10.0.tar.xz [tomcrypt license]: https://github.com/libtom/libtomcrypt/blob/develop/LICENSE [tomcrypt]: https://github.com/libtom/libtomcrypt [unsign]: https://github.com/steakknife/unsign -- cgit v1.3.1 From 6580ae315ea60d630625f7f8592ebddfc95bf563 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Tue, 16 Jan 2018 19:01:51 -0500 Subject: fix slack badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfa453d0..74788a28 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![slack](https://binaryninja-slack-hwwdinrdce.now.sh/badge.svg)](https://binaryninja-slack-hwwdinrdce.now.sh/) +[![slack](https://slackin-sbhuzyheck.now.sh/badge.svg)](https://binaryninja-slack-hwwdinrdce.now.sh/) # Binary Ninja API -- 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(+) 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 From a5328d944c9ba71e67ad2607d0a7f943f91645c2 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 25 Jan 2018 10:30:43 -0500 Subject: fixes #912 --- python/types.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/types.py b/python/types.py index 27b4828f..feb256d0 100644 --- a/python/types.py +++ b/python/types.py @@ -471,6 +471,7 @@ class Type(object): :param int width: width of the integer in bytes :param bool sign: optional variable representing signedness + :param string altname: alternate name for type """ if sign is None: sign = BoolWithConfidence(True, confidence = 0) @@ -484,8 +485,14 @@ class Type(object): return Type(core.BNCreateIntegerType(width, sign_conf, altname)) @classmethod - def float(self, width): - return Type(core.BNCreateFloatType(width)) + def float(self, width, altname=""): + """ + ``float`` class method for creating an floating point Types. + + :param int width: width of the floating point number in bytes + :param string altname: alternate name for type + """ + return Type(core.BNCreateFloatType(width, altname)) @classmethod def structure_type(self, structure_type): -- cgit v1.3.1 From c352fec480dde5321a0c52850be1bb8a3df9bbd3 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sat, 27 Jan 2018 11:12:47 -0500 Subject: fix blocks to function in documentation and another small typo --- docs/getting-started.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 88945f7b..e34121c1 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -210,15 +210,15 @@ By default the interactive python prompt has a number of convenient helper funct - `bv` / `current_view` / : the current [BinaryView](https://api.binary.ninja/binaryninja.BinaryView.html) - `current_function`: the current [Function](https://api.binary.ninja/binaryninja.Function.html) - `current_basic_block`: the current [BasicBlock](https://api.binary.ninja/binaryninja.BasicBlock.html) -- `current_llil`: the current [LowLevelILBasicBlock](https://api.binary.ninja/binaryninja.lowlevelil.LowLevelILBasicBlock.html) -- `current_mlil`: the current [MediumLevelILBasicBlock](https://api.binary.ninja/binaryninja.mediumlevelil.MediumLevelILBasicBlock.html) +- `current_llil`: the current [LowLevelILFunction](https://api.binary.ninja/binaryninja.lowlevelil.LowLevelILFunction.html) +- `current_mlil`: the current [MediumLevelILFunction](https://api.binary.ninja/binaryninja.mediumlevelil.MediumLevelILFunction.html) - `current_selection`: a tuple of the start and end addresses of the current selection - `write_at_cursor(data)`: function that writes data to the start of the current selection - `get_selected_data()`: function that returns the data in the current selection Note !!! Tip "Note" - The current script console only supports Python at the moment, but it's fully extensible for other programming languages for advanced users who with to implement their own bindings. + The current script console only supports Python at the moment, but it's fully extensible for other programming languages for advanced users who wish to implement their own bindings. ## Using Plugins -- cgit v1.3.1