#!/usr/bin/env python3 # https://github.com/mncoppola/ws30/blob/master/basefind.py import os import re import signal import struct import sys from operator import itemgetter chars = "A-Za-z0-9/\\-:.,_$%'\"()[\]<> " min_length = 10 scores = [] top_score = 0 regexp = bytes("[{}]{{{:d},}}".format(chars, min_length), "us-ascii") pattern = re.compile(regexp) regexpc = bytes("[{}]{{1,}}".format(chars), "us-ascii") patternc = re.compile(regexpc) def get_strings(filename, size): table = set() offset = 0 with open(filename, "rb") as f: while True: if offset >= size: break f.seek(offset) try: data = f.read(10) except: break match = pattern.match(data) if match: f.seek(offset - 1) try: char = f.read(1) except: continue if not patternc.match(char): table.add(offset) offset += len(match.group(0)) offset += 1 return table def get_pointers(filename): table = {} with open(filename, "rb") as f: while True: try: value = struct.unpack("= (base + size): continue offset = ptr - base if offset in str_table: score += ptr_table[ptr] if score: scores.append((base, score)) if score > top_score: top_score = score print("New highest score, 0x{:x}: {:d}".format(base, score)) high_scores(0, 0)