summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h130
1 files changed, 104 insertions, 26 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index f2c15fde..678caa06 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -19,7 +19,6 @@
// IN THE SOFTWARE.
#pragma once
-
#ifdef WIN32
#define NOMINMAX
#include <windows.h>
@@ -34,6 +33,7 @@
#include <set>
#include <mutex>
#include <memory>
+#include <cstdint>
#include "binaryninjacore.h"
#include "json/json.h"
@@ -853,7 +853,6 @@ namespace BinaryNinja
BinaryNinja::Ref<BinaryNinja::BinaryView> GetViewOfType(const std::string& name);
};
- class BinaryView;
class Function;
struct DataVariable;
@@ -935,12 +934,10 @@ namespace BinaryNinja
class Function;
class BasicBlock;
-
class Symbol: public CoreRefCountObject<BNSymbol, BNNewSymbolReference, BNFreeSymbol>
{
public:
- Symbol(BNSymbolType type, const std::string& shortName, const std::string& fullName,
- const std::string& rawName, uint64_t addr);
+ Symbol(BNSymbolType type, const std::string& shortName, const std::string& fullName, const std::string& rawName, uint64_t addr);
Symbol(BNSymbolType type, const std::string& name, uint64_t addr);
Symbol(BNSymbol* sym);
@@ -1051,28 +1048,54 @@ namespace BinaryNinja
bool autoDiscovered;
};
- struct Segment
+ class Segment: public CoreRefCountObject<BNSegment, BNNewSegmentReference, BNFreeSegment>
{
- uint64_t start, length;
- uint64_t dataOffset, dataLength;
- uint32_t flags;
- bool autoDefined;
+ public:
+ Segment(BNSegment* seg);
+ uint64_t GetStart() const;
+ uint64_t GetLength() const;
+ uint64_t GetEnd() const;
+ uint64_t GetDataEnd() const;
+ uint64_t GetDataOffset() const;
+ uint64_t GetDataLength() const;
+ uint32_t GetFlags() const;
+ bool IsAutoDefined() const;
+
+ std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRanges() const;
+ std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRangesAtAddress(uint64_t addr) const;
+ uint64_t GetRelocationsCount() const;
+
+ void SetStart(uint64_t newSegmentBase);
+ void SetLength(uint64_t length);
+ void SetDataOffset(uint64_t dataOffset);
+ void SetDataLength(uint64_t dataLength);
+ void SetFlags(uint64_t flags);
+
+ size_t Read(BinaryView* view, uint8_t* dest, uint64_t offset, size_t len);
};
- struct Section
+ class Section: public CoreRefCountObject<BNSection, BNNewSectionReference, BNFreeSection>
{
- std::string name, type;
- uint64_t start, length;
- std::string linkedSection, infoSection;
- uint64_t infoData;
- uint64_t align, entrySize;
- BNSectionSemantics semantics;
- bool autoDefined;
+ public:
+ Section(BNSection* sec);
+ Section(const std::string& name, uint64_t start, uint64_t length, BNSectionSemantics semantics,
+ const std::string& type, uint64_t align, uint64_t entrySize, const std::string& linkedSection,
+ const std::string& infoSection, uint64_t infoData, bool autoDefined);
+ std::string GetName() const;
+ std::string GetType() const;
+ uint64_t GetStart() const;
+ uint64_t GetLength() const;
+ uint64_t GetInfoData() const;
+ uint64_t GetAlignment() const;
+ uint64_t GetEntrySize() const;
+ std::string GetLinkedSection() const;
+ std::string GetInfoSection() const;
+ BNSectionSemantics GetSemantics() const;
+ bool AutoDefined() const;
};
struct QualifiedNameAndType;
class Metadata;
-
class QueryMetadataException: public std::exception
{
const std::string m_error;
@@ -1123,7 +1146,8 @@ namespace BinaryNinja
virtual size_t PerformGetAddressSize() const;
virtual bool PerformSave(FileAccessor* file);
-
+ void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, uint64_t target, uint64_t reloc);
+ void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, Ref<Symbol> sym, uint64_t reloc);
void NotifyDataWritten(uint64_t offset, size_t len);
void NotifyDataInserted(uint64_t offset, size_t len);
void NotifyDataRemoved(uint64_t offset, uint64_t len);
@@ -1150,7 +1174,8 @@ namespace BinaryNinja
static bool IsRelocatableCallback(void* ctxt);
static size_t GetAddressSizeCallback(void* ctxt);
static bool SaveCallback(void* ctxt, BNFileAccessor* file);
-
+ static void DefineRelocationCallback(void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, uint64_t target, uint64_t reloc);
+ static void DefineSymbolRelocationCallback(void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSymbol* target, uint64_t reloc);
public:
BinaryView(BNBinaryView* view);
@@ -1201,6 +1226,7 @@ namespace BinaryNinja
bool IsOffsetBackedByFile(uint64_t offset) const;
bool IsOffsetCodeSemantics(uint64_t offset) const;
bool IsOffsetWritableSemantics(uint64_t offset) const;
+ bool IsOffsetExternSemantics(uint64_t offset) const;
uint64_t GetNextValidOffset(uint64_t offset) const;
uint64_t GetStart() const;
@@ -1222,6 +1248,11 @@ namespace BinaryNinja
bool Save(FileAccessor* file);
bool Save(const std::string& path);
+ void DefineRelocation(Architecture* arch, BNRelocationInfo& info, uint64_t target, uint64_t reloc);
+ void DefineRelocation(Architecture* arch, BNRelocationInfo& info, Ref<Symbol> target, uint64_t reloc);
+ std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRanges() const;
+ std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRangesAtAddress(uint64_t addr) const;
+
void RegisterNotification(BinaryDataNotification* notify);
void UnregisterNotification(BinaryDataNotification* notify);
@@ -1341,8 +1372,8 @@ namespace BinaryNinja
void RemoveAutoSegment(uint64_t start, uint64_t length);
void AddUserSegment(uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags);
void RemoveUserSegment(uint64_t start, uint64_t length);
- std::vector<Segment> GetSegments();
- bool GetSegmentAt(uint64_t addr, Segment& result);
+ std::vector<Ref<Segment>> GetSegments();
+ Ref<Segment> GetSegmentAt(uint64_t addr);
bool GetAddressForDataOffset(uint64_t offset, uint64_t& addr);
void AddAutoSection(const std::string& name, uint64_t start, uint64_t length,
@@ -1355,9 +1386,9 @@ namespace BinaryNinja
uint64_t align = 1, uint64_t entrySize = 0, const std::string& linkedSection = "",
const std::string& infoSection = "", uint64_t infoData = 0);
void RemoveUserSection(const std::string& name);
- std::vector<Section> GetSections();
- std::vector<Section> GetSectionsAt(uint64_t addr);
- bool GetSectionByName(const std::string& name, Section& result);
+ std::vector<Ref<Section>> GetSections();
+ std::vector<Ref<Section>> GetSectionsAt(uint64_t addr);
+ Ref<Section> GetSectionByName(const std::string& name);
std::vector<std::string> GetUniqueSectionNames(const std::vector<std::string>& names);
@@ -1376,6 +1407,19 @@ namespace BinaryNinja
void SetMaxFunctionSizeForAnalysis(uint64_t size);
};
+
+ class Relocation: public CoreRefCountObject<BNRelocation, BNNewRelocationReference, BNFreeRelocation>
+ {
+ public:
+ Relocation(BNRelocation* reloc);
+ BNRelocationInfo GetInfo() const;
+ Architecture* GetArchitecture() const;
+ uint64_t GetTarget() const;
+ uint64_t GetReloc() const;
+ Ref<Symbol> GetSymbol() const;
+ };
+
+
class BinaryData: public BinaryView
{
public:
@@ -1616,6 +1660,7 @@ namespace BinaryNinja
class MediumLevelILFunction;
class FunctionRecognizer;
class CallingConvention;
+ class RelocationHandler;
typedef size_t ExprId;
@@ -1846,6 +1891,8 @@ namespace BinaryNinja
virtual bool SkipAndReturnValue(uint8_t* data, uint64_t addr, size_t len, uint64_t value);
void RegisterFunctionRecognizer(FunctionRecognizer* recog);
+ void RegisterRelocationHandler(const std::string& viewName, RelocationHandler* handler);
+ Ref<RelocationHandler> GetRelocationHandler(const std::string& viewName);
bool IsBinaryViewTypeConstantDefined(const std::string& type, const std::string& name);
uint64_t GetBinaryViewTypeConstant(const std::string& type, const std::string& name,
@@ -1887,6 +1934,7 @@ namespace BinaryNinja
virtual std::string GetRegisterName(uint32_t reg) override;
virtual std::string GetFlagName(uint32_t flag) override;
virtual std::string GetFlagWriteTypeName(uint32_t flags) override;
+
virtual std::string GetSemanticFlagClassName(uint32_t semClass) override;
virtual std::string GetSemanticFlagGroupName(uint32_t semGroup) override;
virtual std::vector<uint32_t> GetFullWidthRegisters() override;
@@ -3323,6 +3371,36 @@ namespace BinaryNinja
virtual bool RecognizeMediumLevelIL(BinaryView* data, Function* func, MediumLevelILFunction* il);
};
+ class RelocationHandler: public CoreRefCountObject<BNRelocationHandler,
+ BNNewRelocationHandlerReference, BNFreeRelocationHandler>
+ {
+ static bool GetRelocationInfoCallback(void* ctxt, BNBinaryView* view, BNArchitecture* arch,
+ BNRelocationInfo* result, size_t resultCount);
+ static bool ApplyRelocationCallback(void* ctxt, BNBinaryView* view, BNArchitecture* arch, BNRelocation* reloc,
+ uint8_t* dest, size_t len);
+
+ protected:
+ RelocationHandler();
+ RelocationHandler(BNRelocationHandler* handler);
+ static void FreeCallback(void* ctxt);
+
+ public:
+
+ virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, std::vector<BNRelocationInfo>& result);
+ virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc, uint8_t* dest,
+ size_t len);
+ };
+
+ class CoreRelocationHandler: public RelocationHandler
+ {
+ public:
+ CoreRelocationHandler(BNRelocationHandler* handler);
+
+ virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, std::vector<BNRelocationInfo>& result) override;
+ virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc, uint8_t* dest,
+ size_t len) override;
+ };
+
class UpdateException: public std::exception
{
const std::string m_desc;