'Patch memory start at an address with string/hexstring/int
Usage:
MYNAME address (multiple lines input)
MYNAME address "string"
MYNAME from_address to_address "string"
MYNAME (will patch at current $pc)'

def patch(self, *arg):

    (address, data, byte) = normalize_argv(arg, 3)
    address = to_int(address)
    end_address = None
    if (address is None):
        address = peda.getreg('pc')
    if ((byte is not None) and (to_int(data) is not None)):
        (end_address, data) = (to_int(data), byte)
        if (end_address < address):
            (address, end_address) = (end_address, address)
    if (data is None):
        data = ''
        while True:
            line = input('patch>    ')
            if (line.strip() == ''):
                continue
            if (line == 'end'):
                break
            user_input = line.strip()
            if user_input.startswith('0x'):
                data += hex2str(user_input)
            else:
                data += eval(('%s' % user_input))
    if (to_int(data) is not None):
        data = hex2str(to_int(data), peda.intsize())
    data = to_binary_string(data)
    data = data.replace('\\\\', '\\')
    if end_address:
        data *= (((end_address - address) + 1) // len(data))
    bytes_ = peda.writemem(address, data)
    if (bytes_ >= 0):
        msg(('Written    %d    bytes    to    0x%x' % (bytes_, address)))
    else:
        warning_msg("Failed    to    patch    memory,    try    'set    write    on'    first    for    offline    patching")
    return
