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

Add Chunk class & template_heap_command #1159

Merged
merged 5 commits into from
Sep 28, 2022
Merged

Add Chunk class & template_heap_command #1159

merged 5 commits into from
Sep 28, 2022

Conversation

CptGibbon
Copy link
Contributor

The Chunk class abstracts developers from some heap & gdb internals and makes use of the gdb module's lazy fetching.
The template_heap_command command serves as an example of how to use the Chunk class (and hopefully future classes).

@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2022

Codecov Report

Merging #1159 (dfdcd20) into dev (96d90d1) will increase coverage by 1.13%.
The diff coverage is 27.02%.

@@            Coverage Diff             @@
##              dev    #1159      +/-   ##
==========================================
+ Coverage   51.45%   52.59%   +1.13%     
==========================================
  Files         176      178       +2     
  Lines       19997    20118     +121     
  Branches     1833     1851      +18     
==========================================
+ Hits        10290    10581     +291     
+ Misses       9325     9129     -196     
- Partials      382      408      +26     
Impacted Files Coverage Δ
pwndbg/heap/ptmalloc.py 37.51% <22.22%> (-0.94%) ⬇️
pwndbg/commands/heap.py 60.42% <40.00%> (-0.57%) ⬇️
tests/test_commands_next.py 95.65% <0.00%> (ø)
tests/test_mprotect.py 100.00% <0.00%> (ø)
pwndbg/commands/__init__.py 69.68% <0.00%> (+0.45%) ⬆️
pwndbg/proc.py 75.00% <0.00%> (+0.58%) ⬆️
pwndbg/commands/telescope.py 80.41% <0.00%> (+1.03%) ⬆️
pwndbg/commands/nearpc.py 88.52% <0.00%> (+1.63%) ⬆️
pwndbg/lib/abi.py 95.65% <0.00%> (+2.17%) ⬆️
pwndbg/commands/vmmap.py 43.47% <0.00%> (+2.17%) ⬆️
... and 21 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

pwndbg/heap/ptmalloc.py Outdated Show resolved Hide resolved
pwndbg/heap/ptmalloc.py Show resolved Hide resolved
pwndbg/heap/ptmalloc.py Outdated Show resolved Hide resolved
pwndbg/heap/ptmalloc.py Outdated Show resolved Hide resolved
pwndbg/heap/ptmalloc.py Show resolved Hide resolved
pwndbg/commands/heap.py Outdated Show resolved Hide resolved
# The `Chunk` class abstracts away many heap & gdb module internals.
chunk = pwndbg.heap.ptmalloc.Chunk(addr)

print(f"chunk.address: 0x{chunk.address:02x}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this PR is great, the only tiny potential issue I can find is: should we use f-strings syntax?
I like f-strings and it's convenient, but for the compatibility, maybe we should not use it until we fully deprecate Python<3.6 support I guess?
(I saw the comment from @disconnect3d about the Python version we want to support here: #1063 (comment))

@gsingh93
Copy link
Member

maybe we should not use it until we fully deprecate Python<3.6 support I guess?

We had a discussion on Discord after that comment, I remember the general consensus was we should support distros that are not EOL yet, which would include Ubuntu 18.04, 20.04 and 22.04, and we now run the CI on all three. Ubuntu 18.04 uses Python 3.6.9, so personally I think it's OK to drop support for versions older than 3.6, but I know we always have the issue of someone wanting to use it on those older versions.

@CptGibbon
Copy link
Contributor Author

So far the consensus seems to be:

  1. Ditch template_heap_command
  2. Keep f-strings

@gsingh93 are you happy to postpone the unit testing stuff?
@disconnect3d do you agree with the above?

@gsingh93
Copy link
Member

Yup, feel free to hold off on the unit testing stuff, we can revisit it later.

@disconnect3d
Copy link
Member

Yeah, I am fine with that. So what with the Chunk class? Are you going to refactor heap commands to use it?:P

@CptGibbon
Copy link
Contributor Author

So what with the Chunk class? Are you going to refactor heap commands to use it?

Exactly. Right now contributors must manually find many heap values in their commands:

size_field = pwndbg.gdblib.memory.u(cursor + ptr_size)
real_size = size_field & ~allocator.malloc_align_mask
prev_inuse = allocator.chunk_flags(size_field)[0]

Hopefully we can avoid this (and benefit from the built-in efficiency the gdb module gives us) by introducing these classes to pwndbg's heap inspection engine.

@disconnect3d disconnect3d merged commit df26a11 into pwndbg:dev Sep 28, 2022
@CptGibbon CptGibbon deleted the chunk-class-example branch September 28, 2022 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants