diff options
| author | Brandon Miller <brandon@vector35.com> | 2024-03-25 08:13:29 -0400 |
|---|---|---|
| committer | Brandon Miller <bkmiller89@icloud.com> | 2024-03-25 14:57:54 -0400 |
| commit | bf6d310f7513b8ce9a3fcadc8fcb32da43485ccd (patch) | |
| tree | 0f2bcda61890e1b72e5785e5a0b53ed2d5951e80 /binaryreader.cpp | |
| parent | 3697a06ba40acbb4386bcdb25ea92143d200f5a1 (diff) | |
Fixed TryReadPointer and ReadPointer APIs
Both TryReadPointer and ReadPointer were assuming little endian
byte order. TryReadPointer was also only setting 32-bits of the
64-bit value while running against binaries targeting 32-bit CPU
architectures
Diffstat (limited to 'binaryreader.cpp')
| -rw-r--r-- | binaryreader.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/binaryreader.cpp b/binaryreader.cpp index f94942b5..c49637f9 100644 --- a/binaryreader.cpp +++ b/binaryreader.cpp @@ -106,15 +106,17 @@ uint64_t BinaryReader::Read64() return result; } + uint64_t BinaryReader::ReadPointer() { size_t addressSize = m_view->GetAddressSize(); if (addressSize > 8 || addressSize == 0) throw ReadException(); - uint64_t result = 0; - if (!BNReadData(m_stream, &result, addressSize)) - throw ReadException(); - return result; + + if (GetEndianness() == BigEndian) + return ReadBEPointer(); + + return ReadLEPointer(); } @@ -315,9 +317,11 @@ bool BinaryReader::TryReadPointer(uint64_t& result) size_t addressSize = m_view->GetAddressSize(); if (addressSize > 8 || addressSize == 0) return false; - if (!BNReadData(m_stream, &result, addressSize)) - return false; - return true; + + if (GetEndianness() == BigEndian) + return TryReadBEPointer(result); + + return TryReadLEPointer(result); } |
