'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"), ("C", "C"))]}'

def cmpmem(self, start, end, buf):

    line_len = 32
    if (end < start):
        (start, end) = (end, start)
    mem = self.dumpmem(start, end)
    if (mem is None):
        return None
    length = min(len(mem), len(buf))
    result = {}
    lineno = 0
    for i in range((length // line_len)):
        diff = 0
        bytes_ = []
        for j in range(line_len):
            offset = ((i * line_len) + j)
            bytes_ += [(mem[offset:(offset + 1)], buf[offset:(offset + 1)])]
            if (mem[offset] != buf[offset]):
                diff = 1
        if (diff == 1):
            result[(start + lineno)] = bytes_
        lineno += line_len
    bytes_ = []
    diff = 0
    for i in range((length % line_len)):
        offset = (lineno + i)
        bytes_ += [(mem[offset:(offset + 1)], buf[offset:(offset + 1)])]
        if (mem[offset] != buf[offset]):
            diff = 1
    if (diff == 1):
        result[(start + lineno)] = bytes_
    return result
