From 3dd22f40996fc128ffce6026e8e747ca66bcc21d Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 22 Jan 2024 16:11:19 -0500 Subject: Project support --- externallibrary.cpp | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 externallibrary.cpp (limited to 'externallibrary.cpp') diff --git a/externallibrary.cpp b/externallibrary.cpp new file mode 100644 index 00000000..77b9cabc --- /dev/null +++ b/externallibrary.cpp @@ -0,0 +1,144 @@ +// Copyright (c) 2015-2023 Vector 35 Inc +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +#include +#include "binaryninjaapi.h" +#include "binaryninjacore.h" + +using namespace BinaryNinja; + + +ExternalLibrary::ExternalLibrary(BNExternalLibrary* lib) +{ + m_object = lib; +} + + +std::string ExternalLibrary::GetName() const +{ + char* name = BNExternalLibraryGetName(m_object); + std::string result = name; + BNFreeString(name); + return result; +} + + +Ref ExternalLibrary::GetBackingFile() const +{ + BNProjectFile* file = BNExternalLibraryGetBackingFile(m_object); + if (!file) + return nullptr; + return new ProjectFile(BNNewProjectFileReference(file)); +} + + +void ExternalLibrary::SetBackingFile(Ref file) +{ + BNExternalLibrarySetBackingFile(m_object, file ? file->m_object : nullptr); +} + + +ExternalLocation::ExternalLocation(BNExternalLocation* loc) +{ + m_object = loc; +} + + +Ref ExternalLocation::GetInternalSymbol() +{ + BNSymbol* sym = BNExternalLocationGetInternalSymbol(m_object); + return new Symbol(sym); +} + + +std::optional ExternalLocation::GetAddress() +{ + if (BNExternalLocationHasAddress(m_object)) + { + return BNExternalLocationGetAddress(m_object); + } + return {}; +} + + +std::optional ExternalLocation::GetSymbol() +{ + if (BNExternalLocationHasSymbol(m_object)) + { + return BNExternalLocationGetSymbol(m_object); + } + return {}; +} + + +Ref ExternalLocation::GetExternalLibrary() +{ + BNExternalLibrary* lib = BNExternalLocationGetExternalLibrary(m_object); + if (!lib) + return nullptr; + return new ExternalLibrary(BNNewExternalLibraryReference(lib)); +} + + +bool ExternalLocation::HasAddress() +{ + return BNExternalLocationHasAddress(m_object); +} + + +bool ExternalLocation::HasSymbol() +{ + return BNExternalLocationHasSymbol(m_object); +} + + +void ExternalLocation::SetAddress(std::optional address) +{ + if (address.has_value()) + { + uint64_t addr = address.value(); + BNExternalLocationSetAddress(m_object, &addr); + } + else + { + BNExternalLocationSetAddress(m_object, nullptr); + } +} + + +void ExternalLocation::SetSymbol(std::optional symbol) +{ + if (symbol.has_value()) + { + std::string sym = symbol.value(); + BNExternalLocationSetSymbol(m_object, sym.c_str()); + } + else + { + BNExternalLocationSetSymbol(m_object, nullptr); + } +} + + +void ExternalLocation::SetExternalLibrary(Ref library) +{ + BNExternalLocationSetExternalLibrary(m_object, library ? library->m_object : nullptr); +} + + -- cgit v1.3.1