summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h6
-rw-r--r--binaryninjacore.h28
-rw-r--r--binaryview.cpp20
-rw-r--r--function.cpp12
-rw-r--r--python/__init__.py26
5 files changed, 79 insertions, 13 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index b4606596..85a0fc41 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -679,6 +679,8 @@ namespace BinaryNinja
bool autoDiscovered;
};
+ struct NameAndType;
+
/*! BinaryView is the base class for creating views on binary data (e.g. ELF, PE, Mach-O).
BinaryView should be subclassed to create a new BinaryView
*/
@@ -887,6 +889,8 @@ namespace BinaryNinja
DisassemblySettings* settings);
std::vector<LinearDisassemblyLine> GetNextLinearDisassemblyLines(LinearDisassemblyPosition& pos,
DisassemblySettings* settings);
+
+ bool ParseTypeString(const std::string& text, NameAndType& result, std::string& errors);
};
class BinaryData: public BinaryView
@@ -1612,6 +1616,8 @@ namespace BinaryNinja
std::set<uint32_t> GetFlagsWrittenByLiftedILInstruction(size_t i);
Ref<Type> GetType() const;
+ void SetAutoType(Type* type);
+ void SetUserType(Type* type);
void ApplyImportedTypes(Symbol* sym);
void ApplyAutoDiscoveredType(Type* type);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index ac4fa0a3..837a99e1 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -161,17 +161,18 @@ extern "C"
FloatingPointToken = 8,
AnnotationToken = 9,
CodeRelativeAddressToken = 10,
- VariableTypeToken = 11,
- FunctionReturnTypeToken = 12,
- FunctionAttributeToken = 13,
- ArgumentTypeToken = 14,
- ArgumentNameToken = 15,
- HexDumpByteValueToken = 16,
- HexDumpSkippedByteToken = 17,
- HexDumpInvalidByteToken = 18,
- HexDumpTextToken = 19,
- OpcodeToken = 20,
- StringToken = 21,
+ StackVariableTypeToken = 11,
+ DataVariableTypeToken = 12,
+ FunctionReturnTypeToken = 13,
+ FunctionAttributeToken = 14,
+ ArgumentTypeToken = 15,
+ ArgumentNameToken = 16,
+ HexDumpByteValueToken = 17,
+ HexDumpSkippedByteToken = 18,
+ HexDumpInvalidByteToken = 19,
+ HexDumpTextToken = 20,
+ OpcodeToken = 21,
+ StringToken = 22,
// The following are output by the analysis system automatically, these should
// not be used directly by the architecture plugins
@@ -1309,6 +1310,8 @@ extern "C"
BINARYNINJACOREAPI BNSymbol* BNGetFunctionSymbol(BNFunction* func);
BINARYNINJACOREAPI bool BNWasFunctionAutomaticallyDiscovered(BNFunction* func);
BINARYNINJACOREAPI bool BNCanFunctionReturn(BNFunction* func);
+ BINARYNINJACOREAPI void BNSetFunctionAutoType(BNFunction* func, BNType* type);
+ BINARYNINJACOREAPI void BNSetFunctionUserType(BNFunction* func, BNType* type);
BINARYNINJACOREAPI char* BNGetCommentForAddress(BNFunction* func, uint64_t addr);
BINARYNINJACOREAPI uint64_t* BNGetCommentedAddresses(BNFunction* func, size_t* count);
@@ -1452,6 +1455,9 @@ extern "C"
BINARYNINJACOREAPI void BNFreeDataVariables(BNDataVariable* vars, size_t count);
BINARYNINJACOREAPI bool BNGetDataVariableAtAddress(BNBinaryView* view, uint64_t addr, BNDataVariable* var);
+ BINARYNINJACOREAPI bool BNParseTypeString(BNBinaryView* view, const char* text, BNNameAndType* result, char** errors);
+ BINARYNINJACOREAPI void BNFreeNameAndType(BNNameAndType* obj);
+
// Disassembly settings
BINARYNINJACOREAPI BNDisassemblySettings* BNCreateDisassemblySettings(void);
BINARYNINJACOREAPI BNDisassemblySettings* BNNewDisassemblySettingsReference(BNDisassemblySettings* settings);
diff --git a/binaryview.cpp b/binaryview.cpp
index ab519297..ee5bda8e 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1338,6 +1338,26 @@ vector<LinearDisassemblyLine> BinaryView::GetNextLinearDisassemblyLines(LinearDi
}
+bool BinaryView::ParseTypeString(const string& text, NameAndType& result, string& errors)
+{
+ BNNameAndType nt;
+ char* errorStr;
+
+ if (!BNParseTypeString(m_object, text.c_str(), &nt, &errorStr))
+ {
+ errors = errorStr;
+ BNFreeString(errorStr);
+ return false;
+ }
+
+ result.name = nt.name;
+ result.type = new Type(nt.type);
+ errors = "";
+ BNFreeString(nt.name);
+ return true;
+}
+
+
BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetObject()))
{
}
diff --git a/function.cpp b/function.cpp
index ea0fec86..55f5cffb 100644
--- a/function.cpp
+++ b/function.cpp
@@ -354,6 +354,18 @@ Ref<Type> Function::GetType() const
}
+void Function::SetAutoType(Type* type)
+{
+ BNSetFunctionAutoType(m_object, type->GetObject());
+}
+
+
+void Function::SetUserType(Type* type)
+{
+ BNSetFunctionUserType(m_object, type->GetObject());
+}
+
+
void Function::ApplyImportedTypes(Symbol* sym)
{
BNApplyImportedTypes(m_object, sym->GetObject());
diff --git a/python/__init__.py b/python/__init__.py
index fd4af520..9f090c2f 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -1733,6 +1733,18 @@ class BinaryView(object):
return iter(LinearDisassemblyIterator(self, settings))
+ def parse_type_string(self, text):
+ result = core.BNNameAndType()
+ errors = ctypes.c_char_p()
+ if not core.BNParseTypeString(self.handle, text, result, errors):
+ error_str = errors.value
+ core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
+ raise SyntaxError, error_str
+ type_obj = Type(core.BNNewTypeReference(result.type))
+ name = result.name
+ core.BNFreeNameAndType(result)
+ return type_obj, name
+
def __setattr__(self, name, value):
try:
object.__setattr__(self,name,value)
@@ -2523,10 +2535,14 @@ class Function(object):
core.BNGetFunctionLiftedIL(self.handle)), self)
@property
- def type(self):
- """Function type (read-only)"""
+ def function_type(self):
+ """Function type"""
return Type(core.BNGetFunctionType(self.handle))
+ @function_type.setter
+ def function_type(self, value):
+ self.set_user_type(value)
+
@property
def stack_layout(self):
"""List of function stack (read-only)"""
@@ -2783,6 +2799,12 @@ class Function(object):
core.BNFreeInstructionTextLines(lines, count.value)
return result
+ def set_auto_type(self, value):
+ core.BNSetFunctionAutoType(self.handle, value.handle)
+
+ def set_user_type(self, value):
+ core.BNSetFunctionUserType(self.handle, value.handle)
+
class BasicBlockEdge:
def __init__(self, branch_type, target, arch):
self.type = core.BNBranchType_names[branch_type]