summaryrefslogtreecommitdiff
path: root/binaryninjacore.h
diff options
context:
space:
mode:
Diffstat (limited to 'binaryninjacore.h')
-rw-r--r--binaryninjacore.h174
1 files changed, 139 insertions, 35 deletions
diff --git a/binaryninjacore.h b/binaryninjacore.h
index fda26d47..cf84fdc5 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -144,6 +144,11 @@ extern "C"
struct BNRepoPlugin;
struct BNRepositoryManager;
struct BNMetadata;
+ struct BNRelocation;
+ struct BNSegment;
+ struct BNSection;
+ struct BNRelocationInfo;
+ struct BNRelocationHandler;
typedef bool (*BNLoadPluginCallback)(const char* repoPath, const char* pluginPath, void* ctx);
@@ -266,7 +271,17 @@ extern "C"
ImportAddressSymbol = 1,
ImportedFunctionSymbol = 2,
DataSymbol = 3,
- ImportedDataSymbol = 4
+ ImportedDataSymbol = 4,
+ ExternalSymbol = 5,
+ LabelSymbol = 6
+ };
+
+ enum BNSymbolBinding
+ {
+ NoBinding,
+ LocalBinding,
+ GlobalBinding,
+ WeakBinding
};
enum BNActionType
@@ -1039,6 +1054,8 @@ extern "C"
bool (*isRelocatable)(void* ctxt);
size_t (*getAddressSize)(void* ctxt);
bool (*save)(void* ctxt, BNFileAccessor* accessor);
+ void (*defineRelocation) (void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, uint64_t target, uint64_t reloc);
+ void (*defineSymbolRelocation) (void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSymbol* target, uint64_t reloc);
};
struct BNCustomBinaryViewType
@@ -1081,6 +1098,33 @@ extern "C"
BNArchitecture* branchArch[BN_MAX_INSTRUCTION_BRANCHES]; // If null, same architecture as instruction
};
+ enum BNRelocationType
+ {
+ ELFGlobalRelocationType,
+ ELFCopyRelocationType,
+ ELFJumpSlotRelocationType,
+ StandardRelocationType,
+ IgnoredRelocation
+ };
+
+ struct BNRelocationInfo
+ {
+ BNRelocationType type; // BinaryNinja Relocation Type
+ bool pcRelative; // PC Relative or Absolute (subtract address from relocation)
+ bool baseRelative; // Relative to start of module (Add module base to relocation)
+ size_t size; // Size of the data to be written
+ size_t truncateSize; // After addition/subtraction truncate to
+ uint64_t nativeType; // Base type from relocation entry
+ size_t addend; // Addend value from relocation entry
+ bool hasSign; // Addend should be subtracted
+ bool implicitAddend; // Addend should be read from the BinaryView
+ bool external; // Relocation entry points to external symbol
+ size_t symbolIndex; // Index into symbol table
+ size_t sectionIndex; // Index into the section table
+ uint64_t address; // Absolute address or segment offset
+ bool dataRelocation; // This relocation is effecting data not code
+ };
+
struct BNInstructionTextToken
{
BNInstructionTextTokenType type;
@@ -1332,6 +1376,17 @@ extern "C"
bool (*recognizeMediumLevelIL)(void* ctxt, BNBinaryView* data, BNFunction* func, BNMediumLevelILFunction* il);
};
+ struct BNCustomRelocationHandler
+ {
+ void* context;
+ void (*freeObject)(void* ctxt);
+
+ bool (*getRelocationInfo)(void* ctxt, BNBinaryView* view, BNArchitecture* arch, BNRelocationInfo* result,
+ size_t resultCount);
+ bool (*applyRelocation)(void* ctxt, BNBinaryView* view, BNArchitecture* arch, BNRelocation* reloc, uint8_t* dest,
+ size_t len);
+ };
+
struct BNTypeParserResult
{
BNQualifiedNameAndType* types;
@@ -1727,33 +1782,13 @@ extern "C"
SegmentDenyExecute = 0x40
};
- struct BNSegment
- {
- uint64_t start, length;
- uint64_t dataOffset, dataLength;
- uint32_t flags;
- bool autoDefined;
- };
-
enum BNSectionSemantics
{
DefaultSectionSemantics,
ReadOnlyCodeSectionSemantics,
ReadOnlyDataSectionSemantics,
- ReadWriteDataSectionSemantics
- };
-
- struct BNSection
- {
- char* name;
- char* type;
- uint64_t start, length;
- char* linkedSection;
- char* infoSection;
- uint64_t infoData;
- uint64_t align, entrySize;
- BNSectionSemantics semantics;
- bool autoDefined;
+ ReadWriteDataSectionSemantics,
+ ExternalSectionSemantics
};
struct BNAddressRange
@@ -1815,6 +1850,12 @@ extern "C"
AlwaysSkipFunctionAnalysis
};
+ struct BNRange
+ {
+ uint64_t start;
+ uint64_t end;
+ };
+
enum BNAnalysisSkipReason
{
NoSkipReason,
@@ -1994,6 +2035,7 @@ extern "C"
BINARYNINJACOREAPI bool BNIsOffsetExecutable(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetBackedByFile(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetCodeSemantics(BNBinaryView* view, uint64_t offset);
+ BINARYNINJACOREAPI bool BNIsOffsetExternSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetWritableSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetStartOffset(BNBinaryView* view);
@@ -2014,6 +2056,12 @@ extern "C"
BINARYNINJACOREAPI bool BNSaveToFile(BNBinaryView* view, BNFileAccessor* file);
BINARYNINJACOREAPI bool BNSaveToFilename(BNBinaryView* view, const char* filename);
+ BINARYNINJACOREAPI void BNDefineRelocation(BNBinaryView* view, BNArchitecture* arch, BNRelocationInfo* info,
+ uint64_t target, uint64_t reloc);
+ BINARYNINJACOREAPI void BNDefineSymbolRelocation(BNBinaryView* view, BNArchitecture* arch, BNRelocationInfo* info,
+ BNSymbol* target, uint64_t reloc);
+ BINARYNINJACOREAPI BNRange* BNGetRelocationRanges(BNBinaryView* segment, size_t* count);
+ BINARYNINJACOREAPI BNRange* BNGetRelocationRangesAtAddress(BNBinaryView* segment, uint64_t addr, size_t* count);
BINARYNINJACOREAPI void BNRegisterDataNotification(BNBinaryView* view, BNBinaryDataNotification* notify);
BINARYNINJACOREAPI void BNUnregisterDataNotification(BNBinaryView* view, BNBinaryDataNotification* notify);
@@ -2040,9 +2088,9 @@ extern "C"
BINARYNINJACOREAPI void BNAddUserSegment(BNBinaryView* view, uint64_t start, uint64_t length,
uint64_t dataOffset, uint64_t dataLength, uint32_t flags);
BINARYNINJACOREAPI void BNRemoveUserSegment(BNBinaryView* view, uint64_t start, uint64_t length);
- BINARYNINJACOREAPI BNSegment* BNGetSegments(BNBinaryView* view, size_t* count);
- BINARYNINJACOREAPI void BNFreeSegmentList(BNSegment* segments);
- BINARYNINJACOREAPI bool BNGetSegmentAt(BNBinaryView* view, uint64_t addr, BNSegment* result);
+ BINARYNINJACOREAPI BNSegment** BNGetSegments(BNBinaryView* view, size_t* count);
+ BINARYNINJACOREAPI void BNFreeSegmentList(BNSegment** segments, size_t count);
+ BINARYNINJACOREAPI BNSegment* BNGetSegmentAt(BNBinaryView* view, uint64_t addr);
BINARYNINJACOREAPI bool BNGetAddressForDataOffset(BNBinaryView* view, uint64_t offset, uint64_t* addr);
BINARYNINJACOREAPI void BNAddAutoSection(BNBinaryView* view, const char* name, uint64_t start, uint64_t length,
@@ -2053,11 +2101,10 @@ extern "C"
BNSectionSemantics semantics, const char* type, uint64_t align, uint64_t entrySize,
const char* linkedSection, const char* infoSection, uint64_t infoData);
BINARYNINJACOREAPI void BNRemoveUserSection(BNBinaryView* view, const char* name);
- BINARYNINJACOREAPI BNSection* BNGetSections(BNBinaryView* view, size_t* count);
- BINARYNINJACOREAPI BNSection* BNGetSectionsAt(BNBinaryView* view, uint64_t addr, size_t* count);
- BINARYNINJACOREAPI void BNFreeSectionList(BNSection* sections, size_t count);
- BINARYNINJACOREAPI bool BNGetSectionByName(BNBinaryView* view, const char* name, BNSection* result);
- BINARYNINJACOREAPI void BNFreeSection(BNSection* section);
+ BINARYNINJACOREAPI BNSection** BNGetSections(BNBinaryView* view, size_t* count);
+ BINARYNINJACOREAPI BNSection** BNGetSectionsAt(BNBinaryView* view, uint64_t addr, size_t* count);
+ BINARYNINJACOREAPI void BNFreeSectionList(BNSection** sections, size_t count);
+ BINARYNINJACOREAPI BNSection* BNGetSectionByName(BNBinaryView* view, const char* name);
BINARYNINJACOREAPI char** BNGetUniqueSectionNames(BNBinaryView* view, const char** names, size_t count);
@@ -2077,7 +2124,6 @@ extern "C"
BINARYNINJACOREAPI BNBinaryView* BNCreateCustomBinaryView(const char* name, BNFileMetadata* file,
BNBinaryView* parent, BNCustomBinaryView* view);
- // Binary view type management
BINARYNINJACOREAPI BNBinaryViewType* BNGetBinaryViewTypeByName(const char* name);
BINARYNINJACOREAPI BNBinaryViewType** BNGetBinaryViewTypes(size_t* count);
BINARYNINJACOREAPI BNBinaryViewType** BNGetBinaryViewTypesForData(BNBinaryView* data, size_t* count);
@@ -2183,7 +2229,7 @@ extern "C"
BINARYNINJACOREAPI size_t BNGetArchitectureOpcodeDisplayLength(BNArchitecture* arch);
BINARYNINJACOREAPI BNArchitecture* BNGetAssociatedArchitectureByAddress(BNArchitecture* arch, uint64_t* addr);
BINARYNINJACOREAPI bool BNGetInstructionInfo(BNArchitecture* arch, const uint8_t* data, uint64_t addr,
- size_t maxLen, BNInstructionInfo* result);
+ size_t maxLen, BNInstructionInfo* result);
BINARYNINJACOREAPI bool BNGetInstructionText(BNArchitecture* arch, const uint8_t* data, uint64_t addr,
size_t* len, BNInstructionTextToken** result, size_t* count);
BINARYNINJACOREAPI bool BNGetInstructionLowLevelIL(BNArchitecture* arch, const uint8_t* data, uint64_t addr,
@@ -2262,9 +2308,7 @@ extern "C"
BINARYNINJACOREAPI bool BNArchitectureInvertBranch(BNArchitecture* arch, uint8_t* data, uint64_t addr, size_t len);
BINARYNINJACOREAPI bool BNArchitectureSkipAndReturnValue(BNArchitecture* arch, uint8_t* data, uint64_t addr,
size_t len, uint64_t value);
-
BINARYNINJACOREAPI void BNRegisterArchitectureFunctionRecognizer(BNArchitecture* arch, BNFunctionRecognizer* rec);
-
BINARYNINJACOREAPI bool BNIsBinaryViewTypeArchitectureConstantDefined(BNArchitecture* arch, const char* type,
const char* name);
BINARYNINJACOREAPI uint64_t BNGetBinaryViewTypeArchitectureConstant(BNArchitecture* arch, const char* type,
@@ -2272,6 +2316,18 @@ extern "C"
BINARYNINJACOREAPI void BNSetBinaryViewTypeArchitectureConstant(BNArchitecture* arch, const char* type,
const char* name, uint64_t value);
+ BINARYNINJACOREAPI void BNArchitectureRegisterRelocationHandler(BNArchitecture* arch, const char* viewName,
+ BNRelocationHandler* handler);
+ BINARYNINJACOREAPI BNRelocationHandler* BNCreateRelocationHandler(BNCustomRelocationHandler* handler);
+ BINARYNINJACOREAPI BNRelocationHandler* BNArchitectureGetRelocationHandler(BNArchitecture* arch, const char* viewName);
+ BINARYNINJACOREAPI BNRelocationHandler* BNNewRelocationHandlerReference(BNRelocationHandler* handler);
+ BINARYNINJACOREAPI void BNFreeRelocationHandler(BNRelocationHandler* handler);
+ BINARYNINJACOREAPI bool BNRelocationHandlerGetRelocationInfo(BNRelocationHandler* handler, BNBinaryView* data,
+ BNArchitecture* arch, BNRelocationInfo* info, size_t infoCount);
+ BINARYNINJACOREAPI bool BNRelocationHandlerApplyRelocation(BNRelocationHandler* handler, BNBinaryView* view,
+ BNArchitecture* arch, BNRelocation* reloc, uint8_t* dest, size_t len);
+ BINARYNINJACOREAPI bool BNRelocationHandlerDefaultApplyRelocation(BNRelocationHandler* handler, BNBinaryView* view,
+ BNArchitecture* arch, BNRelocation* reloc, uint8_t* dest, size_t len);
// Analysis
BINARYNINJACOREAPI void BNAddAnalysisOption(BNBinaryView* view, const char* name);
BINARYNINJACOREAPI void BNAddFunctionForAnalysis(BNBinaryView* view, BNPlatform* platform, uint64_t addr);
@@ -3540,6 +3596,54 @@ extern "C"
BINARYNINJACOREAPI BNMetadata* BNBinaryViewQueryMetadata(BNBinaryView* view, const char* key);
BINARYNINJACOREAPI void BNBinaryViewRemoveMetadata(BNBinaryView* view, const char* key);
+
+ // Relocation object methods
+ BINARYNINJACOREAPI BNRelocation* BNNewRelocationReference(BNRelocation* reloc);
+ BINARYNINJACOREAPI void BNFreeRelocation(BNRelocation* reloc);
+ BINARYNINJACOREAPI BNRelocationInfo BNRelocationGetInfo(BNRelocation* reloc);
+ BINARYNINJACOREAPI BNArchitecture* BNRelocationGetArchitecture(BNRelocation* reloc);
+ BINARYNINJACOREAPI uint64_t BNRelocationGetTarget(BNRelocation* reloc);
+ BINARYNINJACOREAPI uint64_t BNRelocationGetReloc(BNRelocation* reloc);
+ BINARYNINJACOREAPI BNSymbol* BNRelocationGetSymbol(BNRelocation* reloc);
+ // Segment object methods
+ BINARYNINJACOREAPI BNSegment* BNCreateSegment(uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags,
+ bool autoDefined);
+ BINARYNINJACOREAPI BNSegment* BNNewSegmentReference(BNSegment* seg);
+ BINARYNINJACOREAPI void BNFreeSegment(BNSegment* seg);
+
+ BINARYNINJACOREAPI BNRange* BNSegmentGetRelocationRanges(BNSegment* segment, size_t* count);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetRelocationsCount(BNSegment* segment);
+ BINARYNINJACOREAPI BNRange* BNSegmentGetRelocationRangesAtAddress(BNSegment* segment, uint64_t addr, size_t* count);
+ BINARYNINJACOREAPI void BNFreeRelocationRanges(BNRange* ranges);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetStart(BNSegment* segment);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetLength(BNSegment* segment);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetEnd(BNSegment* segment);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetDataEnd(BNSegment* segment);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetDataOffset(BNSegment* segment);
+ BINARYNINJACOREAPI uint64_t BNSegmentGetDataLength(BNSegment* segment);
+ BINARYNINJACOREAPI uint32_t BNSegmentGetFlags(BNSegment* segment);
+ BINARYNINJACOREAPI bool BNSegmentIsAutoDefined(BNSegment* segment);
+ BINARYNINJACOREAPI void BNSegmentSetLength(BNSegment* segment, uint64_t length);
+ BINARYNINJACOREAPI void BNSegmentSetDataOffset(BNSegment* segment, uint64_t dataOffset);
+ BINARYNINJACOREAPI void BNSegmentSetDataLength(BNSegment* segment, uint64_t dataLength);
+ BINARYNINJACOREAPI void BNSegmentSetFlags(BNSegment* segment, uint32_t flags);
+ BINARYNINJACOREAPI size_t BNSegmentRead(BNSegment* segment, BNBinaryView* view, uint8_t* dest, uint64_t offset, size_t len);
+
+ // Section object methods
+ BINARYNINJACOREAPI BNSection* BNNewSectionReference(BNSection* section);
+ BINARYNINJACOREAPI void BNFreeSection(BNSection* section);
+ BINARYNINJACOREAPI char* BNSectionGetName(BNSection* section);
+ BINARYNINJACOREAPI char* BNSectionGetType(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetStart(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetLength(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetEnd(BNSection* section);
+ BINARYNINJACOREAPI char* BNSectionGetLinkedSection(BNSection* section);
+ BINARYNINJACOREAPI char* BNSectionGetInfoSection(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetInfoData(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetAlign(BNSection* section);
+ BINARYNINJACOREAPI uint64_t BNSectionGetEntrySize(BNSection* section);
+ BINARYNINJACOREAPI BNSectionSemantics BNSectionGetSemantics(BNSection* section);
+ BINARYNINJACOREAPI bool BNSectionIsAutoDefined(BNSection* section);
#ifdef __cplusplus
}
#endif