From b505e0464383284e7ce8fefeffc18713488c2c48 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 5 Apr 2016 23:01:17 -0400 Subject: Add backend support for discovering stack variables --- binaryninjaapi.h | 6 ++++++ function.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 0895d831..6ddeaa17 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1273,6 +1273,12 @@ namespace BinaryNinja void ApplyAutoDiscoveredType(Type* type); Ref CreateFunctionGraph(); + + std::map GetStackLayout(); + void CreateAutoStackVariable(int64_t offset, Type* type, const std::string& name); + void CreateUserStackVariable(int64_t offset, Type* type, const std::string& name); + void DeleteAutoStackVariable(int64_t offset); + void DeleteUserStackVariable(int64_t offset); }; struct FunctionGraphTextLine diff --git a/function.cpp b/function.cpp index ee2c5d36..df3b5090 100644 --- a/function.cpp +++ b/function.cpp @@ -210,3 +210,46 @@ Ref Function::CreateFunctionGraph() BNFunctionGraph* graph = BNCreateFunctionGraph(m_object); return new FunctionGraph(graph); } + + +map Function::GetStackLayout() +{ + size_t count; + BNStackVariable* vars = BNGetStackLayout(m_object, &count); + + map result; + for (size_t i = 0; i < count; i++) + { + NameAndType nt; + nt.name = vars[i].name; + nt.type = new Type(BNNewTypeReference(vars[i].type)); + result[vars[i].offset] = nt; + } + + BNFreeStackLayout(vars, count); + return result; +} + + +void Function::CreateAutoStackVariable(int64_t offset, Type* type, const string& name) +{ + BNCreateAutoStackVariable(m_object, offset, type->GetObject(), name.c_str()); +} + + +void Function::CreateUserStackVariable(int64_t offset, Type* type, const string& name) +{ + BNCreateUserStackVariable(m_object, offset, type->GetObject(), name.c_str()); +} + + +void Function::DeleteAutoStackVariable(int64_t offset) +{ + BNDeleteAutoStackVariable(m_object, offset); +} + + +void Function::DeleteUserStackVariable(int64_t offset) +{ + BNDeleteUserStackVariable(m_object, offset); +} -- cgit v1.3.1