mallocng: add ng-slots command (#3144)

* move slot printing out to a func; add ng-slots

* make ng-find use this now
pull/3153/head
k4lizen 5 months ago committed by GitHub
parent 7cec118771
commit 93275b45db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -261,6 +261,7 @@
- [mallocng-find](musl/mallocng-find.md) - Find slot which contains the given address.
- [mallocng-group](musl/mallocng-group.md) - Print out information about a mallocng group at the given address.
- [mallocng-meta](musl/mallocng-meta.md) - Print out information about a mallocng group given the address of its meta.
- [mallocng-slot-start](musl/mallocng-slot-start.md) - Dump information about a mallocng slot, given its start address.
- [mallocng-slot-user](musl/mallocng-slot-user.md) - Dump information about a mallocng slot, given its user address.
<!-- END OF AUTOGENERATED PART. Do not modify this line or the line below, they mark the end of the auto-generated part of the file. If you want to extend the documentation in a way which cannot easily be done by adding to the command help description, write below the following line. -->

@ -0,0 +1,26 @@
<!-- THIS PART OF THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT. See scripts/generate-docs.sh -->
# mallocng-slot-start
```text
usage: mallocng-slot-start [-h] [-a] address
```
Dump information about a mallocng slot, given its start address.
**Alias:** ng-slots
### Positional arguments
|Positional Argument|Help|
| :--- | :--- |
|address|The start of the slot (not including IB).|
### Optional arguments
|Short|Long|Help|
| :--- | :--- | :--- |
|-h|--help|show this help message and exit|
|-a|--all|Print out all information. Including meta and group data.|
<!-- END OF AUTOGENERATED PART. Do not modify this line or the line below, they mark the end of the auto-generated part of the file. If you want to extend the documentation in a way which cannot easily be done by adding to the command help description, write below the following line. -->
<!-- ------------\>8---- ----\>8---- ----\>8------------ -->

@ -331,42 +331,12 @@ def dump_meta(meta: mallocng.Meta) -> str:
return output
parser = argparse.ArgumentParser(
description="""
Dump information about a mallocng slot, given its user address.
""",
)
parser.add_argument(
"address",
type=int,
help="The start of user memory. Referred to as `p` in the source.",
)
parser.add_argument(
"-a",
"--all",
action="store_true",
help="Print out all information. Including meta and group data.",
)
@pwndbg.commands.Command(
parser,
category=CommandCategory.MUSL,
aliases=["ng-slotu"],
)
@pwndbg.commands.OnlyWhenRunning
def mallocng_slot_user(address: int, all: bool) -> None:
if not memory.is_readable_address(address):
print(message.error(f"Address {address:#x} not readable."))
return
slot = mallocng.Slot(address)
def dump_slot(slot: mallocng.Slot, all: bool) -> str:
try:
slot.preload()
except pwndbg.dbg_mod.Error as e:
print(message.error(f"Error while reading slot: {e}"))
return
return ""
read_success: bool = True
@ -483,11 +453,79 @@ def mallocng_slot_user(address: int, all: bool) -> None:
pp.add(inband_group)
pp.end_section()
pp.print()
output = pp.dump()
if all:
print(dump_group(slot.group), end="")
print(dump_meta(slot.meta), end="")
output += dump_group(slot.group)
output += dump_meta(slot.meta)
return output
parser = argparse.ArgumentParser(
description="""
Dump information about a mallocng slot, given its user address.
""",
)
parser.add_argument(
"address",
type=int,
help="The start of user memory. Referred to as `p` in the source.",
)
parser.add_argument(
"-a",
"--all",
action="store_true",
help="Print out all information. Including meta and group data.",
)
@pwndbg.commands.Command(
parser,
category=CommandCategory.MUSL,
aliases=["ng-slotu"],
)
@pwndbg.commands.OnlyWhenRunning
def mallocng_slot_user(address: int, all: bool) -> None:
if not memory.is_readable_address(address):
print(message.error(f"Address {address:#x} not readable."))
return
slot = mallocng.Slot(address)
print(dump_slot(slot, all), end="")
parser = argparse.ArgumentParser(
description="""
Dump information about a mallocng slot, given its start address.
""",
)
parser.add_argument(
"address",
type=int,
help="The start of the slot (not including IB).",
)
parser.add_argument(
"-a",
"--all",
action="store_true",
help="Print out all information. Including meta and group data.",
)
@pwndbg.commands.Command(
parser,
category=CommandCategory.MUSL,
aliases=["ng-slots"],
)
@pwndbg.commands.OnlyWhenRunning
def mallocng_slot_start(address: int, all: bool) -> None:
if not memory.is_readable_address(address):
print(message.error(f"Address {address:#x} not readable."))
return
slot = mallocng.Slot.from_start(address)
print(dump_slot(slot, all), end="")
parser = argparse.ArgumentParser(
@ -630,4 +668,4 @@ def mallocng_find(
print(message.info("No slot found containing that address."))
return
mallocng_slot_user(mallocng.Slot.from_start(slot_start).p, all=all)
mallocng_slot_start(slot_start, all=all)

Loading…
Cancel
Save