Skip to content

Commit

Permalink
Change 'LOCATION' to 'address'
Browse files Browse the repository at this point in the history
  • Loading branch information
theguy147 committed Aug 7, 2021
1 parent d5e958a commit b33316a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions docs/commands/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In some cases, the allocation will start immediately from start of the page. If
so, specify the base address of the first chunk as follows:

```
gef➤ heap chunks [LOCATION]
gef➤ heap chunks [address]
```

![heap-chunks](https://i.imgur.com/2Ew2fA6.png)
Expand All @@ -38,7 +38,7 @@ provide the address to the user memory pointer of the chunk to show the
information related to a specific chunk:

```
gef➤ heap chunk [LOCATION]
gef➤ heap chunk [address]
```

![heap-chunk](https://i.imgur.com/SAWNptW.png)
Expand All @@ -64,7 +64,7 @@ binary), it is possible to instruct GEF to find the `main_arena` at a different
location with the command:

```
gef➤ heap set-arena [LOCATION]
gef➤ heap set-arena [address]
```

If the arena address is correct, all `heap` commands will be functional, and use
Expand Down
24 changes: 12 additions & 12 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def __init__(self, addr, from_base=False, allow_unaligned=True):
return

def align_data_address(self):
"""Align chunk data addresses according to glibc's MALLOC_ALIGNMENT."""
"""Align chunk data addresses according to glibc's MALLOC_ALIGNMENT. See also Issue #689 on Github"""
if is_x86_32() and get_libc_version() >= (2, 26):
# Special case introduced in Glibc 2.26:
# https://elixir.bootlin.com/glibc/glibc-2.26/source/sysdeps/i386/malloc-alignment.h#L22
Expand Down Expand Up @@ -6541,7 +6541,7 @@ class GlibcHeapSetArenaCommand(GenericCommand):
"""Display information on a heap chunk."""

_cmdline_ = "heap set-arena"
_syntax_ = "{:s} LOCATION".format(_cmdline_)
_syntax_ = "{:s} address".format(_cmdline_)
_example_ = "{:s} 0x001337001337".format(_cmdline_)

def __init__(self):
Expand All @@ -6558,13 +6558,13 @@ def do_invoke(self, argv):

new_arena = safe_parse_and_eval(argv[0])
if new_arena is None:
err("Invalid location")
err("Invalid address")
return

if argv[0].startswith("0x"):
new_arena = Address(value=to_unsigned_long(new_arena))
if new_arena is None or not new_arena.valid:
err("Invalid location")
err("Invalid address")
return

__gef_default_main_arena__ = "*{:s}".format(format_address(new_arena.value))
Expand Down Expand Up @@ -6602,25 +6602,25 @@ class GlibcHeapChunkCommand(GenericCommand):
See https://github.com/sploitfun/lsploits/blob/master/glibc/malloc/malloc.c#L1123."""

_cmdline_ = "heap chunk"
_syntax_ = "{:s} [-h] [--allow-unaligned] LOCATION".format(_cmdline_)
_syntax_ = "{:s} [-h] [--allow-unaligned] address".format(_cmdline_)

def __init__(self):
super().__init__(complete=gdb.COMPLETE_LOCATION)
return

@parse_arguments({"LOCATION": ""}, {"--allow-unaligned": True})
@parse_arguments({"address": ""}, {"--allow-unaligned": True})
@only_if_gdb_running
def do_invoke(self, *args, **kwargs):
args = kwargs["arguments"]
if not args.LOCATION:
if not args.address:
err("Missing chunk address")
self.usage()
return

if get_main_arena() is None:
return

addr = to_unsigned_long(gdb.parse_and_eval(args.LOCATION))
addr = to_unsigned_long(gdb.parse_and_eval(args.address))
chunk = GlibcChunk(addr, allow_unaligned=args.allow_unaligned)
gef_print(chunk.psprint())
return
Expand All @@ -6632,26 +6632,26 @@ class GlibcHeapChunksCommand(GenericCommand):
it must correspond to the base address of the first chunk."""

_cmdline_ = "heap chunks"
_syntax_ = "{0} [-h] [--allow-unaligned] [LOCATION]".format(_cmdline_)
_syntax_ = "{0} [-h] [--allow-unaligned] [address]".format(_cmdline_)
_example_ = "\n{0}\n{0} 0x555555775000".format(_cmdline_)

def __init__(self):
super().__init__(complete=gdb.COMPLETE_LOCATION)
self.add_setting("peek_nb_byte", 16, "Hexdump N first byte(s) inside the chunk data (0 to disable)")
return

@parse_arguments({"LOCATION": ""}, {"--allow-unaligned": True})
@parse_arguments({"address": ""}, {"--allow-unaligned": True})
@only_if_gdb_running
def do_invoke(self, *args, **kwargs):
args = kwargs["arguments"]

if not args.LOCATION:
if not args.address:
heap_section = HeapBaseFunction.heap_base()
if not heap_section:
err("Heap not initialized")
return
else:
heap_section = int(args.LOCATION, 0)
heap_section = int(args.address, 0)

arena = get_main_arena()
if arena is None:
Expand Down

0 comments on commit b33316a

Please sign in to comment.