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

Use regex lookaround in asm sanitize #62

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

disinvite
Copy link
Collaborator

The regular expressions used in asm sanitize looked like this:

ptr_replace_regex = re.compile(r"\[(0x[0-9a-f]+)\]")

i.e. capturing the surrounding square brackets as part of the total match.

re.sub will replace the entire match with a string or the return value of a function. We use the function, but match.group(0) included more than just the hex value, so we used a hacky string replacement to get it working. The correct way is to use lookaround expressions to match with the surrounding characters but to not include them in group(0).

I also removed an edge case that makes no sense. The expression that detects immediate value operands would allow a replacement of the first operand, which is the destination in intel syntax. But an immediate value can never be the destination. I think this was there to cover replacement for single operand instructions, but we already match the ones we want earlier in the function: call, push, and jumps.

Copy link
Collaborator

@jonschz jonschz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@disinvite disinvite merged commit 0e04724 into isledecomp:master Jan 6, 2025
4 checks passed
@disinvite disinvite deleted the asm-lookaround branch January 6, 2025 22:09
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

Successfully merging this pull request may close these issues.

2 participants