summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--architecture.cpp104
-rw-r--r--binaryninjaapi.h101
-rw-r--r--binaryninjacore.h155
-rw-r--r--binaryview.cpp322
-rw-r--r--python/binaryview.py134
-rw-r--r--python/types.py11
6 files changed, 644 insertions, 183 deletions
diff --git a/architecture.cpp b/architecture.cpp
index 821f4c7b..78c41dd3 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -140,8 +140,8 @@ BNArchitecture* Architecture::GetAssociatedArchitectureByAddressCallback(void* c
}
-bool Architecture::GetInstructionInfoCallback(void* ctxt, const uint8_t* data, uint64_t addr,
- size_t maxLen, BNInstructionInfo* result)
+bool Architecture::GetInstructionInfoCallback(void* ctxt, const uint8_t* data, uint64_t addr, size_t maxLen,
+ BNInstructionInfo* result)
{
Architecture* arch = (Architecture*)ctxt;
@@ -152,6 +152,19 @@ bool Architecture::GetInstructionInfoCallback(void* ctxt, const uint8_t* data, u
}
+bool Architecture::GetRelocationInfoCallback(void* ctxt, BNBinaryView* view, uint64_t relocType,
+ BNRelocationInfo* result)
+{
+ Architecture* arch = (Architecture*)ctxt;
+
+ BNRelocationInfo info = *result;
+ Ref<BinaryView> bv = new BinaryView(BNNewViewReference(view));
+ bool ok = arch->GetRelocationInfo(bv, relocType, info);
+ *result = info;
+ return ok;
+}
+
+
bool Architecture::GetInstructionTextCallback(void* ctxt, const uint8_t* data, uint64_t addr,
size_t* len, BNInstructionTextToken** result, size_t* count)
{
@@ -443,6 +456,33 @@ bool Architecture::SkipAndReturnValueCallback(void* ctxt, uint8_t* data, uint64_
}
+// bool Architecture::ApplyPERelocationCallback(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len)
+// {
+// Architecture* arch = (Architecture*)ctxt;
+// Ref<BinaryView> bv = new BinaryView(BNNewViewReference(view));
+// Ref<Relocation> reloc = new Relocation(BNNewRelocationReference(rel));
+// return arch->ApplyPERelocation(bv, reloc, data, len);
+// }
+
+
+bool Architecture::ApplyELFRelocationCallback(void* ctxt, BNBinaryView* view, BNRelocationInfo* rel, uint8_t* data, size_t len)
+{
+ Architecture* arch = (Architecture*)ctxt;
+ Ref<BinaryView> bv = new BinaryView(BNNewViewReference(view));
+ BNRelocationInfo reloc = *rel;
+ return arch->ApplyELFRelocation(bv, reloc, data, len);
+}
+
+
+// bool Architecture::ApplyMachoRelocationCallback(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len)
+// {
+// Architecture* arch = (Architecture*)ctxt;
+// Ref<BinaryView> bv = new BinaryView(BNNewViewReference(view));
+// Ref<Relocation> reloc = new Relocation(BNNewRelocationReference(rel));
+// return arch->ApplyMachoRelocation(bv, reloc, data, len);
+// }
+
+
void Architecture::Register(Architecture* arch)
{
BNCustomArchitecture callbacks;
@@ -486,6 +526,11 @@ void Architecture::Register(Architecture* arch)
callbacks.alwaysBranch = AlwaysBranchCallback;
callbacks.invertBranch = InvertBranchCallback;
callbacks.skipAndReturnValue = SkipAndReturnValueCallback;
+ // callbacks.applyPERelocation = ApplyPERelocationCallback;
+ callbacks.applyELFRelocation = ApplyELFRelocationCallback;
+ // callbacks.applyMachoRelocation = ApplyMachoRelocationCallback;
+ callbacks.getRelocationInfo = GetRelocationInfoCallback;
+
arch->AddRefForRegistration();
BNRegisterArchitecture(arch->m_nameForRegister.c_str(), &callbacks);
}
@@ -897,6 +942,37 @@ Ref<Platform> Architecture::GetStandalonePlatform()
}
+// bool Architecture::ApplyPERelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len)
+// {
+// (void)view;
+// (void)rel;
+// (void)dest;
+// (void)len;
+// return true;
+// }
+
+
+bool Architecture::ApplyELFRelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len)
+{
+ (void)view;
+ (void)rel;
+ (void)dest;
+ (void)len;
+
+ return true;
+}
+
+
+// bool Architecture::ApplyMachoRelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len)
+// {
+// (void)view;
+// (void)rel;
+// (void)dest;
+// (void)len;
+// return true;
+// }
+
+
CoreArchitecture::CoreArchitecture(BNArchitecture* arch): Architecture(arch)
{
}
@@ -1202,3 +1278,27 @@ bool CoreArchitecture::SkipAndReturnValue(uint8_t* data, uint64_t addr, size_t l
{
return BNArchitectureSkipAndReturnValue(m_object, data, addr, len, value);
}
+
+
+// bool CoreArchitecture::ApplyPERelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len)
+// {
+// return BNArchitectureApplyPERelocation(m_object, view->GetObject(), rel->GetObject(), dest, len);
+// }
+
+
+bool CoreArchitecture::ApplyELFRelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len)
+{
+ return BNArchitectureApplyELFRelocation(m_object, view->GetObject(), &rel, dest, len);
+}
+
+
+// bool CoreArchitecture::ApplyMachoRelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len)
+// {
+// return BNArchitectureApplyMachoRelocation(m_object, view->GetObject(), rel->GetObject(), dest, len);
+// }
+
+
+bool CoreArchitecture::GetRelocationInfo(BinaryView* view, uint64_t relocType, BNRelocationInfo& reloc)
+{
+ return BNGetRelocationInfo(m_object, view->GetObject(), relocType, &reloc);
+} \ No newline at end of file
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 31bd2316..7fabe042 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -850,7 +850,6 @@ namespace BinaryNinja
BinaryNinja::Ref<BinaryNinja::BinaryView> GetViewOfType(const std::string& name);
};
- class BinaryView;
class Function;
struct DataVariable;
@@ -930,13 +929,13 @@ 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(const std::string& shortName, const std::string& fullName, const std::string& rawName, SymbolBinding binding, size_t size);
+ //Symbol(const std::string& name, SymbolBinding binding, size_t size);
Symbol(BNSymbol* sym);
BNSymbolType GetType() const;
@@ -1025,28 +1024,50 @@ 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;
+
+ 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;
@@ -1097,7 +1118,10 @@ namespace BinaryNinja
virtual size_t PerformGetAddressSize() const;
virtual bool PerformSave(FileAccessor* file);
-
+ void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Symbol> sym, uint64_t symOffset,
+ const Ref<Segment> seg, uint64_t segOffset);
+ void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Section> sec, uint64_t secOffset,
+ const Ref<Segment> seg, uint64_t segOffset);
void NotifyDataWritten(uint64_t offset, size_t len);
void NotifyDataInserted(uint64_t offset, size_t len);
void NotifyDataRemoved(uint64_t offset, uint64_t len);
@@ -1124,7 +1148,10 @@ 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, BNSymbol* sym,
+ uint64_t symOffset, BNSegment* seg, uint64_t segOffset);
+ static void DefineSectionRelocationCallback(void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSection* sec,
+ uint64_t secOffset, BNSegment* seg, uint64_t segOffset);
public:
BinaryView(BNBinaryView* view);
@@ -1175,6 +1202,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;
@@ -1196,6 +1224,10 @@ namespace BinaryNinja
bool Save(FileAccessor* file);
bool Save(const std::string& path);
+ void DefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Symbol> sym, uint64_t symOffset,
+ const Ref<Segment> seg, uint64_t segOffset);
+ void DefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Section> sec, uint64_t secOffset,
+ const Ref<Segment> seg, uint64_t segOffset);
void RegisterNotification(BinaryDataNotification* notify);
void UnregisterNotification(BinaryDataNotification* notify);
@@ -1313,8 +1345,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,
@@ -1327,9 +1359,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);
@@ -1633,6 +1665,11 @@ namespace BinaryNinja
static bool InvertBranchCallback(void* ctxt, uint8_t* data, uint64_t addr, size_t len);
static bool SkipAndReturnValueCallback(void* ctxt, uint8_t* data, uint64_t addr, size_t len, uint64_t value);
+ // static bool ApplyPERelocationCallback(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len);
+ static bool ApplyELFRelocationCallback(void* ctxt, BNBinaryView* view, BNRelocationInfo* rel, uint8_t* data, size_t len);
+ // static bool ApplyMachoRelocationCallback(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len);
+ static bool GetRelocationInfoCallback(void* ctxt, BNBinaryView* view, uint64_t relocType, BNRelocationInfo* result);
+
public:
Architecture(const std::string& name);
@@ -1778,6 +1815,15 @@ namespace BinaryNinja
Ref<CallingConvention> GetStdcallCallingConvention();
Ref<CallingConvention> GetFastcallCallingConvention();
Ref<Platform> GetStandalonePlatform();
+
+ //virtual bool ApplyPERelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len);
+ virtual bool ApplyELFRelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len);
+ // virtual bool ApplyMachoRelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len);
+ virtual bool GetRelocationInfo(BinaryView* view, uint64_t relocType, BNRelocationInfo& result)
+ {
+ (void)view; (void)relocType; (void)result;
+ return false;
+ }
};
class CoreArchitecture: public Architecture
@@ -1825,6 +1871,11 @@ namespace BinaryNinja
virtual bool AlwaysBranch(uint8_t* data, uint64_t addr, size_t len) override;
virtual bool InvertBranch(uint8_t* data, uint64_t addr, size_t len) override;
virtual bool SkipAndReturnValue(uint8_t* data, uint64_t addr, size_t len, uint64_t value) override;
+
+ //virtual bool ApplyPERelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len) override;
+ virtual bool ApplyELFRelocation(BinaryView* view, BNRelocationInfo& rel, uint8_t* dest, size_t len) override;
+ //virtual bool ApplyMachoRelocation(BinaryView* view, Relocation* rel, uint8_t* dest, size_t len) override;
+ virtual bool GetRelocationInfo(BinaryView* view, uint64_t relocType, BNRelocationInfo& result) override;
};
class Structure;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 245e6353..4abbbbdb 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -142,6 +142,10 @@ extern "C"
struct BNRepoPlugin;
struct BNRepositoryManager;
struct BNMetadata;
+ struct BNRelocation;
+ struct BNSegment;
+ struct BNSection;
+ struct BNRelocationInfo;
typedef bool (*BNLoadPluginCallback)(const char* repoPath, const char* pluginPath, void* ctx);
@@ -264,7 +268,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
@@ -914,6 +928,15 @@ extern "C"
size_t (*write)(void* ctxt, uint64_t offset, const void* src, size_t len);
};
+ enum BNRelocationType
+ {
+ ELFGlobalRelocationType,
+ ELFCopyRelocationType,
+ ELFJumpSlotRelocationType,
+ StandardRelocationType,
+ CustomRelocationType
+ };
+
struct BNCustomBinaryView
{
void* context;
@@ -938,6 +961,19 @@ 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 BNCustomRelocation
+ {
+ void* context;
+ BNArchitecture* arch;
+ bool (*init)(void* ctxt);
+ void (*freeRelocation)(void* ctxt);
+ bool (*applyRelocation)(void* ctxt, BNBinaryView* view, uint8_t* dest, size_t len);
};
struct BNCustomBinaryViewType
@@ -980,6 +1016,25 @@ extern "C"
BNArchitecture* branchArch[BN_MAX_INSTRUCTION_BRANCHES]; // If null, same architecture as instruction
};
+ enum BNRelativeRelocationType
+ {
+ NotRelativeRelocationType,
+ SegmentRelativeRelocationType,
+ BaseRelativeRelocationType
+ };
+
+ struct BNRelocationInfo
+ {
+ BNRelocationType bnType; // BinaryNinja Relocation Type
+ BNRelativeRelocationType relative; // Relative to base/symbol or Absolute
+ bool hasSign; // Addend should be subtracted
+ size_t size; // Size of the data to be written
+ size_t truncateSize; // After addition/subtraction truncate to
+ uint64_t type; // Base type from relocation entry
+ size_t addend; // Addend value from relocation entry
+ bool implicitAddend; // Addend should be read from the BinaryView
+ };
+
struct BNInstructionTextToken
{
BNInstructionTextTokenType type;
@@ -1044,6 +1099,11 @@ extern "C"
bool (*alwaysBranch)(void* ctxt, uint8_t* data, uint64_t addr, size_t len);
bool (*invertBranch)(void* ctxt, uint8_t* data, uint64_t addr, size_t len);
bool (*skipAndReturnValue)(void* ctxt, uint8_t* data, uint64_t addr, size_t len, uint64_t value);
+
+ //bool (*applyPERelocation)(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len);
+ bool (*applyELFRelocation)(void* ctxt, BNBinaryView* view, BNRelocationInfo* rel, uint8_t* data, size_t len);
+ //bool (*applyMachoRelocation)(void* ctxt, BNBinaryView* view, BNRelocation* rel, uint8_t* data, size_t len);
+ bool (*getRelocationInfo)(void* ctxt, BNBinaryView* view, uint64_t relocType, BNRelocationInfo* result);
};
struct BNBasicBlockEdge
@@ -1526,33 +1586,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
@@ -1771,6 +1811,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);
@@ -1791,7 +1832,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);
@@ -1817,9 +1861,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,
@@ -1830,11 +1874,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);
@@ -1854,6 +1897,11 @@ extern "C"
BINARYNINJACOREAPI BNBinaryView* BNCreateCustomBinaryView(const char* name, BNFileMetadata* file,
BNBinaryView* parent, BNCustomBinaryView* view);
+ // Creation of new types of relocations
+ // BINARYNINJACOREAPI BNRelocation* BNCreateRelocation(BNArchitecture* arch, size_t size, BNSymbol* sym, uint64_t addend,
+ // uint64_t segmentOffset, BNCustomRelocation* reloc);
+ // BINARYNINJACOREAPI BNRelocation* BNNewRelocationReference(BNRelocation* reloc);
+ // BINARYNINJACOREAPI void BNFreeRelocation(BNRelocation* reloc);
// Binary view type management
BINARYNINJACOREAPI BNBinaryViewType* BNGetBinaryViewTypeByName(const char* name);
BINARYNINJACOREAPI BNBinaryViewType** BNGetBinaryViewTypes(size_t* count);
@@ -1956,7 +2004,9 @@ 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 BNGetRelocationInfo(BNArchitecture* arch, BNBinaryView* view, uint64_t relocType,
+ BNRelocationInfo* 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,
@@ -2010,7 +2060,9 @@ 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 bool BNArchitectureApplyPERelocation(BNArchitecture* arch, BNBinaryView* view, BNRelocation* rel, uint8_t* dest, size_t len);
+ BINARYNINJACOREAPI bool BNArchitectureApplyELFRelocation(BNArchitecture* arch, BNBinaryView* view, BNRelocationInfo* rel, uint8_t* dest, size_t len);
+ //BINARYNINJACOREAPI bool BNArchitectureApplyMachoRelocation(BNArchitecture* arch, BNBinaryView* view, BNRelocation* rel, uint8_t* dest, size_t len);
BINARYNINJACOREAPI void BNRegisterArchitectureFunctionRecognizer(BNArchitecture* arch, BNFunctionRecognizer* rec);
BINARYNINJACOREAPI bool BNIsBinaryViewTypeArchitectureConstantDefined(BNArchitecture* arch, const char* type,
@@ -3191,6 +3243,41 @@ extern "C"
BINARYNINJACOREAPI char* BNGetLinuxCADirectory();
BINARYNINJACOREAPI char* BNGetLinuxCABundlePath();
+
+ // Segment Operations
+ 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 bool BNSegmentAddRelocation(BNSegment* segment, BNRelocation* rel);
+ BINARYNINJACOREAPI size_t BNSegmentRead(BNSegment* segment, BNBinaryView* view, uint8_t* dest, uint64_t offset, size_t len);
+
+ 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
diff --git a/binaryview.cpp b/binaryview.cpp
index 00cd294f..24a976e8 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -257,6 +257,165 @@ void AnalysisCompletionEvent::Cancel()
}
+Segment::Segment(BNSegment* seg)
+{
+ m_object = seg;
+}
+
+
+uint64_t Segment::GetStart() const
+{
+ return BNSegmentGetStart(m_object);
+}
+
+
+uint64_t Segment::GetLength() const
+{
+ return BNSegmentGetLength(m_object);
+}
+
+
+uint64_t Segment::GetEnd() const
+{
+ return BNSegmentGetEnd(m_object);
+}
+
+
+uint64_t Segment::GetDataEnd() const
+{
+ return BNSegmentGetDataEnd(m_object);
+}
+
+
+uint64_t Segment::GetDataOffset() const
+{
+ return BNSegmentGetDataOffset(m_object);
+}
+
+
+uint64_t Segment::GetDataLength() const
+{
+ return BNSegmentGetDataLength(m_object);
+}
+
+
+uint32_t Segment::GetFlags() const
+{
+ return BNSegmentGetFlags(m_object);
+}
+
+
+bool Segment::IsAutoDefined() const
+{
+ return BNSegmentIsAutoDefined(m_object);
+}
+
+
+void Segment::SetLength(uint64_t length)
+{
+ BNSegmentSetLength(m_object, length);
+}
+
+
+void Segment::SetDataOffset(uint64_t dataOffset)
+{
+ BNSegmentSetDataOffset(m_object, dataOffset);
+}
+
+
+void Segment::SetDataLength(uint64_t dataLength)
+{
+ BNSegmentSetDataLength(m_object, dataLength);
+}
+
+
+void Segment::SetFlags(uint64_t flags)
+{
+ BNSegmentSetFlags(m_object, flags);
+}
+
+
+size_t Segment::Read(BinaryView* view, uint8_t* dest, uint64_t offset, size_t len)
+{
+ return BNSegmentRead(m_object, view->GetObject(), dest, offset, len);
+}
+
+
+Section::Section(BNSection* sec)
+{
+ m_object = sec;
+}
+
+
+std::string Section::GetName() const
+{
+ return BNSectionGetName(m_object);
+}
+
+
+std::string Section::GetType() const
+{
+ return BNSectionGetType(m_object);
+}
+
+
+uint64_t Section::GetStart() const
+{
+ return BNSectionGetStart(m_object);
+}
+
+
+uint64_t Section::GetLength() const
+{
+ return BNSectionGetLength(m_object);
+}
+
+
+uint64_t Section::GetInfoData() const
+{
+ return BNSectionGetInfoData(m_object);
+}
+
+
+uint64_t Section::GetAlignment() const
+{
+ return BNSectionGetAlign(m_object);
+}
+
+
+uint64_t Section::GetEntrySize() const
+{
+ return BNSectionGetEntrySize(m_object);
+}
+
+
+std::string Section::GetLinkedSection() const
+{
+ return BNSectionGetLinkedSection(m_object);
+}
+
+
+std::string Section::GetInfoSection() const
+{
+ return BNSectionGetInfoSection(m_object);
+}
+
+
+BNSectionSemantics Section::GetSemantics() const
+{
+ return BNSectionGetSemantics(m_object);
+}
+
+
+bool Section::AutoDefined() const
+{
+ return BNSectionIsAutoDefined(m_object);
+}
+
+
+
+
+
BinaryView::BinaryView(const std::string& typeName, FileMetadata* file, BinaryView* parentView)
{
BNCustomBinaryView view;
@@ -282,7 +441,8 @@ BinaryView::BinaryView(const std::string& typeName, FileMetadata* file, BinaryVi
view.isRelocatable = IsRelocatableCallback;
view.getAddressSize = GetAddressSizeCallback;
view.save = SaveCallback;
-
+ view.defineRelocation = DefineRelocationCallback;
+ view.defineSectionRelocation = DefineSectionRelocationCallback;
m_file = file;
AddRefForRegistration();
m_object = BNCreateCustomBinaryView(typeName.c_str(), m_file->GetObject(),
@@ -445,6 +605,30 @@ bool BinaryView::SaveCallback(void* ctxt, BNFileAccessor* file)
}
+void BinaryView::DefineRelocationCallback(void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSymbol* sym,
+ uint64_t symOffset, BNSegment* seg, uint64_t segOffset)
+{
+ BinaryView* view = (BinaryView*)ctxt;
+ Architecture* curArch = new CoreArchitecture(arch);
+ BNRelocationInfo curInfo = *info;
+ Ref<Symbol> curSym = new Symbol(sym);
+ Ref<Segment> curSeg = new Segment(seg);
+ return view->PerformDefineRelocation(curArch, curInfo, curSym, symOffset, curSeg, segOffset);
+}
+
+
+void BinaryView::DefineSectionRelocationCallback(void* ctxt, BNArchitecture* arch, BNRelocationInfo* info, BNSection* sec,
+ uint64_t secOffset, BNSegment* seg, uint64_t segOffset)
+{
+ BinaryView* view = (BinaryView*)ctxt;
+ Architecture* curArch = new CoreArchitecture(arch);
+ BNRelocationInfo curInfo = *info;
+ Ref<Section> curSec = new Section(sec);
+ Ref<Segment> curSeg = new Segment(seg);
+ return view->PerformDefineRelocation(curArch, curInfo, curSec, secOffset, curSeg, segOffset);
+}
+
+
bool BinaryView::PerformIsValidOffset(uint64_t offset)
{
uint8_t val;
@@ -518,6 +702,26 @@ bool BinaryView::PerformSave(FileAccessor* file)
}
+void BinaryView::PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Symbol> sym,
+ uint64_t symOffset, const Ref<Segment> seg, uint64_t segOffset)
+{
+ Ref<BinaryView> parent = GetParentView();
+ if (parent)
+ parent->DefineRelocation(arch, info, sym, symOffset, seg, segOffset);
+ return;
+}
+
+
+void BinaryView::PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Section> sec,
+ uint64_t secOffset, const Ref<Segment> seg, uint64_t segOffset)
+{
+ Ref<BinaryView> parent = GetParentView();
+ if (parent)
+ parent->DefineRelocation(arch, info, sec, secOffset, seg, segOffset);
+ return;
+}
+
+
void BinaryView::NotifyDataWritten(uint64_t offset, size_t len)
{
BNNotifyDataWritten(m_object, offset, len);
@@ -690,6 +894,20 @@ bool BinaryView::Save(const string& path)
}
+void BinaryView::DefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Symbol> sym,
+ uint64_t symOffset, const Ref<Segment> seg, uint64_t segOffset)
+{
+ BNDefineRelocation(m_object, arch->GetObject(), &info, sym->GetObject(), symOffset, seg->GetObject(), segOffset);
+}
+
+
+void BinaryView::DefineRelocation(Architecture* arch, BNRelocationInfo& info, const Ref<Section> sec,
+ uint64_t secOffset, const Ref<Segment> seg, uint64_t segOffset)
+{
+ BNDefineSectionRelocation(m_object, arch->GetObject(), &info, sec->GetObject(), secOffset, seg->GetObject(), segOffset);
+}
+
+
void BinaryView::RegisterNotification(BinaryDataNotification* notify)
{
BNRegisterDataNotification(m_object, notify->GetCallbacks());
@@ -768,6 +986,12 @@ bool BinaryView::IsOffsetCodeSemantics(uint64_t offset) const
}
+bool BinaryView::IsOffsetExternSemantics(uint64_t offset) const
+{
+ return BNIsOffsetExternSemantics(m_object, offset);
+}
+
+
bool BinaryView::IsOffsetWritableSemantics(uint64_t offset) const
{
return BNIsOffsetWritableSemantics(m_object, offset);
@@ -1698,40 +1922,27 @@ void BinaryView::RemoveUserSegment(uint64_t start, uint64_t length)
}
-vector<Segment> BinaryView::GetSegments()
+vector<Ref<Segment>> BinaryView::GetSegments()
{
size_t count;
- BNSegment* segments = BNGetSegments(m_object, &count);
+ BNSegment** segments = BNGetSegments(m_object, &count);
- vector<Segment> result;
+ vector<Ref<Segment>> result;
for (size_t i = 0; i < count; i++)
- {
- Segment segment;
- segment.start = segments[i].start;
- segment.length = segments[i].length;
- segment.dataOffset = segments[i].dataOffset;
- segment.dataLength = segments[i].dataLength;
- segment.flags = segments[i].flags;
- segment.autoDefined = segments[i].autoDefined;
- result.push_back(segment);
- }
+ result.push_back(new Segment(BNNewSegmentReference(segments[i])));
- BNFreeSegmentList(segments);
+ BNFreeSegmentList(segments, count);
return result;
}
-bool BinaryView::GetSegmentAt(uint64_t addr, Segment& result)
+
+Ref<Segment> BinaryView::GetSegmentAt(uint64_t addr)
{
- BNSegment segment;
- if (!BNGetSegmentAt(m_object, addr, &segment))
- return false;
+ BNSegment* segment = BNGetSegmentAt(m_object, addr);
+ if (!segment)
+ return nullptr;
- result.start = segment.start;
- result.length = segment.length;
- result.dataOffset = segment.dataOffset;
- result.dataLength = segment.dataLength;
- result.flags = segment.flags;
- return true;
+ return new Segment(BNNewSegmentReference(segment));
}
@@ -1771,53 +1982,29 @@ void BinaryView::RemoveUserSection(const string& name)
}
-vector<Section> BinaryView::GetSections()
+vector<Ref<Section>> BinaryView::GetSections()
{
size_t count;
- BNSection* sections = BNGetSections(m_object, &count);
+ BNSection** sections = BNGetSections(m_object, &count);
- vector<Section> result;
+ vector<Ref<Section>> result;
for (size_t i = 0; i < count; i++)
- {
- Section section;
- section.name = sections[i].name;
- section.type = sections[i].type;
- section.start = sections[i].start;
- section.length = sections[i].length;
- section.linkedSection = sections[i].linkedSection;
- section.infoSection = sections[i].infoSection;
- section.infoData = sections[i].infoData;
- section.align = sections[i].align;
- section.entrySize = sections[i].entrySize;
- section.semantics = sections[i].semantics;
- result.push_back(section);
- }
+ result.push_back(new Section(BNNewSectionReference(sections[i])));
BNFreeSectionList(sections, count);
return result;
}
-vector<Section> BinaryView::GetSectionsAt(uint64_t addr)
+vector<Ref<Section>> BinaryView::GetSectionsAt(uint64_t addr)
{
size_t count;
- BNSection* sections = BNGetSectionsAt(m_object, addr, &count);
+ BNSection** sections = BNGetSectionsAt(m_object, addr, &count);
- vector<Section> result;
+ vector<Ref<Section>> result;
for (size_t i = 0; i < count; i++)
{
- Section section;
- section.name = sections[i].name;
- section.type = sections[i].type;
- section.start = sections[i].start;
- section.length = sections[i].length;
- section.linkedSection = sections[i].linkedSection;
- section.infoSection = sections[i].infoSection;
- section.infoData = sections[i].infoData;
- section.align = sections[i].align;
- section.entrySize = sections[i].entrySize;
- section.semantics = sections[i].semantics;
- result.push_back(section);
+ result.push_back(new Section(BNNewSectionReference(sections[i])));
}
BNFreeSectionList(sections, count);
@@ -1825,25 +2012,9 @@ vector<Section> BinaryView::GetSectionsAt(uint64_t addr)
}
-bool BinaryView::GetSectionByName(const string& name, Section& result)
+Ref<Section> BinaryView::GetSectionByName(const string& name)
{
- BNSection section;
- if (!BNGetSectionByName(m_object, name.c_str(), &section))
- return false;
-
- result.name = section.name;
- result.type = section.type;
- result.start = section.start;
- result.length = section.length;
- result.linkedSection = section.linkedSection;
- result.infoSection = section.infoSection;
- result.infoData = section.infoData;
- result.align = section.align;
- result.entrySize = section.entrySize;
- result.semantics = section.semantics;
-
- BNFreeSection(&section);
- return true;
+ return new Section(BNGetSectionByName(m_object, name.c_str()));
}
@@ -1919,6 +2090,7 @@ uint64_t BinaryView::GetUIntMetadata(const string& key)
return data->GetUnsignedInteger();
}
+
BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetObject()))
{
}
diff --git a/python/binaryview.py b/python/binaryview.py
index 6eb59db1..19bff9e5 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -416,32 +416,47 @@ class BinaryViewType(object):
class Segment(object):
- def __init__(self, start, length, data_offset, data_length, flags, auto_defined):
- self.start = start
- self.length = length
- self.data_offset = data_offset
- self.data_length = data_length
- self.flags = flags
- self.auto_defined = auto_defined
+ def __init__(self, handle):
+ self.handle = handle
+
+ @property
+ def start(self):
+ return core.BNSegmentGetStart(self.handle)
+
+ @property
+ def end(self):
+ return core.BNSegmentGetEnd(self.handle)
@property
def executable(self):
- return (self.flags & SegmentFlag.SegmentExecutable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentExecutable) != 0
@property
def writable(self):
- return (self.flags & SegmentFlag.SegmentWritable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentWritable) != 0
@property
def readable(self):
- return (self.flags & SegmentFlag.SegmentReadable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentReadable) != 0
@property
def end(self):
- return self.start + self.length
+ return core.BNSegmentGetEnd(self.handle)
+
+ @property
+ def data_length(self):
+ return core.BNSegmentGetDataLength(self.handle)
+
+ @property
+ def data_offset(self):
+ return core.BNSegmentGetDataOffset(self.handle)
+
+ @property
+ def data_end(self):
+ return core.BNSegmentGetDataEnd(self.handle)
def __len__(self):
- return self.length
+ return core.BNSegmentGetLength(self.handle)
def __repr__(self):
return "<segment: %#x-%#x, %s%s%s>" % (self.start, self.end,
@@ -451,25 +466,55 @@ class Segment(object):
class Section(object):
- def __init__(self, name, section_type, start, length, linked_section, info_section, info_data, align, entry_size, semantics, auto_defined):
- self.name = name
- self.type = section_type
- self.start = start
- self.length = length
- self.linked_section = linked_section
- self.info_section = info_section
- self.info_data = info_data
- self.align = align
- self.entry_size = entry_size
- self.semantics = SectionSemantics(semantics)
- self.auto_defined = auto_defined
+ def __init__(self, handle):
+ self.handle = core.handle_of_type(handle, core.BNSection)
+
+ @property
+ def name(self):
+ return core.BNSectionGetName(self.handle)
+
+ @property
+ def type(self):
+ return core.BNSectionGetType(self.handle)
+
+ @property
+ def start(self):
+ return core.BNSectionGetStart(self.handle)
+
+ @property
+ def linked_section(self):
+ return core.BNSectionLinkedSection(self.handle)
+
+ @property
+ def info_section(self):
+ return core.BNSectionInfoSection(self.handle)
+
+ @property
+ def info_data(self):
+ return core.BNSectionInfoData(self.handle)
+
+ @property
+ def align(self):
+ return core.BNSectionAlign(self.handle)
+
+ @property
+ def entry_size(self):
+ return core.BNSectionEntrySize(self.handle)
+
+ @property
+ def semantics(self):
+ return SectionSemantics(core.BNSectionSemantics(self.handle))
+
+ @property
+ def auto_defined(self):
+ return core.BNSectionAutoDefined(self.handle)
@property
def end(self):
- return self.start + self.length
+ return self.start + len(self)
def __len__(self):
- return self.length
+ return core.BNSectionGetLength(self.handle)
def __repr__(self):
return "<section %s: %#x-%#x>" % (self.name, self.start, self.end)
@@ -966,9 +1011,8 @@ class BinaryView(object):
segment_list = core.BNGetSegments(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(Segment(segment_list[i].start, segment_list[i].length,
- segment_list[i].dataOffset, segment_list[i].dataLength, segment_list[i].flags, segment_list[i].autoDefined))
- core.BNFreeSegmentList(segment_list)
+ result.append(Segment(core.BNNewSegmentReference(segment_list[i])))
+ core.BNFreeSegmentList(segment_list, count.value)
return result
@property
@@ -978,10 +1022,7 @@ class BinaryView(object):
section_list = core.BNGetSections(self.handle, count)
result = {}
for i in xrange(0, count.value):
- result[section_list[i].name] = Section(section_list[i].name, section_list[i].type, section_list[i].start,
- section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
- section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
- section_list[i].semantics, section_list[i].autoDefined)
+ result[core.BNSectionGetName(section_list[i])] = Section(section_list[i])
core.BNFreeSectionList(section_list, count.value)
return result
@@ -1796,6 +1837,16 @@ class BinaryView(object):
"""
return core.BNIsOffsetCodeSemantics(self.handle, addr)
+ def is_offset_extern_semantics(self, addr):
+ """
+ ``is_offset_extern_semantics`` checks if an virtual address ``addr`` is semantically valid for external references.
+
+ :param int addr: a virtual address to be checked
+ :return: true if the virtual address is valid for writing, false if the virtual address is invalid or error
+ :rtype: bool
+ """
+ return core.BNIsOffsetExternSemantics(self.handle, addr)
+
def is_offset_writable_semantics(self, addr):
"""
``is_offset_writable_semantics`` checks if an virtual address ``addr`` is semantically writable. Some sections
@@ -3351,12 +3402,10 @@ class BinaryView(object):
core.BNRemoveUserSegment(self.handle, start, length)
def get_segment_at(self, addr):
- segment = core.BNSegment()
- if not core.BNGetSegmentAt(self.handle, addr, segment):
+ seg = core.BNGetSegmentAt(self.handle, addr)
+ if not seg:
return None
- result = Segment(segment.start, segment.length, segment.dataOffset, segment.dataLength,
- segment.flags, segment.autoDefined)
- return result
+ return Segment(seg)
def get_address_for_data_offset(self, offset):
address = ctypes.c_ulonglong()
@@ -3385,10 +3434,7 @@ class BinaryView(object):
section_list = core.BNGetSectionsAt(self.handle, addr, count)
result = []
for i in xrange(0, count.value):
- result.append(Section(section_list[i].name, section_list[i].type, section_list[i].start,
- section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
- section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
- section_list[i].semantics, section_list[i].autoDefined))
+ result.append(Section(section_list[i]))
core.BNFreeSectionList(section_list, count.value)
return result
@@ -3396,9 +3442,7 @@ class BinaryView(object):
section = core.BNSection()
if not core.BNGetSectionByName(self.handle, name, section):
return None
- result = Section(section.name, section.type, section.start, section.length, section.linkedSection,
- section.infoSection, section.infoData, section.align, section.entrySize, section.semantics,
- section_list.autoDefined)
+ result = Section(section)
core.BNFreeSection(section)
return result
diff --git a/python/types.py b/python/types.py
index 49f1fdeb..f5279047 100644
--- a/python/types.py
+++ b/python/types.py
@@ -471,6 +471,7 @@ class Type(object):
:param int width: width of the integer in bytes
:param bool sign: optional variable representing signedness
+ :param string altname: alternate name for type
"""
if sign is None:
sign = BoolWithConfidence(True, confidence = 0)
@@ -484,8 +485,14 @@ class Type(object):
return Type(core.BNCreateIntegerType(width, sign_conf, altname))
@classmethod
- def float(self, width):
- return Type(core.BNCreateFloatType(width))
+ def float(self, width, altname=""):
+ """
+ ``float`` class method for creating an floating point Types.
+
+ :param int width: width of the floating point number in bytes
+ :param string altname: alternate name for type
+ """
+ return Type(core.BNCreateFloatType(width, altname))
@classmethod
def structure_type(self, structure_type):