mirror of https://github.com/pwndbg/pwndbg.git
Fix memory.poke and make memory.peek return bytearray (#2483)
Fixes #2472 where poke could write incorrect bytes to memory when testing if certain address is writable or not (see longer description below). Summary of changes: * Changes `{aglib,gdblib}.memory.peek` to return a `bytearray` instead of `str` (which made no sense) * Add tests for multiple use cases of `gdblib.memory.{peek,poke}` Longer description: Before this commit, the `memory.poke` implementation could end up writing a different byte to memory then the byte that was initially there. This is because it used `memory.peek` which returned a `str` and this str was then encoded to utf-8 to get bytes back again for `memory.write` used by `memory.poke`. This resulted in writing different bytes to memory then the byte that was initially read from the given address. Below is an example. If `memory.peek` read the `b'\xa9'` byte, then this was converted to a `'©'` string via chr(b'\xa9'[0]) which was returned from peek. Then, this was converted back to bytes in poke with utf-8 encoding which resulted in `b'\xc2\xa9'` bytes. ``` In [4]: bytes(chr(b'\xa9'[0]), 'utf-8') Out[4]: b'\xc2\xa9' ``` During all this I also tried to change the `peek/poke` to only pass on a `gdb.MemoryError`. This however uncovered some other bugs that have to be fixed in another PR/commit.pull/2484/head
parent
2922ba9b24
commit
3226ade3ff
Loading…
Reference in new issue