"""Scan a binary blob for MZ markers, validate as PE, dump each as separate file.""" import struct, sys, pathlib blob_path = pathlib.Path(sys.argv[1]) out_dir = pathlib.Path(sys.argv[2]) out_dir.mkdir(parents=True, exist_ok=True) data = blob_path.read_bytes() def pe_total_size(buf, off): """Compute size of PE image at offset using section table.""" # MZ at off; PE header offset at off+0x3C if off + 0x40 > len(buf): return None pe_off = struct.unpack_from(" len(buf) or buf[pe_start:pe_start+4] != b"PE\x00\x00": return None num_sections = struct.unpack_from(" {out.name}") n += 1 i = j + sz else: i = j + 2 print(f"\nExtracted {n} plain PE files into {out_dir}")