'Dump content of a memory region to raw binary file
Usage:
MYNAME file start end
MYNAME file mapname'

def dumpmem(self, *arg):

    (filename, start, end) = normalize_argv(arg, 3)
    if ((end is not None) and to_int(end)):
        if (end < start):
            (start, end) = (end, start)
        ret = peda.execute(('dump    memory    %s    0x%x    0x%x' % (filename, start, end)))
        if (not ret):
            warning_msg('failed    to    dump    memory')
        else:
            msg(("Dumped    %d    bytes    to    '%s'" % ((end - start), filename)))
    elif (start is not None):
        maps = peda.get_vmmap(start)
        if maps:
            fd = open(filename, 'wb')
            count = 0
            for (start, end, _, _) in maps:
                mem = peda.dumpmem(start, end)
                if (mem is None):
                    mem = ('\x00' * (end - start))
                fd.write(mem)
                count += (end - start)
            fd.close()
            msg(("Dumped    %d    bytes    to    '%s'" % (count, filename)))
        else:
            warning_msg('invalid    mapname')
    else:
        self._missing_argument()
    return
