WerWolv / PatternLanguage

The Pattern Language used by the ImHex Hex Editor
https://imhex.werwolv.net
GNU Lesser General Public License v2.1
165 stars 41 forks source link

Implement the ability to conditionally assign attributes #16

Open vulpes2 opened 1 year ago

vulpes2 commented 1 year ago

It would be great if there's a way to conditionally assign attributes to a variable. This would be pretty nice for verifying checksums included in some file formats, where the pattern language can verify the checksum for the data chunks if the algorithm is known, and dynamically rename the variable to something like CRC(verified) and CRC(unverified) depending on the result. Currently there does not seem to be a way to implement this if the variable is a part of a struct.

ctrlcctrlv commented 1 year ago

Yes please, or just a way to set attributes programmatically.

This is not allowed:

struct palette_entry_t {
    u24 color;
} [[inline, color(color)]];

And while there is e.g.:

builtin::std::core::get_attribute_value(this, "color");

There's no set_attribute_value.

WerWolv commented 1 year ago

This has been partially implemented now. It's not possible yet to assign attributes conditionally but they aren't limited to taking string literals as inputs anymore and can access the current pattern's fields

ctrlcctrlv commented 1 year ago

so can i now set a palette entry to its color?

WerWolv commented 1 year ago

You can indeed. Something like this should work now provided you're using the latest nightly version of ImHex

#include <std/io.pat>

struct PaletteEntry {
    u8 r, g, b;
} [[color(std::format("{:02X}{:02X}{:02X}", r, g, b))]];
ctrlcctrlv commented 1 year ago

nice :D i will give it a try in the png pattern