summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-04-21 22:08:06 -0400
committerRusty Wagner <rusty@vector35.com>2017-04-21 22:08:06 -0400
commit095d7a42a0d2858b4240fbd041d8c22a01c7e571 (patch)
tree94dc183ea3091653cbebfb068def78415b8b209f
parente673afe4b958b5f8f808ff8457d0664ccecce93a (diff)
Allowing rename of all types of variables
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h10
-rw-r--r--function.cpp4
-rw-r--r--python/function.py24
-rw-r--r--python/mediumlevelil.py4
5 files changed, 23 insertions, 21 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 072bfb5a..8df46775 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1838,7 +1838,7 @@ namespace BinaryNinja
uint32_t sourceOperand;
Ref<Type> type;
std::string name;
- int64_t startingOffset;
+ Variable var;
int64_t referencedOffset;
};
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 21592772..69b45c28 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -188,7 +188,7 @@ extern "C"
// not be used directly by the architecture plugins
CodeSymbolToken = 64,
DataSymbolToken = 65,
- StackVariableToken = 66,
+ LocalVariableToken = 66,
ImportToken = 67,
AddressDisplayToken = 68
};
@@ -196,7 +196,7 @@ extern "C"
enum BNInstructionTextTokenContext
{
NoTokenContext = 0,
- StackVariableTokenContext = 1,
+ LocalVariableTokenContext = 1,
DataVariableTokenContext = 2,
FunctionReturnTokenContext = 3,
ArgumentTokenContext = 4
@@ -212,8 +212,8 @@ extern "C"
FunctionHeaderStartLineType,
FunctionHeaderEndLineType,
FunctionContinuationLineType,
- StackVariableLineType,
- StackVariableListEndLineType,
+ LocalVariableLineType,
+ LocalVariableListEndLineType,
FunctionEndLineType,
NoteStartLineType,
NoteLineType,
@@ -1144,7 +1144,7 @@ extern "C"
uint32_t sourceOperand;
BNType* type;
char* name;
- int64_t startingOffset;
+ uint64_t varIdentifier;
int64_t referencedOffset;
};
diff --git a/function.cpp b/function.cpp
index b22f91dc..d4f91db1 100644
--- a/function.cpp
+++ b/function.cpp
@@ -355,7 +355,7 @@ vector<StackVariableReference> Function::GetStackVariablesReferencedByInstructio
ref.sourceOperand = refs[i].sourceOperand;
ref.type = refs[i].type ? new Type(BNNewTypeReference(refs[i].type)) : nullptr;
ref.name = refs[i].name;
- ref.startingOffset = refs[i].startingOffset;
+ ref.var = Variable::FromIdentifier(refs[i].varIdentifier);
ref.referencedOffset = refs[i].referencedOffset;
result.push_back(ref);
}
@@ -584,7 +584,7 @@ void Function::DeleteAutoVariable(const Variable& var)
void Function::DeleteUserVariable(const Variable& var)
{
- BNDeleteAutoVariable(m_object, &var);
+ BNDeleteUserVariable(m_object, &var);
}
diff --git a/python/function.py b/python/function.py
index bca67a44..04187cbe 100644
--- a/python/function.py
+++ b/python/function.py
@@ -147,29 +147,29 @@ class PossibleValueSet(object):
class StackVariableReference(object):
- def __init__(self, src_operand, t, name, start_ofs, ref_ofs):
+ def __init__(self, src_operand, t, name, var, ref_ofs):
self.source_operand = src_operand
self.type = t
self.name = name
- self.starting_offset = start_ofs
+ self.var = var
self.referenced_offset = ref_ofs
if self.source_operand == 0xffffffff:
self.source_operand = None
def __repr__(self):
if self.source_operand is None:
- if self.referenced_offset != self.starting_offset:
- return "<ref to %s%+#x>" % (self.name, self.referenced_offset - self.starting_offset)
+ if self.referenced_offset != self.var.storage:
+ return "<ref to %s%+#x>" % (self.name, self.referenced_offset - self.var.storage)
return "<ref to %s>" % self.name
- if self.referenced_offset != self.starting_offset:
- return "<operand %d ref to %s%+#x>" % (self.source_operand, self.name, self.referenced_offset)
+ if self.referenced_offset != self.var.storage:
+ return "<operand %d ref to %s%+#x>" % (self.source_operand, self.name, self.var.storage)
return "<operand %d ref to %s>" % (self.source_operand, self.name)
class Variable(object):
def __init__(self, func, source_type, index, storage, name = None, var_type = None):
self.function = func
- self.source_type = source_type
+ self.source_type = VariableSourceType(source_type)
self.index = index
self.storage = storage
@@ -190,9 +190,9 @@ class Variable(object):
self.type = var_type
@classmethod
- def from_identifier(self, func, identifier):
+ def from_identifier(self, func, identifier, name = None, var_type = None):
var = core.BNFromVariableIdentifier(identifier)
- return Variable(func, VariableSourceType(var.type), var.index, var.storage)
+ return Variable(func, VariableSourceType(var.type), var.index, var.storage, name, var_type)
def __repr__(self):
if self.type is None:
@@ -603,8 +603,10 @@ class Function(object):
refs = core.BNGetStackVariablesReferencedByInstruction(self.handle, arch.handle, addr, count)
result = []
for i in xrange(0, count.value):
- result.append(StackVariableReference(refs[i].sourceOperand, types.Type(core.BNNewTypeReference(refs[i].type)),
- refs[i].name, refs[i].startingOffset, refs[i].referencedOffset))
+ var_type = types.Type(core.BNNewTypeReference(refs[i].type))
+ result.append(StackVariableReference(refs[i].sourceOperand, var_type,
+ refs[i].name, Variable.from_identifier(self, refs[i].varIdentifier, refs[i].name, var_type),
+ refs[i].referencedOffset))
core.BNFreeStackVariableReferenceList(refs, count.value)
return result
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 316e45b7..bc7a5c89 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -169,8 +169,8 @@ class MediumLevelILInstruction(object):
operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in operand_list:
- value.append(function.Variable.from_identifier(self.function.source_function, j))
+ for j in xrange(count.value):
+ value.append(function.Variable.from_identifier(self.function.source_function, operand_list[j]))
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "var_ssa_list":
count = ctypes.c_ulonglong()