MCPcopy Create free account
hub / github.com/HexHive/NASS / search_pattern_by_address

Method search_pattern_by_address

tools/gef.py:5735–5764  ·  view source on GitHub ↗

Search a pattern within a range defined by arguments.

(self, pattern: str, start_address: int, end_address: int)

Source from the content-addressed store, hash-verified

5733 return
5734
5735 def search_pattern_by_address(self, pattern: str, start_address: int, end_address: int) -> List[Tuple[int, int, Optional[str]]]:
5736 """Search a pattern within a range defined by arguments."""
5737 _pattern = gef_pybytes(pattern)
5738 step = self["nr_pages_chunk"] * gef.session.pagesize
5739 locations = []
5740
5741 for chunk_addr in range(start_address, end_address, step):
5742 if chunk_addr + step > end_address:
5743 chunk_size = end_address - chunk_addr
5744 else:
5745 chunk_size = step
5746
5747 try:
5748 mem = gef.memory.read(chunk_addr, chunk_size)
5749 except gdb.MemoryError as e:
5750 return []
5751
5752 for match in re.finditer(_pattern, mem):
5753 start = chunk_addr + match.start()
5754 if is_ascii_string(start):
5755 ustr = gef.memory.read_ascii_string(start) or ""
5756 end = start + len(ustr)
5757 else:
5758 ustr = gef_pystring(_pattern) + "[...]"
5759 end = start + len(_pattern)
5760 locations.append((start, end, ustr))
5761
5762 del mem
5763
5764 return locations
5765
5766 def search_binpattern_by_address(self, binpattern: bytes, start_address: int, end_address: int) -> List[Tuple[int, int, Optional[str]]]:
5767 """Search a binary pattern within a range defined by arguments."""

Callers 2

search_patternMethod · 0.95
do_invokeMethod · 0.95

Calls 6

gef_pybytesFunction · 0.85
is_ascii_stringFunction · 0.85
gef_pystringFunction · 0.85
read_ascii_stringMethod · 0.80
readMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected