From 52e8a740df9da470c5e35dc4469bd176638c8777 Mon Sep 17 00:00:00 2001 From: tinysec Date: Wed, 8 Jul 2026 13:17:21 +0800 Subject: [PATCH] fix: BinaryReader 64-bit endianness + base-class generic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two correctness bugs in BinaryReader surfaced by the parity audit: 1. ReadInt64/ReadUInt64 hardcoded BNReadLE64 (little-endian) instead of the endian-agnostic BNRead64, so a BinaryReader whose Endianness is set to BigEndian silently read little-endian 64-bit values. The 8/16/32-bit siblings and the explicit *LE/*BE variants are all correct; only the two endian-agnostic 64-bit readers were wrong. Mirrors Python's read64. 2. Copy-paste typo: BinaryReader derived from AbstractSafeHandle instead of (BinaryWriter correctly uses ). AbstractSafeHandle implements IEquatable/IComparable by casting `other as T_SELF`, so two BinaryReader wrappers never compared equal and BinaryReader was not IEquatable — diverging from Python's handle-address __eq__/__hash__. --- Handle/BNBinaryReader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Handle/BNBinaryReader.cs b/Handle/BNBinaryReader.cs index 75a422a..072f8b7 100644 --- a/Handle/BNBinaryReader.cs +++ b/Handle/BNBinaryReader.cs @@ -7,7 +7,7 @@ namespace BinaryNinja { - public sealed class BinaryReader : AbstractSafeHandle + public sealed class BinaryReader : AbstractSafeHandle { public BinaryReader(BinaryView view) : this(NativeMethods.BNCreateBinaryReader(view.DangerousGetHandle()) , true) @@ -243,7 +243,7 @@ public bool ReadData(byte[] buffer) public long? ReadInt64() { - bool ok = NativeMethods.BNReadLE64(this.handle, out ulong slug); + bool ok = NativeMethods.BNRead64(this.handle, out ulong slug); if (!ok) { @@ -374,7 +374,7 @@ public bool ReadData(byte[] buffer) public ulong? ReadUInt64() { - bool ok = NativeMethods.BNReadLE64(this.handle, out ulong slug); + bool ok = NativeMethods.BNRead64(this.handle, out ulong slug); if (!ok) {