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

I dont know how to get the current offset of file. #27

Closed
ProfElements opened this issue Dec 5, 2020 · 7 comments
Closed

I dont know how to get the current offset of file. #27

ProfElements opened this issue Dec 5, 2020 · 7 comments
Labels
need info Further information is requested

Comments

@ProfElements
Copy link

Im trying to use your patterns and I dont know how to get the current offset of the file.

@WerWolv
Copy link
Owner

WerWolv commented Dec 5, 2020

Hi
Could you please clarify your question a little? What offset do you mean?

@WerWolv WerWolv added the need info Further information is requested label Dec 5, 2020
@ProfElements
Copy link
Author

current byte offset of file when used in a hex pattern
hopefully that makes more sense

@benvanik
Copy link

benvanik commented Dec 7, 2020

I was having the same usability issue I think: there doesn't seem to be a good way to get the current byte offset under the cursor in various views. For example, in the hex editor if I'm looking at a byte I literally counted the byte columns from the start of the row to manually type it in the pattern editor. Having every single byte offset be easily accessible would be super useful (imgui makes this nice - a byteOffsetText() fn that handled right clicking/shift+clicking/etc on the text to copy to clipboard would be easy to slot in, etc).

@ProfElements
Copy link
Author

That is correct ^

@WerWolv
Copy link
Owner

WerWolv commented Dec 16, 2021

This is possible now using the $ operator

@WerWolv WerWolv closed this as completed Dec 16, 2021
@supercherrysai
Copy link

Reference in new

can you be more specific on how to use the $ operator?

@paxcut
Copy link
Contributor

paxcut commented Mar 11, 2024

To copy the offset on the hex editor view place the cursor on the data whose offset you want and right click Copy As > Address. That will copy the offset to the clipboard. The $ operator in the pattern language is the operator that returns the current offset that the pattern is processing. When you place a pattern in the data using the @ operator, the value of $ is updated automatically. $ can be read, assigned to variables, written to using values or variables like for example:

std::print("{:#x}",$); //prints offset in hex
u32 offset = $;  // assigns offset to variable 'offset'
$ = a==0 ? 0x25 : a; // if a is zero set offset to 37 else set it to the value of a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need info Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants