summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2018-01-11 17:10:34 -0500
committerBrian Potchik <brian@vector35.com>2018-01-11 17:10:34 -0500
commit1df49afa5522d73d509d20db9588294fe259085f (patch)
tree089a2ff85c527c485a9d8bd7f3b9c6d234f2fa2f
parentbc779f1e0140a933d65926b9af840a80636a6dd4 (diff)
API Temporary Object Elimination.
-rw-r--r--architecture.cpp4
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryview.cpp22
-rw-r--r--function.cpp49
-rw-r--r--lowlevelil.cpp24
-rw-r--r--mediumlevelil.cpp24
-rw-r--r--plugin.cpp2
-rw-r--r--settings.cpp4
-rw-r--r--type.cpp36
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<Ref<Type>> 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<BinaryView> view = new BinaryView(BNNewViewReference(object));
- DataVariable varObj;
- varObj.address = var->address;
- varObj.type = Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence);
- varObj.autoDiscovered = var->autoDiscovered;
+ DataVariable varObj(var->address, Confidence<Ref<Type>>(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<BinaryView> view = new BinaryView(BNNewViewReference(object));
- DataVariable varObj;
- varObj.address = var->address;
- varObj.type = Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence);
- varObj.autoDiscovered = var->autoDiscovered;
+ DataVariable varObj(var->address, Confidence<Ref<Type>>(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<BinaryView> view = new BinaryView(BNNewViewReference(object));
- DataVariable varObj;
- varObj.address = var->address;
- varObj.type = Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence);
- varObj.autoDiscovered = var->autoDiscovered;
+ DataVariable varObj(var->address, Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered);
notify->OnDataVariableUpdated(view, varObj);
}
@@ -965,11 +956,8 @@ map<uint64_t, DataVariable> BinaryView::GetDataVariables()
map<uint64_t, DataVariable> result;
for (size_t i = 0; i < count; i++)
{
- DataVariable var;
- var.address = vars[i].address;
- var.type = Confidence<Ref<Type>>(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<Ref<Type>>(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<vector<Variable>> Function::GetParameterVariables() const
vector<Variable> 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<vector<Variable>> result(varList, vars.confidence);
BNFreeParameterVariables(&vars);
@@ -569,13 +565,14 @@ void Function::SetAutoCallingConvention(const Confidence<Ref<CallingConvention>>
void Function::SetAutoParameterVariables(const Confidence<vector<Variable>>& 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<size_t>& stackAdjust)
void Function::SetAutoClobberedRegisters(const Confidence<std::set<uint32_t>>& 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, &regs);
delete[] regs.regs;
@@ -652,13 +650,14 @@ void Function::SetCallingConvention(const Confidence<Ref<CallingConvention>>& co
void Function::SetParameterVariables(const Confidence<vector<Variable>>& 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<size_t>& stackAdjust)
void Function::SetClobberedRegisters(const Confidence<std::set<uint32_t>>& 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, &regs);
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<Ins
tokens.clear();
for (size_t i = 0; i < count; i++)
{
- InstructionTextToken token;
- token.type = list[i].type;
- token.text = list[i].text;
- token.value = list[i].value;
- token.size = list[i].size;
- token.operand = list[i].operand;
- token.context = list[i].context;
- token.confidence = list[i].confidence;
- token.address = list[i].address;
- tokens.push_back(token);
+ 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);
@@ -421,16 +413,8 @@ bool LowLevelILFunction::GetInstructionText(Function* func, Architecture* arch,
tokens.clear();
for (size_t i = 0; i < count; i++)
{
- InstructionTextToken token;
- token.type = list[i].type;
- token.text = list[i].text;
- token.value = list[i].value;
- token.size = list[i].size;
- token.operand = list[i].operand;
- token.context = list[i].context;
- token.confidence = list[i].confidence;
- token.address = list[i].address;
- tokens.push_back(token);
+ 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);
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index 04a7341f..2cd5a233 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -340,16 +340,8 @@ bool MediumLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector<
tokens.clear();
for (size_t i = 0; i < count; i++)
{
- InstructionTextToken token;
- token.type = list[i].type;
- token.text = list[i].text;
- token.value = list[i].value;
- token.size = list[i].size;
- token.operand = list[i].operand;
- token.context = list[i].context;
- token.confidence = list[i].confidence;
- token.address = list[i].address;
- tokens.push_back(token);
+ 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);
@@ -369,16 +361,8 @@ bool MediumLevelILFunction::GetInstructionText(Function* func, Architecture* arc
tokens.clear();
for (size_t i = 0; i < count; i++)
{
- InstructionTextToken token;
- token.type = list[i].type;
- token.text = list[i].text;
- token.value = list[i].value;
- token.size = list[i].size;
- token.operand = list[i].operand;
- token.context = list[i].context;
- token.confidence = list[i].confidence;
- token.address = list[i].address;
- tokens.push_back(token);
+ 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);
diff --git a/plugin.cpp b/plugin.cpp
index e8dd881d..2378fdab 100644
--- a/plugin.cpp
+++ b/plugin.cpp
@@ -212,7 +212,7 @@ vector<PluginCommand> 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<std::string> Setting::GetStringList(const std::string& pluginName,
vector<string> 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<InstructionTextToken> Type::GetTokens(Platform* platform, uint8_t baseCon
vector<InstructionTextToken> 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<InstructionTextToken> Type::GetTokensBeforeName(Platform* platform, uint8
vector<InstructionTextToken> 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<InstructionTextToken> Type::GetTokensAfterName(Platform* platform, uint8_
vector<InstructionTextToken> 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);