Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the ability to conditionally assign attributes #16

Open
vulpes2 opened this issue Nov 1, 2022 · 5 comments
Open

Implement the ability to conditionally assign attributes #16

vulpes2 opened this issue Nov 1, 2022 · 5 comments

Comments

@vulpes2
Copy link

vulpes2 commented Nov 1, 2022

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
Copy link
Contributor

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
Copy link
Owner

WerWolv commented Jan 30, 2023

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
Copy link
Contributor

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

@WerWolv
Copy link
Owner

WerWolv commented Jan 30, 2023

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants