solemnwarning / rehex

Reverse Engineers' Hex Editor
https://rehex.solemnwarning.net/
GNU General Public License v2.0
2.3k stars 113 forks source link

Null terminated strings in binary templates #211

Closed pulkomandy closed 10 months ago

pulkomandy commented 1 year ago

Hello,

I am trying to make sense of a file where part of the data is null-terminated strings using rehex binary templates. I looked at examples from 010 editor since I saw the format is similar. It seems in rehex editor, a null terminated string can be done like this:

char someText[];

and the parser will auto detect the NULL terminator and size the array.

However, in rehex that doesn't work.

I had to use a struct like this instead:

struct NullTerminatedString {
    local int64_t start = FTell();
    local int64_t end = start;

    while (ReadU8(end) != 0) {
        end++;
    }

    local int64_t size = end - start + 1;
    char string[size];
};

Is there a way to do this that I have missed?

solemnwarning commented 1 year ago

In the current development version, you can do something like this:

local string s = ReadString();
char string[ StringLengthBytes(s) + 1 ];

Or more condensed:

char string[ StringLengthBytes(ReadString()) + 1 ];