MCPcopy Create free account
hub / github.com/longld/peda / cmpmem

Method cmpmem

peda.py:1797–1843  ·  view source on GitHub ↗

Compare contents of a memory region with a buffer Args: - start: start address (Int) - end: end address (Int) - buf: raw bytes Returns: - dictionary of array of diffed bytes in hex (Dictionary) {123: [("A", "B"),

(self, start, end, buf)

Source from the content-addressed store, hash-verified

1795 return self.write_int(address, value, 8)
1796
1797 def cmpmem(self, start, end, buf):
1798 """
1799 Compare contents of a memory region with a buffer
1800
1801 Args:
1802 - start: start address (Int)
1803 - end: end address (Int)
1804 - buf: raw bytes
1805
1806 Returns:
1807 - dictionary of array of diffed bytes in hex (Dictionary)
1808 {123: [("A", "B"), ("C", "C"))]}
1809 """
1810 line_len = 32
1811 if end < start:
1812 (start, end) = (end, start)
1813
1814 mem = self.dumpmem(start, end)
1815 if mem is None:
1816 return None
1817
1818 length = min(len(mem), len(buf))
1819 result = {}
1820 lineno = 0
1821 for i in range(length//line_len):
1822 diff = 0
1823 bytes_ = []
1824 for j in range(line_len):
1825 offset = i*line_len+j
1826 bytes_ += [(mem[offset:offset + 1], buf[offset:offset + 1])]
1827 if mem[offset] != buf[offset]:
1828 diff = 1
1829 if diff == 1:
1830 result[start+lineno] = bytes_
1831 lineno += line_len
1832
1833 bytes_ = []
1834 diff = 0
1835 for i in range(length % line_len):
1836 offset = lineno+i
1837 bytes_ += [(mem[offset:offset + 1], buf[offset:offset + 1])]
1838 if mem[offset] != buf[offset]:
1839 diff = 1
1840 if diff == 1:
1841 result[start+lineno] = bytes_
1842
1843 return result
1844
1845 def xormem(self, start, end, key):
1846 """

Callers 1

cmpmemMethod · 0.45

Calls 1

dumpmemMethod · 0.95

Tested by

no test coverage detected