def cyclic_pattern_search(buf):
 result = []
 pattern = cyclic_pattern()
 p = re.compile((('[' + re.escape(to_binary_string(cyclic_pattern_charset()))) + ']{4,}'))
 found = p.finditer(buf)
 found = list(found)
 for m in found:
  s = buf[m.start():m.end()]
  i = pattern.find(s)
  k = 0
  while ((i == (-1)) and (len(s) > 4)):
   s = s[1:]
   k += 1
   i = pattern.find(s)
  if (i != (-1)):
   result += [((m.start() + k), len(s), i)]
 return result

def cyclic_pattern_search ( buf ) : result = [ ] pattern = cyclic_pattern ( ) p = re . compile ( ( ( '[' + re . escape ( to_binary_string ( cyclic_pattern_charset ( ) ) ) ) + ']{4,}' ) ) found = p . finditer ( buf ) found = list ( found ) for m in found : s = buf [ m . start ( ) : m . end ( ) ] i = pattern . find ( s ) k = 0 while ( ( i == ( - 1 ) ) and ( len ( s ) > 4 ) ) : s = s [ 1 : ] k += 1 i = pattern . find ( s ) if ( i != ( - 1 ) ) : result += [ ( ( m . start ( ) + k ) , len ( s ) , i ) ] return result
search all cyclic pattern pieces in a buffer args: - buf: buffer to search for returns: - list of tuple .