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

Method cmpmem

peda.py:4574–4614  ·  view source on GitHub ↗

Compare content of a memory region with a file Usage: MYNAME start end file

(self, *arg)

Source from the content-addressed store, hash-verified

4572
4573 # cmpmem()
4574 def cmpmem(self, *arg):
4575 """
4576 Compare content of a memory region with a file
4577 Usage:
4578 MYNAME start end file
4579 """
4580 (start, end, filename) = normalize_argv(arg, 3)
4581 if filename is None:
4582 self._missing_argument()
4583
4584 try:
4585 buf = open(filename, "rb").read()
4586 except:
4587 error_msg("cannot read data from filename %s" % filename)
4588 return
4589
4590 result = peda.cmpmem(start, end, buf)
4591
4592 if result is None:
4593 warning_msg("failed to perform comparison")
4594 elif result == {}:
4595 msg("mem and filename are identical")
4596 else:
4597 msg("--- mem: %s -> %s" % (arg[0], arg[1]), "green", "bold")
4598 msg("+++ filename: %s" % arg[2], "blue", "bold")
4599 for (addr, bytes_) in result.items():
4600 msg("@@ 0x%x @@" % addr, "red")
4601 line_1 = "- "
4602 line_2 = "+ "
4603 for (mem_val, file_val) in bytes_:
4604 m_byte = "%02X " % ord(mem_val)
4605 f_byte = "%02X " % ord(file_val)
4606 if mem_val == file_val:
4607 line_1 += m_byte
4608 line_2 += f_byte
4609 else:
4610 line_1 += green(m_byte)
4611 line_2 += blue(f_byte)
4612 msg(line_1)
4613 msg(line_2)
4614 return
4615
4616 # xormem()
4617 def xormem(self, *arg):

Callers

nothing calls this directly

Calls 7

_missing_argumentMethod · 0.95
normalize_argvFunction · 0.85
error_msgFunction · 0.85
warning_msgFunction · 0.85
greenFunction · 0.85
blueFunction · 0.85
cmpmemMethod · 0.45

Tested by

no test coverage detected