C#C
C#3y ago
Bambino

❔ Understanding reading values from binary

I'm reading a version number from the binary of a client via hex. However, I get different results with different client versions.

Using IDA, I have found the correct offsets for each client, so that is not the issue. I have reached my intended goal of getting the value for different client versions, but I am trying to understand why.

I am new to this so there must be something I do not comprehend.
-------------------------
Using BinaryPrimitives.ReadUInt16LittleEndian
var majorPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset));
var minorPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 2));
var privatePart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 5));
var buildPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 8));


Client 1, I get the correct value:
Version: 7.0.98.16

for the version. Client 2, I get
Version: 29554.28521.8302.29477
-------------------------


Using Encoding.ASCII.GetString

majorPart = Encoding.ASCII.GetString(buffer.AsSpan(offset, 1));
minorPart = Encoding.ASCII.GetString(buffer.AsSpan(offset + 2, 2));
buildPart = Encoding.ASCII.GetString(buffer.AsSpan(offset + 5, 2));
privatePart = Encoding.ASCII.GetString(buffer.AsSpan(offset + 8, 2));

for the version. Client 2, I get the intended value for Client 2
Version: 1.25.35.00

------------------------------------------
Was this page helpful?