code: def guess_peb_size(path):
      
      file_offset = 0
      offsets = []
      f = open(path, 'rb')
      f.seek(0,2)
      file_size = f.tell()+1
      f.seek(0)
  
      for _ in range(0, file_size, FILE_CHUNK_SZ):
          buf = f.read(FILE_CHUNK_SZ)
          for m in re.finditer(UBI_EC_HDR_MAGIC, buf):
              start = m.start()
  
              if not file_offset:
                  file_offset = start
                  idx = start
              else:
                  idx = start+file_offset
  
              offsets.append(idx)
  
          file_offset += FILE_CHUNK_SZ
      f.close()
  
      occurances = {}
      for i in range(0, len(offsets)):
          try:
              diff = offsets[i] - offsets[i-1]
          except:
              diff = offsets[i]
  
          if diff not in occurances:
              occurances[diff] = 0
  
          occurances[diff] += 1
  
      most_frequent = 0
      block_size = None
  
      for offset in occurances:
          if occurances[offset] > most_frequent:
              most_frequent = occurances[offset]
              block_size = offset
  
      return block_size
docs: Determine the most likely block size
  
      Arguments:
      Str:path    -- Path to file.
      
      Returns:
      Int         -- PEB size.
      
      Searches file for Magic Number, picks most 
          common length between them.