import os, re, sys PAT = re.compile(rb'(/dev/mtd[a-z/]*\d*|mtdblock|nandwrite|nanddump|flash_erase(all)?|flashcp|eraseall|mtd_debug|NBLXLoad|-t jffs2|jffs2)', re.I) root = sys.argv[1] hits = {} for r, dd, ff in os.walk(root): rel_r = os.path.relpath(r, root) if rel_r.startswith(('proc', 'sys', 'dev', 'usr/share/doc', 'usr/share/man', 'usr/lib/ipkg', 'usr/include')): continue for f in ff: p = os.path.join(r, f) if os.path.islink(p): continue try: d = open(p, 'rb').read() except Exception: continue if b'\0' in d[:1024] and not d.startswith(b'\x7fELF'): continue # skip non-ELF binary data found = sorted(set(m.group(0).decode('latin1') for m in PAT.finditer(d))) if found: hits[os.path.relpath(p, root)] = found for k in sorted(hits): kind = 'ELF ' if open(os.path.join(root, k), 'rb').read(4) == b'\x7fELF' else 'TEXT' print(f" {kind} {k:52} {hits[k][:5]}")