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

Cache output of asm() #2358

Merged
merged 10 commits into from
Aug 12, 2024
Merged

Cache output of asm() #2358

merged 10 commits into from
Aug 12, 2024

Conversation

peace-maker
Copy link
Member

To speed up repeated runs of an exploit, cache the assembled output.

Use a sha1 hash of the shellcode as well as relevant context values like context.arch and context.bits to see if the exact same shellcode was assembled for the same context before.

Fixes #2312

To speed up repeated runs of an exploit, cache the assembled output.

Use a sha1 hash of the shellcode as well as relevant context values
like `context.arch` and `context.bits` to see if the exact same
shellcode was assembled for the same context before.

Fixes Gallopsled#2312
@Arusekk
Copy link
Member

Arusekk commented May 20, 2024

I think we should use the preprocessed assembly and full assembler command in order to avoid stale bugs on pwntools updates

@peace-maker
Copy link
Member Author

peace-maker commented May 21, 2024

Yeah, that's fine too. I wanted to avoid running any processes. But one instead of several is still an improvement if it prevents subtle bugs in the future.

"The assembler command" is tricky though due to the multi step approach. Building the command line arguments calls which too to find the binutils tools.

This should catch any changes across pwntools updates and system environment changes.
@Arusekk
Copy link
Member

Arusekk commented Aug 7, 2024

Two more things:

  • the doctest should maybe flush or disable the cache (so that it can be sure that the first run uses no cache)
  • the hash should include pwntools version and as invocation command (there are more context fields that influence the results: endianness, bits, arch, ...) OR put a limit on cache age (say 2h), just to make the cache as conservative as possible (it can be frustrating to look for the one rogue cache that broke something)

@peace-maker
Copy link
Member Author

The as command line is already included, that's why I removed the explicit context fields from the hash. Is there more? I'll add the pwntools version though.

@peace-maker
Copy link
Member Author

I don't think there is a way to disable caching atm. context.cache_dir and context.cache_dir_base don't accept an invalid path or None/False. We can allow setting cache_dir to False to disable caching and maybe to None to enable it again and have it generate a path based on the cache_dir_base? Not really belonging in this PR but w/e.

@Arusekk
Copy link
Member

Arusekk commented Aug 8, 2024 via email

@peace-maker peace-maker merged commit 67678c2 into Gallopsled:dev Aug 12, 2024
12 of 13 checks passed
@peace-maker peace-maker deleted the asm_cache branch August 12, 2024 18:59
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.

Cache assembler output
2 participants