diff options
Diffstat (limited to 'binaryninjacore.h')
| -rw-r--r-- | binaryninjacore.h | 167 |
1 files changed, 131 insertions, 36 deletions
diff --git a/binaryninjacore.h b/binaryninjacore.h index e4d3a919..202684a8 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -142,6 +142,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); @@ -264,7 +269,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 @@ -1037,6 +1052,10 @@ 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, BNSymbol* sym, + uint64_t symOffset, BNSegment* seg, uint64_t segOffset); + void (*defineSectionRelocation) (void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSection* sec, + uint64_t secOffset, BNSegment* seg, uint64_t segOffset); }; struct BNCustomBinaryViewType @@ -1079,6 +1098,32 @@ 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 + }; + struct BNInstructionTextToken { BNInstructionTextTokenType type; @@ -1330,6 +1375,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; @@ -1678,33 +1734,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, + ExternalCodeSectionSemantics }; struct BNAddressRange @@ -1937,6 +1973,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); @@ -1957,7 +1994,10 @@ 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, + BNSymbol* sym, uint64_t symOffset, BNSegment* seg, uint64_t segOffset); + BINARYNINJACOREAPI void BNDefineSectionRelocation(BNBinaryView* view, BNArchitecture* arch, BNRelocationInfo* info, + BNSection* sec, uint64_t secOffset, BNSegment* seg, uint64_t segOffset); BINARYNINJACOREAPI void BNRegisterDataNotification(BNBinaryView* view, BNBinaryDataNotification* notify); BINARYNINJACOREAPI void BNUnregisterDataNotification(BNBinaryView* view, BNBinaryDataNotification* notify); @@ -1983,9 +2023,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, @@ -1996,11 +2036,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); @@ -2020,7 +2059,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); @@ -2126,7 +2164,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, @@ -2205,9 +2243,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, @@ -2215,6 +2251,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); @@ -3462,6 +3510,53 @@ extern "C" BINARYNINJACOREAPI char* BNGetLinuxCADirectory(); BINARYNINJACOREAPI char* BNGetLinuxCABundlePath(); + + // Relocation object methods + BINARYNINJACOREAPI BNRelocation* BNNewRelocationReference(BNRelocation* reloc); + BINARYNINJACOREAPI void BNFreeRelocation(BNRelocation* reloc); + BINARYNINJACOREAPI BNRelocationInfo BNRelocationGetInfo(BNRelocation* reloc); + BINARYNINJACOREAPI BNArchitecture* BNRelocationGetArchitecture(BNRelocation* reloc); + BINARYNINJACOREAPI BNSymbol* BNRelocationGetSymbol(BNRelocation* reloc); + BINARYNINJACOREAPI uint64_t BNRelocationGetSymbolOffset(BNRelocation* reloc); + BINARYNINJACOREAPI uint64_t BNRelocationGetTargetAddress(BNRelocation* reloc); + BINARYNINJACOREAPI BNSegment* BNRelocationGetSegment(BNRelocation* reloc); + BINARYNINJACOREAPI uint64_t BNRelocationGetSegmentOffset(BNRelocation* reloc); + BINARYNINJACOREAPI uint64_t BNRelocationGetDestAddress(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 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 |
