ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Feature] support for c#'s 7bit int?

Open sk337 opened this issue 9 months ago • 3 comments

What feature would you like to see?

i would like to see c#'s binary reader 7 bit integer

How will this feature be useful to you and others?

i will be able to parse c# fields that use that number format

Request Type

  • [x] I can provide a PoC for this feature or am willing to work on it myself and submit a PR

Additional context?

i am willing to work on this

sk337 avatar Mar 22 '25 20:03 sk337

I am assuming that you mean that the pattern language a binary reader to process this type of data. The pattern language has already a bit reader in std::mem::read_bits. You can also parse 7 bit integers easily using bit-fields. What exact functionality are you trying to use that you are having trouble with? If you can provide more details maybe it will be easier to determine if extra functionality is needed or not.

paxcut avatar Mar 22 '25 20:03 paxcut

the 7 bit format is a dynamic size where the msb determines if another byte is read a related stack overflow question i am unsure on how to implement this into the Pattern editor as i am very new ImHex

sk337 avatar Mar 22 '25 20:03 sk337

Here is a partial implementation . Use the values in pragma example to create a sample input file for testing it.

#pragma example 56 78 86 99 95 87 58 88 57 78 78 00 00 00 00 00
import std.core;
import std.mem;

bitfield SevenBitBits {
    value : 7;
   bool keepReading : 1;
   if (!keepReading || std::core::array_index() > 3 )
       break;
};

struct SevenBitBytes {
   SevenBitBits bytes[while(true)];
};

SevenBitBytes data[while(!std::mem::eof())]@0;

paxcut avatar Mar 22 '25 20:03 paxcut