'Search for all instances of a pattern in memory from start to end
Args:
- start: start address (Int)
- end: end address (Int)
- search: string or python regex pattern (String)
- mem: cached mem to not re-read for repeated searches (raw bytes)
Returns:
- list of found result: (address(Int), hex encoded value(String))'

def searchmem(self, start, end, search, mem=None):

    result = []
    if (end < start):
        (start, end) = (end, start)
    if (mem is None):
        mem = self.dumpmem(start, end)
    if (not mem):
        return result
    if (isinstance(search, six.string_types) and search.startswith('0x')):
        search = search[2:]
        if ((len(search) % 2) != 0):
            search = ('0' + search)
        search = codecs.decode(search, 'hex')[::(-1)]
        search = re.escape(search)
    if (not isinstance(search, bytes)):
        search = search.encode('utf-8')
    try:
        p = re.compile(search)
    except:
        search = re.escape(search)
        p = re.compile(search)
    found = list(p.finditer(mem))
    for m in found:
        index = 1
        if ((m.start() == m.end()) and m.lastindex):
            index = (m.lastindex + 1)
        for i in range(0, index):
            if (m.start(i) != m.end(i)):
                result += [((start + m.start(i)), codecs.encode(mem[m.start(i):m.end(i)], 'hex'))]
    return result
