From bdf05c261bd1c24f0440c17e10b983b50613bc20 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Thu, 22 Sep 2022 13:43:46 -0400 Subject: Add new DebugInfo APIs --- debuginfo.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 3 deletions(-) (limited to 'debuginfo.cpp') diff --git a/debuginfo.cpp b/debuginfo.cpp index e8450399..fb10039e 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -38,7 +38,23 @@ DebugInfo::DebugInfo(BNDebugInfo* debugInfo) } -vector DebugInfo::GetTypes(const string& parserName) +vector DebugInfo::GetParsers() const +{ + size_t count; + char** parsers = BNGetDebugParserNames(m_object, &count); + + vector result; + for (size_t i = 0; i < count; ++i) + { + result.emplace_back(parsers[i]); + } + BNFreeStringList(parsers, count); + + return result; +} + + +vector DebugInfo::GetTypes(const string& parserName) const { size_t count; BNNameAndType* nameAndTypes = @@ -56,7 +72,7 @@ vector DebugInfo::GetTypes(const string& parserName) } -vector DebugInfo::GetFunctions(const string& parserName) +vector DebugInfo::GetFunctions(const string& parserName) const { size_t count; BNDebugFunctionInfo* functions = @@ -86,7 +102,7 @@ vector DebugInfo::GetFunctions(const string& parserName) } -vector DebugInfo::GetDataVariables(const string& parserName) +vector DebugInfo::GetDataVariables(const string& parserName) const { size_t count; BNDataVariableAndName* variableAndNames = @@ -105,6 +121,138 @@ vector DebugInfo::GetDataVariables(const string& parserName } +// May return nullptr +Ref DebugInfo::GetTypeByName(const string& parserName, const string& name) const +{ + BNType* result = BNGetDebugTypeByName(m_object, parserName.c_str(), name.c_str()); + if (result) + return Ref(new Type(result)); + return nullptr; +} + + +optional>> DebugInfo::GetDataVariableByName( + const string& parserName, const string& name) const +{ + BNDataVariableAndName* result = BNGetDebugDataVariableByName(m_object, parserName.c_str(), name.c_str()); + if (result) + { + BNFreeString(result->name); + return {{result->address, Ref(new Type(result->type))}}; + } + return {}; +} + + +optional>> DebugInfo::GetDataVariableByAddress( + const string& parserName, const uint64_t address) const +{ + BNDataVariableAndName* nameAndVar = BNGetDebugDataVariableByAddress(m_object, parserName.c_str(), address); + if (nameAndVar) + { + const tuple> result = {nameAndVar->name, Ref(new Type(nameAndVar->type))}; + BNFreeString(nameAndVar->name); + return {result}; + } + return {}; +} + + +// The tuple is (DebugInfoParserName, type) +vector>> DebugInfo::GetTypesByName(const string& name) const +{ + size_t count; + BNNameAndType* namesAndTypes = BNGetDebugTypesByName(m_object, name.c_str(), &count); + + vector>> result; + for (size_t i = 0; i < count; ++i) + { + result.emplace_back(namesAndTypes[i].name, Ref(new Type(BNNewTypeReference(namesAndTypes[i].type)))); + } + + BNFreeNameAndTypeList(namesAndTypes, count); + return result; +} + + +// The tuple is (DebugInfoParserName, address, type) +vector>> DebugInfo::GetDataVariablesByName(const string& name) const +{ + size_t count; + BNDataVariableAndName* variablesAndName = BNGetDebugDataVariablesByName(m_object, name.c_str(), &count); + + vector>> result; + for (size_t i = 0; i < count; ++i) + { + result.emplace_back(variablesAndName[i].name, variablesAndName[i].address, + Ref(new Type(BNNewTypeReference(variablesAndName[i].type)))); + } + + BNFreeDataVariablesAndName(variablesAndName, count); + return result; +} + + +// The tuple is (DebugInfoParserName, TypeName, type) +vector>> DebugInfo::GetDataVariablesByAddress(const uint64_t address) const +{ + size_t count; + BNDataVariableAndNameAndDebugParser* variablesAndName = BNGetDebugDataVariablesByAddress(m_object, address, &count); + + vector>> result; + for (size_t i = 0; i < count; ++i) + { + result.emplace_back(variablesAndName[i].parser, variablesAndName[i].name, + Ref(new Type(BNNewTypeReference(variablesAndName[i].type)))); + } + + BNFreeDataVariableAndNameAndDebugParserList(variablesAndName, count); + return result; +} + + +bool DebugInfo::RemoveParserInfo(const string& parserName) +{ + return BNRemoveDebugParserInfo(m_object, parserName.c_str()); +} + + +bool DebugInfo::RemoveParserTypes(const string& parserName) +{ + return BNRemoveDebugParserTypes(m_object, parserName.c_str()); +} + + +bool DebugInfo::RemoveParserFunctions(const string& parserName) +{ + return BNRemoveDebugParserFunctions(m_object, parserName.c_str()); +} + + +bool DebugInfo::RemoveParserDataVariables(const string& parserName) +{ + return BNRemoveDebugParserDataVariables(m_object, parserName.c_str()); +} + + +bool DebugInfo::RemoveTypeByName(const string& parserName, const string& name) +{ + return BNRemoveDebugTypeByName(m_object, parserName.c_str(), name.c_str()); +} + + +bool DebugInfo::RemoveFunctionByIndex(const string& parserName, const size_t index) +{ + return BNRemoveDebugFunctionByIndex(m_object, parserName.c_str(), index); +} + + +bool DebugInfo::RemoveDataVariableByAddress(const string& parserName, const uint64_t address) +{ + return BNRemoveDebugDataVariableByAddress(m_object, parserName.c_str(), address); +} + + bool DebugInfo::AddType(const string& name, Ref type) { return BNAddDebugType(m_object, name.c_str(), type->GetObject()); -- cgit v1.3.1