* Remove use of OnlyWhenRunning when we already have OnlyWhenHeapInitialized
* Remove use of OnlyWhenHeapInitialized when we already have OnlyWithTcache
* Add OnlyWhenUserspace Decorator #1459
* The decorator is implemented as the inverse of OnlyWhenQemuKernel
* Apply the decorator to all of the heap commands and tls, auxv and environ/envp
* Update pwndbg/commands/__init__.py
---------
Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
This commit optimizes the `bin_ascii` function used by the `vis_heap_chunks` command.
That function executed the following line on each call:
```
valid_chars = list(map(ord, set(printable) - set("\t\r\n\x0c\x0b")))
```
And it could be called thousand times, e.g. 90k on a benchmark.
This commit moves the creation of the `valid_chars` list to the global space so it is computed only once.
As a result, on a simple benchmark we improved the speed of `vis_heap_chunks` command from 4.6s to 3s.
The `pwndbg.gdblib.regs.sp` value is cached and its cache is cleared on a next stop, memory write or register write events.
We keep a dictionary of stacks in Pwndbg, that are updated on each stop by the `stack.update` functionality which reused a cached stack pointer (`gdblib.regs.sp`) value.
As a result, if we had more than one threads, the `pwndbg.gdblib.stacks.stacks` reported the same stack address for all threads and then the `canary` command printed the same addresses N times where N is the number of threads that were running.
This commit fixes this bug by clearing up the registers cache when we switch into a different thread in the loop in the `stacks.update` function.
vmmap would try to add the executable to memory pages if the `info auxv`
command contained an address, but the memory maps would be accessed
recursively when trying to lookup the start of the ELF based on the
given address.
Since qemu doesn't provide memory map info, do a leap of faith and try
if the start of the page of the given address contains the ELF magic
header.
Since the program headers are more likely to be on the same page as the
ELF header than the program entrypoint, try both.
* Optimize vis_heap_chunks command
This commit optimizes the vis_heap_chunks command by:
1) precalculating bin labels instead of computing them on demand for each chunk
2) calling pwndbg.gdblib.memory.read once instead of twice in a hot loop
For `vis 2000` command ran when debugging python3 shell, the first change
cut down the execution time from almost 20s to 5s.
Another benchmark, for both 1) and 2) changes showed 19.28s->4.14s timing.
The benchmark done is included in this commit in
profiling/benchmark_vis_heap_chunks/ so that it can be reproduced e.g.
to optimize the function further or to reproduce my results.
* fix: remove minor bugs and complete address translation
* feat: add 5lvl paging
* feat: add address translation tests
* fix: remove unnecessary comments
* fix: add references for magic values
* fix: add X86_FEATURE_LA57 reference
* fix: move x86 specific functions to x86_64Ops
* fix: extend tests and remove faulty code
* fix: only test address translation for lowmem
* fix: adjust arch_ops test to pytest
* fix: add reference for memory models in linux
* fix: do not memoize staticmethods
* Fix and test ctx disasm when disassembly-flavor changes
* New lib/cache.py: make caching great again
This commit fixes bugs with old caching (memoize.py) and makes it more
readable.
See also https://github.com/pwndbg/pwndbg/issues/1453
* Update pwndbg/lib/cache.py
Co-authored-by: Gulshan Singh <gsingh2011@gmail.com>
* lib.cache: address PR comments and add debug mode
* Fix lint
* Remove leftover memoize usages
* Add cache benchmark
* fix lint
---------
Co-authored-by: Gulshan Singh <gsingh2011@gmail.com>