Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9006,6 +9006,8 @@ namespace BinaryNinja {
Ref<BinaryView> m_view;
BNBinaryReader* m_stream;

BinaryReader(Ref<BinaryView> data, BNBinaryReader* stream);

public:
/*! Create a BinaryReader instance given a BinaryView and endianness.

Expand Down Expand Up @@ -9311,6 +9313,15 @@ namespace BinaryNinja {

*/
bool IsEndOfFile() const;

/*! Create a new reader that represents a bounded slice of this reader

\param offset The start offset for the new slice
\param length The length of the new slice

\return A new reader representing this slice
*/
BinaryReader Slice(uint64_t offset, size_t length) const;
};

/*! Raised whenever a write is performed out of bounds.
Expand Down
1 change: 1 addition & 0 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -5649,6 +5649,7 @@ extern "C"
// Stream reader object
BINARYNINJACOREAPI BNBinaryReader* BNCreateBinaryReader(BNBinaryView* view);
BINARYNINJACOREAPI void BNFreeBinaryReader(BNBinaryReader* stream);
BINARYNINJACOREAPI BNBinaryReader* BNSliceBinaryReader(BNBinaryReader* stream, uint64_t offset, size_t length);
BINARYNINJACOREAPI BNEndianness BNGetBinaryReaderEndianness(BNBinaryReader* stream);
BINARYNINJACOREAPI void BNSetBinaryReaderEndianness(BNBinaryReader* stream, BNEndianness endian);

Expand Down
11 changes: 11 additions & 0 deletions binaryreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ BinaryReader::BinaryReader(BinaryView* data, BNEndianness endian) : m_view(data)
}


BinaryReader::BinaryReader(Ref<BinaryView> data, BNBinaryReader* stream) : m_view(data), m_stream(stream)
{
}


BinaryReader::~BinaryReader()
{
BNFreeBinaryReader(m_stream);
Expand Down Expand Up @@ -443,6 +448,12 @@ bool BinaryReader::TryReadBEPointer(uint64_t& result)
}


BinaryReader BinaryReader::Slice(uint64_t offset, size_t length) const
{
return BinaryReader(m_view, BNSliceBinaryReader(m_stream, offset, length));
}


uint64_t BinaryReader::GetOffset() const
{
return BNGetReaderPosition(m_stream);
Expand Down
Loading