SHOW:
|
|
- or go back to the newest paste.
| 1 | import os | |
| 2 | import struct | |
| 3 | ||
| 4 | os.chdir( os.path.dirname( __file__ ) ) | |
| 5 | ||
| 6 | fp = r"add01dat.bin" | |
| 7 | fs = os.path.getsize(fp) | |
| 8 | ||
| 9 | with open(fp, "rb") as bin: | |
| 10 | offsets = [ ] | |
| 11 | while bin.tell() < fs: | |
| 12 | data = bin.read(4) | |
| 13 | offset = struct.unpack(">I", data)[0]
| |
| 14 | offsets.append(offset) | |
| 15 | if not offset: break | |
| 16 | ||
| 17 | numfiles = len(offsets) | |
| 18 | for i in range(numfiles): | |
| 19 | offset = offsets[i] | |
| 20 | if i + 1 < numfiles: | |
| 21 | size = offsets[i+1] - offset | |
| 22 | else: | |
| 23 | size = fs - offset | |
| 24 | with open(r"add01dat_%02d.bin" % i, "wb") as fout: | |
| 25 | bin.seek(offset) | |
| 26 | fout.write( bin.read(size) ) |