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

[Feature] Set default value for in variables in patterns #1916

Open
1 task
Alex-Addy opened this issue Sep 26, 2024 · 0 comments
Open
1 task

[Feature] Set default value for in variables in patterns #1916

Alex-Addy opened this issue Sep 26, 2024 · 0 comments

Comments

@Alex-Addy
Copy link

What feature would you like to see?

It would be nice to have some way to set a non-zero default value for an in variable.

An example:

u32 max_data_size in = 1024 * 1024;

Alternatively it might be better to have an attribute or the like to set the value instead.

How will this feature be useful to you and others?

I have a use case where I would like to avoid parsing some data depending on the size to keep the pattern fast. However it would be good to have a way for the user to increase or decrease the values depending on their usage.

I believe that this would make variables useful in situations where having a zero value in the variable isn't very useful or may even cause errors.

Request Type

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

Additional context?

I have this pattern for afs files (archive files used by sega, see [https://github.com/fuzziqersoftware/gctools/blob/master/src/afsdump.cc] for some code that pulls out the data):

#pragma magic [41 46 53 00] @ 0x00

u32 max_data_size = 1024 * 1024;

struct file {
  le u32 offset;
  le u32 size;
  if (size < max_data_size) {
    u8 data[size] @ offset;
  }
};

struct afs {
  le u32 magic;
  le u32 num_files;
  file files[num_files];
};

afs afs @ 0x00;

I would like to have max_data_size be an in variable, but can't do that without it being zero by default.

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

No branches or pull requests

1 participant