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

search-pattern better code #862

Merged
merged 1 commit into from
Jul 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 3 additions & 15 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5714,7 +5714,7 @@ def print_loc(self, loc: Tuple[int, int, str]) -> None:
def search_pattern_by_address(self, pattern: str, start_address: int, end_address: int) -> List[Tuple[int, int, Optional[str]]]:
"""Search a pattern within a range defined by arguments."""
_pattern = gef_pybytes(pattern)
step = 0x400 * 0x1000
step = self["nr_pages_chunk"] * gef.session.pagesize
locations = []

for chunk_addr in range(start_address, end_address, step):
Expand All @@ -5725,20 +5725,8 @@ def search_pattern_by_address(self, pattern: str, start_address: int, end_addres

try:
mem = gef.memory.read(chunk_addr, chunk_size)
except gdb.error as e:
estr = str(e)
if estr.startswith("Cannot access memory "):
#
# This is a special case where /proc/$pid/maps
# shows virtual memory address with a read bit,
# but it cannot be read directly from userspace.
#
# See: https://github.com/hugsy/gef/issues/674
#
err(estr)
return []
else:
raise e
except gdb.MemoryError as e:
return []

for match in re.finditer(_pattern, mem):
start = chunk_addr + match.start()
Expand Down