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 number arg for 'heap chunk' command #745

Merged
merged 5 commits into from Nov 2, 2021
Merged

add number arg for 'heap chunk' command #745

merged 5 commits into from Nov 2, 2021

Conversation

skysider
Copy link
Contributor

@skysider skysider commented Oct 17, 2021

add number arg for 'heap chunk command'

Description/Motivation/Screenshots

add a number argument for heap chunk command which is usable for statically linked binary. There is no need to know the main_arena address and mp_ address for heap chunks, just chunk address and number.

gef➤  heap chunk -h
usage: heap chunk [-h] [--allow-unaligned] [--number NUMBER] [address]

positional arguments:
  address

optional arguments:
  -h, --help         show this help message and exit
  --allow-unaligned
  --number NUMBER

gef➤  heap chunk 0x4e5400
Chunk(addr=0x4e5400, size=0xd0, flags=PREV_INUSE)
Chunk size: 208 (0xd0)
Usable size: 200 (0xc8)
Previous chunk size: 0 (0x0)
PREV_INUSE flag: On
IS_MMAPPED flag: Off
NON_MAIN_ARENA flag: Off

gef➤  heap chunk --number 6 0x4e5400
Chunk(addr=0x4e5400, size=0xd0, flags=PREV_INUSE)
Chunk(addr=0x4e54d0, size=0x1a0, flags=PREV_INUSE)
Chunk(addr=0x4e5670, size=0x200, flags=PREV_INUSE)
Chunk(addr=0x4e5870, size=0xbc0, flags=PREV_INUSE)
Chunk(addr=0x4e6430, size=0x330, flags=PREV_INUSE)
Chunk(addr=0x4e6760, size=0x4c0, flags=PREV_INUSE)
gef➤  heap chunk --number 10 0x4e5400
Chunk(addr=0x4e5400, size=0xd0, flags=PREV_INUSE)
Chunk(addr=0x4e54d0, size=0x1a0, flags=PREV_INUSE)
Chunk(addr=0x4e5670, size=0x200, flags=PREV_INUSE)
Chunk(addr=0x4e5870, size=0xbc0, flags=PREV_INUSE)
Chunk(addr=0x4e6430, size=0x330, flags=PREV_INUSE)
Chunk(addr=0x4e6760, size=0x4c0, flags=PREV_INUSE)
Chunk(addr=0x4e6c20, size=0x650, flags=PREV_FREE)
Chunk(addr=0x4e7270, size=0xd50, flags=PREV_INUSE)
Chunk(addr=0x4e7fc0, size=0x1e050, flags=PREV_INUSE)
[!] Command 'heap chunk' failed to execute properly, reason: Cannot access memory at address 0x506008

How Has This Been Tested?

Architecture Yes/No Comments
x86-32 ✖️
x86-64 ✔️
ARM ✖️
AARCH64 ✖️
MIPS ✖️
POWERPC ✖️
SPARC ✖️
RISC-V ✖️
make test ✖️

Checklist

  • My PR was done against the dev branch, not master.
  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • My change adds tests as appropriate.
  • I have read and agree to the CONTRIBUTING document.

Copy link
Collaborator

@daniellimws daniellimws left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Could you also update the documentation, and the help message? It wasn't immediately clear to me at the start what this argument does.

gef.py Outdated Show resolved Hide resolved
docs/commands/heap.md Outdated Show resolved Hide resolved
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

The code though needs to be updated. Also you're missing adding unit test cases, please provide some.

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
docs/commands/heap.md Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
@hugsy hugsy added this to the Release: next milestone Oct 18, 2021
tests/runtests.py Outdated Show resolved Hide resolved
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@daniellimws daniellimws left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@hugsy hugsy merged commit 8fc0583 into hugsy:dev Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants