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

Method search_binpattern_by_address

tools/gef.py:5766–5795  ·  view source on GitHub ↗

Search a binary pattern within a range defined by arguments.

(self, binpattern: bytes, start_address: int, end_address: int)

Source from the content-addressed store, hash-verified

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."""
5768
5769 step = self["nr_pages_chunk"] * gef.session.pagesize
5770 locations = []
5771
5772 for chunk_addr in range(start_address, end_address, step):
5773 if chunk_addr + step > end_address:
5774 chunk_size = end_address - chunk_addr
5775 else:
5776 chunk_size = step
5777
5778 try:
5779 mem = gef.memory.read(chunk_addr, chunk_size)
5780 except gdb.MemoryError as e:
5781 return []
5782 preview_size = self["max_size_preview"]
5783 for match in re.finditer(binpattern, mem):
5784 start = chunk_addr + match.start()
5785 preview = str(mem[slice(*match.span())][0:preview_size]) + "..."
5786 size_match = match.span()[1] - match.span()[0]
5787 if size_match > 0:
5788 size_match -= 1
5789 end = start + size_match
5790
5791 locations.append((start, end, preview))
5792
5793 del mem
5794
5795 return locations
5796
5797 def search_pattern(self, pattern: str, section_name: str) -> None:
5798 """Search a pattern within the whole userland memory."""

Callers 1

do_invokeMethod · 0.95

Calls 2

readMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected