WerWolv / ImHex

🔍 A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.
https://imhex.werwolv.net
GNU General Public License v2.0
43.96k stars 1.92k forks source link

[[format_write]] is broken #1694

Open Kein opened 4 months ago

Kein commented 4 months ago

Operating System

Windows

What's the issue you encountered?

I'mHex v 1.33.0

u8               SaveHash      [[format_write("WriteHash")]];

// Hash handling
fn WriteHash(str v) { return 12; };

Result: nothing happens. Completely nothing, not even user-input value being written as-is.

How can the issue be reproduced?

See above.

ImHex Version

1.33.0

ImHex Build Type

Installation type

manual

Additional context?

format_read works

EtiTheSpirit commented 4 months ago

I can reproduce this on 1.33.2 Release installed via the non-portable .msi installer on Windows

I tested this myself and as tested by OP, the return value of the function is entirely ignored and discarded in all cases. In my case I am using a custom struct rather than u8, but the same issue applies here.

I will also add that nothing is output into the log console at debug level with respect to the pattern data.

Edit 12 July 2024: I've just decided to come back to this since I ran into it on accident again. There's some additional quirks I noticed.

  1. Adding a std::print(txt) (where txt is the string arg to the function) does nothing if the argument type is ref str txt, but works fine if it is just str txt.
  2. I was attempting to return a custom object type but realized this does not work. Is this intentional?
  3. I followed this up by trying to return a char array but this just placed corrupted data in, even if I wrote to the array in a loop (bug? it always seemed to be the same data, I was using std::string::at)
  4. I did get it to work by returning a string value. My struct is a string value prefixed with a 16 bit length, so I just prepended two spaces to the result string then replaced [0] and [1] of the string with the length bytes. The issue I ran into now is that it can't seem to insert or remove bytes.