ptmalloc ¤
Classes:
-
BinType
– -
Bin
– -
Bins
– -
ChunkField
– -
Chunk
– -
Heap
– -
Arena
– -
GlibcMemoryAllocator
– -
DebugSymsHeap
– -
SymbolUnresolvableError
– -
HeuristicHeap
–
Functions:
-
heap_for_ptr
–Round a pointer to a chunk down to find its corresponding heap_info
-
fetch_chunk_metadata
–
Attributes:
-
PREV_INUSE
– -
IS_MMAPPED
– -
NON_MAIN_ARENA
– -
SIZE_BITS
– -
NONCONTIGUOUS_BIT
– -
TheType
– -
TheValue
– -
HEAP_MAX_SIZE
(int
) – -
NBINS
– -
BINMAPSIZE
– -
TCACHE_MAX_BINS
– -
NFASTBINS
– -
NSMALLBINS
–
BinType ¤
Bases: str
, Enum
Methods:
Attributes:
Bin ¤
Bin(
fd_chain: list[int],
bk_chain: list[int] | None = None,
count: int | None = None,
is_corrupted: bool = False,
)
ChunkField ¤
Chunk ¤
Methods:
-
next_chunk
– -
__contains__
–This allow us to avoid extra constructions like 'if start_addr <= ptr < end_addr', etc.
Attributes:
-
__slots__
– -
address
– -
prev_size
(int | None
) – -
size
(int | None
) – -
real_size
(int | None
) – -
flags
(dict[str, bool] | None
) – -
non_main_arena
(bool | None
) – -
is_mmapped
(bool | None
) – -
prev_inuse
(bool | None
) – -
fd
– -
bk
– -
fd_nextsize
– -
bk_nextsize
– -
heap
(Heap
) – -
arena
(Arena | None
) – -
is_top_chunk
–
__slots__ class-attribute
instance-attribute
¤
__slots__ = (
"_gdbValue",
"address",
"_prev_size",
"_size",
"_real_size",
"_flags",
"_non_main_arena",
"_is_mmapped",
"_prev_inuse",
"_fd",
"_bk",
"_fd_nextsize",
"_bk_nextsize",
"_heap",
"_arena",
"_is_top_chunk",
)
__contains__ ¤
This allow us to avoid extra constructions like 'if start_addr <= ptr < end_addr', etc.
Heap ¤
Heap(addr: int, arena: Arena | None = None)
1) main_arena - uses the sbrk heap 2) non-main arena - heap starts after its heap_info struct (and possibly an arena) 3) non-contiguous main_arena - just a memory region 4) no arena - for fake/mmapped chunks
Methods:
-
__iter__
– -
__contains__
– -
__str__
–
Attributes:
__slots__ class-attribute
instance-attribute
¤
Arena ¤
Methods:
Attributes:
-
__slots__
– -
address
– -
is_main_arena
(bool
) – -
mutex
(int | None
) – -
flags
(int | None
) – -
non_contiguous
(bool | None
) – -
have_fastchunks
(int | None
) – -
top
(int | None
) – -
fastbinsY
(list[int]
) – -
bins
(list[int]
) – -
binmap
(list[int]
) – -
next
(int | None
) – -
next_free
(int | None
) – -
system_mem
(int | None
) – -
active_heap
(Heap
) – -
heaps
–
__slots__ class-attribute
instance-attribute
¤
__slots__ = (
"_gdbValue",
"address",
"_is_main_arena",
"_top",
"_active_heap",
"_heaps",
"_mutex",
"_flags",
"_non_contiguous",
"_have_fastchunks",
"_fastbinsY",
"_bins",
"_binmap",
"_next",
"_next_free",
"_system_mem",
)
GlibcMemoryAllocator ¤
Bases: MemoryAllocator
, Generic[TheType, TheValue]
Methods:
-
largebin_reverse_lookup
–Pick the appropriate largebin_reverse_lookup_ function for this architecture.
-
largebin_size_range_from_index
– -
can_be_resolved
– -
has_tcache
– -
chunk_flags
– -
chunk_key_offset
–Find the index of a field in the malloc_chunk struct.
-
get_heap
– -
get_tcache
– -
get_sbrk_heap_region
– -
get_region
–Find the memory map containing 'addr'.
-
get_bins
– -
fastbin_index
– -
fastbins
–Returns: chain or None
-
tcachebins
–Returns: tuple(chain, count) or None
-
check_chain_corrupted
–Checks if the doubly linked list (of a {unsorted, small, large} bin)
-
bin_at
–Modeled after glibc's bin_at function - so starts indexing from 1
-
unsortedbin
– -
smallbins
– -
largebins
– -
largebin_index_32
–Modeled on the GLIBC malloc largebin_index_32 macro.
-
largebin_index_32_big
–Modeled on the GLIBC malloc largebin_index_32_big macro.
-
largebin_index_64
–Modeled on the GLIBC malloc largebin_index_64 macro.
-
largebin_index
–Pick the appropriate largebin_index_ function for this architecture.
-
is_initialized
– -
is_statically_linked
– -
libc_has_debug_syms
–The
struct malloc_chunk
comes from debugging symbols and it will not be there -
summarize
–Returns a textual summary of the specified address.
-
containing
–Returns the address of the allocation which contains 'address'.
Attributes:
-
largebin_reverse_lookup_32
– -
largebin_reverse_lookup_32_big
– -
largebin_reverse_lookup_64
– -
main_arena
(Arena | None
) – -
arenas
(tuple[Arena, ...]
) –Return a tuple of all current arenas.
-
thread_arena
(Arena | None
) – -
thread_cache
(TheValue | None
) – -
mp
(TheValue | None
) – -
global_max_fast
(int | None
) – -
heap_info
(TheType | None
) – -
malloc_chunk
(TheType | None
) – -
malloc_state
(TheType | None
) – -
tcache_perthread_struct
(TheType | None
) – -
tcache_entry
(TheType | None
) – -
mallinfo
(TheType | None
) – -
malloc_par
(TheType | None
) – -
malloc_alignment
(int
) –Corresponds to MALLOC_ALIGNMENT in glibc malloc.c
-
size_sz
(int
) –Corresponds to SIZE_SZ in glibc malloc.c
-
malloc_align_mask
(int
) –Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
-
minsize
(int
) –Corresponds to MINSIZE in glibc malloc.c
-
min_chunk_size
(int
) –Corresponds to MIN_CHUNK_SIZE in glibc malloc.c
-
multithreaded
(bool
) –Is malloc operating within a multithreaded environment.
-
tcache_next_offset
(int
) –
largebin_reverse_lookup_32 class-attribute
instance-attribute
¤
largebin_reverse_lookup_32 = (
512,
576,
640,
704,
768,
832,
896,
960,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_32_big class-attribute
instance-attribute
¤
largebin_reverse_lookup_32_big = (
1008,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
2944,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_64 class-attribute
instance-attribute
¤
largebin_reverse_lookup_64 = (
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
3008,
3072,
3136,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
malloc_align_mask property
¤
Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
multithreaded property
¤
Is malloc operating within a multithreaded environment.
largebin_reverse_lookup ¤
Pick the appropriate largebin_reverse_lookup_ function for this architecture.
chunk_key_offset ¤
Find the index of a field in the malloc_chunk struct.
64bit example
prev_size == 0 size == 8 fd == 16 bk == 24 ...
get_region ¤
Find the memory map containing 'addr'.
tcachebins ¤
tcachebins(tcache_addr: int | None = None) -> Bins | None
Returns: tuple(chain, count) or None
check_chain_corrupted ¤
Checks if the doubly linked list (of a {unsorted, small, large} bin) defined by chain_fd, chain_bk is corrupted.
Even if the chains do not cover the whole bin, they still are expected to be of the same length.
Returns True if the bin is certainly corrupted, otherwise False.
bin_at ¤
Modeled after glibc's bin_at function - so starts indexing from 1 https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty-security/view/head:/malloc/malloc.c#L1394
bin_at(1) returns the unsorted bin
Bin 1 - Unsorted BiN Bin 2 to 63 - Smallbins Bin 64 to 126 - Largebins
Returns: tuple(chain_from_bin_fd, chain_from_bin_bk, is_chain_corrupted) or None
largebin_index_32 ¤
Modeled on the GLIBC malloc largebin_index_32 macro.
largebin_index_32_big ¤
Modeled on the GLIBC malloc largebin_index_32_big macro.
largebin_index_64 ¤
Modeled on the GLIBC malloc largebin_index_64 macro.
largebin_index ¤
Pick the appropriate largebin_index_ function for this architecture.
libc_has_debug_syms ¤
The struct malloc_chunk
comes from debugging symbols and it will not be there for statically linked binaries
summarize ¤
Returns a textual summary of the specified address.
Parameters:
-
address
(int
) –Address of the heap block to summarize.
Returns:
-
str
–A string.
containing ¤
Returns the address of the allocation which contains 'address'.
Parameters:
-
address
(int
) –Address to look up.
Returns:
-
int
–An integer.
DebugSymsHeap ¤
Bases: GlibcMemoryAllocator[Type, Value]
Methods:
-
can_be_resolved
– -
has_tcache
– -
get_heap
–Find & read the heap_info struct belonging to the chunk at 'addr'.
-
get_tcache
– -
get_sbrk_heap_region
–Return a Page object representing the sbrk heap region.
-
is_initialized
– -
summarize
–Returns a textual summary of the specified address.
-
containing
–Returns the address of the allocation which contains 'address'.
-
libc_has_debug_syms
–The
struct malloc_chunk
comes from debugging symbols and it will not be there -
largebin_reverse_lookup
–Pick the appropriate largebin_reverse_lookup_ function for this architecture.
-
largebin_size_range_from_index
– -
chunk_flags
– -
chunk_key_offset
–Find the index of a field in the malloc_chunk struct.
-
get_region
–Find the memory map containing 'addr'.
-
get_bins
– -
fastbin_index
– -
fastbins
–Returns: chain or None
-
tcachebins
–Returns: tuple(chain, count) or None
-
check_chain_corrupted
–Checks if the doubly linked list (of a {unsorted, small, large} bin)
-
bin_at
–Modeled after glibc's bin_at function - so starts indexing from 1
-
unsortedbin
– -
smallbins
– -
largebins
– -
largebin_index_32
–Modeled on the GLIBC malloc largebin_index_32 macro.
-
largebin_index_32_big
–Modeled on the GLIBC malloc largebin_index_32_big macro.
-
largebin_index_64
–Modeled on the GLIBC malloc largebin_index_64 macro.
-
largebin_index
–Pick the appropriate largebin_index_ function for this architecture.
-
is_statically_linked
–
Attributes:
-
main_arena
(Arena | None
) – -
thread_arena
(Arena | None
) – -
thread_cache
(Value | None
) –Locate a thread's tcache struct. If it doesn't have one, use the main
-
mp
(Value | None
) – -
global_max_fast
(int | None
) – -
heap_info
(Type | None
) – -
malloc_chunk
(Type | None
) – -
malloc_state
(Type | None
) – -
tcache_perthread_struct
(Type | None
) – -
tcache_entry
(Type | None
) – -
mallinfo
(Type | None
) – -
malloc_par
(Type | None
) – -
largebin_reverse_lookup_32
– -
largebin_reverse_lookup_32_big
– -
largebin_reverse_lookup_64
– -
arenas
(tuple[Arena, ...]
) –Return a tuple of all current arenas.
-
malloc_alignment
(int
) –Corresponds to MALLOC_ALIGNMENT in glibc malloc.c
-
size_sz
(int
) –Corresponds to SIZE_SZ in glibc malloc.c
-
malloc_align_mask
(int
) –Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
-
minsize
(int
) –Corresponds to MINSIZE in glibc malloc.c
-
min_chunk_size
(int
) –Corresponds to MIN_CHUNK_SIZE in glibc malloc.c
-
multithreaded
(bool
) –Is malloc operating within a multithreaded environment.
-
tcache_next_offset
(int
) –
thread_cache property
¤
thread_cache: Value | None
Locate a thread's tcache struct. If it doesn't have one, use the main thread's tcache.
largebin_reverse_lookup_32 class-attribute
instance-attribute
¤
largebin_reverse_lookup_32 = (
512,
576,
640,
704,
768,
832,
896,
960,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_32_big class-attribute
instance-attribute
¤
largebin_reverse_lookup_32_big = (
1008,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
2944,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_64 class-attribute
instance-attribute
¤
largebin_reverse_lookup_64 = (
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
3008,
3072,
3136,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
malloc_align_mask property
¤
Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
multithreaded property
¤
Is malloc operating within a multithreaded environment.
get_heap ¤
get_heap(addr: int) -> Value | None
Find & read the heap_info struct belonging to the chunk at 'addr'.
get_sbrk_heap_region ¤
get_sbrk_heap_region() -> Page | None
Return a Page object representing the sbrk heap region. Ensure the region's start address is aligned to SIZE_SZ * 2, which compensates for the presence of GLIBC_TUNABLES.
summarize ¤
Returns a textual summary of the specified address.
Parameters:
-
address
(int
) –Address of the heap block to summarize.
Returns:
-
str
–A string.
containing ¤
Returns the address of the allocation which contains 'address'.
Parameters:
-
address
(int
) –Address to look up.
Returns:
-
int
–An integer.
libc_has_debug_syms ¤
The struct malloc_chunk
comes from debugging symbols and it will not be there for statically linked binaries
largebin_reverse_lookup ¤
Pick the appropriate largebin_reverse_lookup_ function for this architecture.
chunk_key_offset ¤
Find the index of a field in the malloc_chunk struct.
64bit example
prev_size == 0 size == 8 fd == 16 bk == 24 ...
get_region ¤
Find the memory map containing 'addr'.
tcachebins ¤
tcachebins(tcache_addr: int | None = None) -> Bins | None
Returns: tuple(chain, count) or None
check_chain_corrupted ¤
Checks if the doubly linked list (of a {unsorted, small, large} bin) defined by chain_fd, chain_bk is corrupted.
Even if the chains do not cover the whole bin, they still are expected to be of the same length.
Returns True if the bin is certainly corrupted, otherwise False.
bin_at ¤
Modeled after glibc's bin_at function - so starts indexing from 1 https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty-security/view/head:/malloc/malloc.c#L1394
bin_at(1) returns the unsorted bin
Bin 1 - Unsorted BiN Bin 2 to 63 - Smallbins Bin 64 to 126 - Largebins
Returns: tuple(chain_from_bin_fd, chain_from_bin_bk, is_chain_corrupted) or None
largebin_index_32 ¤
Modeled on the GLIBC malloc largebin_index_32 macro.
largebin_index_32_big ¤
Modeled on the GLIBC malloc largebin_index_32_big macro.
largebin_index_64 ¤
Modeled on the GLIBC malloc largebin_index_64 macro.
largebin_index ¤
Pick the appropriate largebin_index_ function for this architecture.
SymbolUnresolvableError ¤
HeuristicHeap ¤
Bases: GlibcMemoryAllocator[Type['pwndbg.aglib.heap.structs.CStruct2GDB'], 'pwndbg.aglib.heap.structs.CStruct2GDB']
Methods:
-
can_be_resolved
– -
has_tcache
– -
prompt_for_brute_force_thread_arena_permission
–Check if the user wants to brute force the thread_arena's value.
-
prompt_for_brute_force_thread_cache_permission
–Check if the user wants to brute force the tcache's value.
-
prompt_for_tls_address
–Check if we can determine the TLS address and return it.
-
brute_force_tls_reference_in_got_section
–Brute force the TLS-reference in the .got section to that can pass the validator.
-
brute_force_thread_local_variable_near_tls_base
–Brute force the thread-local variable near the TLS base address that can pass the validator.
-
get_heap
–Find & read the heap_info struct belonging to the chunk at 'addr'.
-
get_tcache
– -
get_sbrk_heap_region
–Return a Page object representing the sbrk heap region.
-
is_initialized
– -
summarize
–Returns a textual summary of the specified address.
-
containing
–Returns the address of the allocation which contains 'address'.
-
libc_has_debug_syms
–The
struct malloc_chunk
comes from debugging symbols and it will not be there -
largebin_reverse_lookup
–Pick the appropriate largebin_reverse_lookup_ function for this architecture.
-
largebin_size_range_from_index
– -
chunk_flags
– -
chunk_key_offset
–Find the index of a field in the malloc_chunk struct.
-
get_region
–Find the memory map containing 'addr'.
-
get_bins
– -
fastbin_index
– -
fastbins
–Returns: chain or None
-
tcachebins
–Returns: tuple(chain, count) or None
-
check_chain_corrupted
–Checks if the doubly linked list (of a {unsorted, small, large} bin)
-
bin_at
–Modeled after glibc's bin_at function - so starts indexing from 1
-
unsortedbin
– -
smallbins
– -
largebins
– -
largebin_index_32
–Modeled on the GLIBC malloc largebin_index_32 macro.
-
largebin_index_32_big
–Modeled on the GLIBC malloc largebin_index_32_big macro.
-
largebin_index_64
–Modeled on the GLIBC malloc largebin_index_64 macro.
-
largebin_index
–Pick the appropriate largebin_index_ function for this architecture.
-
is_statically_linked
–
Attributes:
-
struct_module
(ModuleType | None
) – -
main_arena
(Arena | None
) – -
thread_arena
(Arena | None
) – -
thread_cache
('pwndbg.aglib.heap.structs.TcachePerthreadStruct' | None
) –Locate a thread's tcache struct. We try to find its address in Thread Local Storage (TLS) first,
-
mp
('pwndbg.aglib.heap.structs.CStruct2GDB'
) – -
global_max_fast
(int
) – -
heap_info
(type['pwndbg.aglib.heap.structs.HeapInfo'] | None
) – -
malloc_chunk
(type['pwndbg.aglib.heap.structs.MallocChunk'] | None
) – -
malloc_state
(type['pwndbg.aglib.heap.structs.MallocState'] | None
) – -
tcache_perthread_struct
(type['pwndbg.aglib.heap.structs.TcachePerthreadStruct'] | None
) – -
tcache_entry
(type['pwndbg.aglib.heap.structs.TcacheEntry'] | None
) – -
mallinfo
(type['pwndbg.aglib.heap.structs.CStruct2GDB'] | None
) – -
malloc_par
(type['pwndbg.aglib.heap.structs.MallocPar'] | None
) – -
largebin_reverse_lookup_32
– -
largebin_reverse_lookup_32_big
– -
largebin_reverse_lookup_64
– -
arenas
(tuple[Arena, ...]
) –Return a tuple of all current arenas.
-
malloc_alignment
(int
) –Corresponds to MALLOC_ALIGNMENT in glibc malloc.c
-
size_sz
(int
) –Corresponds to SIZE_SZ in glibc malloc.c
-
malloc_align_mask
(int
) –Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
-
minsize
(int
) –Corresponds to MINSIZE in glibc malloc.c
-
min_chunk_size
(int
) –Corresponds to MIN_CHUNK_SIZE in glibc malloc.c
-
multithreaded
(bool
) –Is malloc operating within a multithreaded environment.
-
tcache_next_offset
(int
) –
thread_cache property
¤
Locate a thread's tcache struct. We try to find its address in Thread Local Storage (TLS) first, and if that fails, we guess it's at the first chunk of the heap.
tcache_perthread_struct property
¤
largebin_reverse_lookup_32 class-attribute
instance-attribute
¤
largebin_reverse_lookup_32 = (
512,
576,
640,
704,
768,
832,
896,
960,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_32_big class-attribute
instance-attribute
¤
largebin_reverse_lookup_32_big = (
1008,
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
2944,
3072,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
largebin_reverse_lookup_64 class-attribute
instance-attribute
¤
largebin_reverse_lookup_64 = (
1024,
1088,
1152,
1216,
1280,
1344,
1408,
1472,
1536,
1600,
1664,
1728,
1792,
1856,
1920,
1984,
2048,
2112,
2176,
2240,
2304,
2368,
2432,
2496,
2560,
2624,
2688,
2752,
2816,
2880,
2944,
3008,
3072,
3136,
3584,
4096,
4608,
5120,
5632,
6144,
6656,
7168,
7680,
8192,
8704,
9216,
9728,
10240,
10752,
12288,
16384,
20480,
24576,
28672,
32768,
36864,
40960,
65536,
98304,
131072,
163840,
262144,
524288,
)
malloc_align_mask property
¤
Corresponds to MALLOC_ALIGN_MASK in glibc malloc.c
multithreaded property
¤
Is malloc operating within a multithreaded environment.
prompt_for_brute_force_thread_arena_permission ¤
Check if the user wants to brute force the thread_arena's value.
prompt_for_brute_force_thread_cache_permission ¤
Check if the user wants to brute force the tcache's value.
prompt_for_tls_address ¤
Check if we can determine the TLS address and return it.
brute_force_tls_reference_in_got_section ¤
brute_force_tls_reference_in_got_section(
tls_address: int, validator: Callable[[int], bool]
) -> tuple[int, int] | None
Brute force the TLS-reference in the .got section to that can pass the validator.
brute_force_thread_local_variable_near_tls_base ¤
brute_force_thread_local_variable_near_tls_base(
tls_address: int, validator: Callable[[int], bool]
) -> tuple[int, int] | None
Brute force the thread-local variable near the TLS base address that can pass the validator.
get_heap ¤
Find & read the heap_info struct belonging to the chunk at 'addr'.
get_tcache ¤
get_tcache(
tcache_addr: int | None = None,
) -> "pwndbg.aglib.heap.structs.TcachePerthreadStruct" | None
get_sbrk_heap_region ¤
get_sbrk_heap_region() -> Page
Return a Page object representing the sbrk heap region. Ensure the region's start address is aligned to SIZE_SZ * 2, which compensates for the presence of GLIBC_TUNABLES. This heuristic version requires some sanity checks and may raise SymbolUnresolvableError if malloc's mp_
struct can't be resolved.
summarize ¤
Returns a textual summary of the specified address.
Parameters:
-
address
(int
) –Address of the heap block to summarize.
Returns:
-
str
–A string.
containing ¤
Returns the address of the allocation which contains 'address'.
Parameters:
-
address
(int
) –Address to look up.
Returns:
-
int
–An integer.
libc_has_debug_syms ¤
The struct malloc_chunk
comes from debugging symbols and it will not be there for statically linked binaries
largebin_reverse_lookup ¤
Pick the appropriate largebin_reverse_lookup_ function for this architecture.
chunk_key_offset ¤
Find the index of a field in the malloc_chunk struct.
64bit example
prev_size == 0 size == 8 fd == 16 bk == 24 ...
get_region ¤
Find the memory map containing 'addr'.
tcachebins ¤
tcachebins(tcache_addr: int | None = None) -> Bins | None
Returns: tuple(chain, count) or None
check_chain_corrupted ¤
Checks if the doubly linked list (of a {unsorted, small, large} bin) defined by chain_fd, chain_bk is corrupted.
Even if the chains do not cover the whole bin, they still are expected to be of the same length.
Returns True if the bin is certainly corrupted, otherwise False.
bin_at ¤
Modeled after glibc's bin_at function - so starts indexing from 1 https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty-security/view/head:/malloc/malloc.c#L1394
bin_at(1) returns the unsorted bin
Bin 1 - Unsorted BiN Bin 2 to 63 - Smallbins Bin 64 to 126 - Largebins
Returns: tuple(chain_from_bin_fd, chain_from_bin_bk, is_chain_corrupted) or None
largebin_index_32 ¤
Modeled on the GLIBC malloc largebin_index_32 macro.
largebin_index_32_big ¤
Modeled on the GLIBC malloc largebin_index_32_big macro.
largebin_index_64 ¤
Modeled on the GLIBC malloc largebin_index_64 macro.
largebin_index ¤
Pick the appropriate largebin_index_ function for this architecture.
heap_for_ptr ¤
Round a pointer to a chunk down to find its corresponding heap_info struct, the pointer must point inside a heap which does not belong to the main arena.
fetch_chunk_metadata ¤
fetch_chunk_metadata(
address: int, include_only_fields: set[ChunkField] | None = None
)