mirror of https://github.com/pwndbg/pwndbg.git
-s/--step First skipping blocks of memory between results
-l/--limit Stop searching after finding N results -a/--align A match must be aligned at the specified boundarypull/1894/head
parent
f642efbd92
commit
d008d14f4b
@ -1 +1 @@
|
||||
Subproject commit a9b56502f68e8ef7e4086331099bb645583be0a0
|
||||
Subproject commit 25bae64f45e5e957cab5083a1067acc88ce70ec5
|
||||
@ -0,0 +1,31 @@
|
||||
/* For testing the search command.
|
||||
*
|
||||
* We just spray some known patterns into memory
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void break_here(void) {}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc(0x100000);
|
||||
memset(p, 0x0, 0x100000);
|
||||
|
||||
// Pattern we want to find with -i 0x1000
|
||||
for (int i = 0; i < 0x100000; i += 0x100) {
|
||||
*(unsigned int *)(p + i) = 0xd00dbeef;
|
||||
}
|
||||
|
||||
// Pattern we want to avoid with -a 0x8
|
||||
for (int i = 0; i < 0x100000; i += 0x100) {
|
||||
*(unsigned int *)(p + i + 0x17) = 0xd00dbeef;
|
||||
}
|
||||
|
||||
break_here();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,160 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import gdb
|
||||
|
||||
import tests
|
||||
|
||||
SEARCH_BINARY = tests.binaries.get("search_memory.out")
|
||||
SEARCH_PATTERN = 0xD00DBEEF
|
||||
|
||||
|
||||
def test_command_search_limit(start_binary):
|
||||
"""
|
||||
Tests simple search limit
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
search_limit = 10
|
||||
result_str = gdb.execute(
|
||||
f"search --dword {SEARCH_PATTERN} -l {search_limit} -w", to_string=True
|
||||
)
|
||||
result_count = 0
|
||||
result_value = None
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
if not result_value:
|
||||
result_value = line.split(" ")[2]
|
||||
result_count += 1
|
||||
|
||||
assert result_count == search_limit
|
||||
assert result_value == hex(SEARCH_PATTERN)
|
||||
|
||||
|
||||
def test_command_search_alignment(start_binary):
|
||||
"""
|
||||
Tests aligned search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
alignment = 8
|
||||
result_str = gdb.execute(f"search --dword {SEARCH_PATTERN} -a {alignment} -w", to_string=True)
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_address = line.split(" ")[1]
|
||||
assert int(result_address, 16) % alignment == 0
|
||||
|
||||
|
||||
def test_command_search_step(start_binary):
|
||||
"""
|
||||
Tests stepped search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
step = 0x1000
|
||||
result_str = gdb.execute(f"search --dword {SEARCH_PATTERN} -s {step} -w", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
# We allocate 0x100000 bytes
|
||||
assert result_count == 0x100
|
||||
|
||||
|
||||
def test_command_search_byte_width(start_binary):
|
||||
"""
|
||||
Tests 1-byte search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
result_str = gdb.execute(f"search --byte 0xef -w", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
assert result_count > 0x100
|
||||
|
||||
|
||||
def test_command_search_word_width(start_binary):
|
||||
"""
|
||||
Tests 2-byte word search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
result_str = gdb.execute(f"search --word 0xbeef -w", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
assert result_count > 0x100
|
||||
|
||||
|
||||
def test_command_search_dword_width(start_binary):
|
||||
"""
|
||||
Tests 4-byte dword search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
result_str = gdb.execute(f"search --dword 0xd00dbeef -w", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
assert result_count > 0x100
|
||||
|
||||
|
||||
def test_command_search_qword_width(start_binary):
|
||||
"""
|
||||
Tests 8-byte qword search
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
result_str = gdb.execute(f"search --dword 0x00000000d00dbeef -w", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
assert result_count > 0x100
|
||||
|
||||
|
||||
def test_command_search_rwx(start_binary):
|
||||
"""
|
||||
Tests searching for rwx memory only
|
||||
"""
|
||||
start_binary(SEARCH_BINARY)
|
||||
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
result_str = gdb.execute(f"search --dword 0x00000000d00dbeef -w -x", to_string=True)
|
||||
result_count = 0
|
||||
for line in result_str.split("\n"):
|
||||
if line.startswith("[anon_"):
|
||||
result_count += 1
|
||||
|
||||
assert result_count == 0
|
||||
Loading…
Reference in new issue