Skip to content

Commit

Permalink
printing 4 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
rjoberon committed Apr 23, 2024
1 parent 23e2549 commit 64fd5ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions _posts/2024-04-23-searching-for-the-index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ This creates an image 1024 pixels in width, so each line represents

We can see several segments with quite some regularities.

Skipping the first 16 bytes (which is likely the file header), and
then interpreting each 4 bytes as unsigned integer (`./src/mp.py -c
dump_ints un1.dat > un1_ints.tsv`), this segment basically contains
the byte offsets of the tiles: 316020, 328719, 351371, 384572, 405841,
446659, 483024, 525098, 566987, 619866, ...

So the coordinates of the tiles must be stored somewhere else.

## unknown2

![](/img/un2.png)
Expand Down
16 changes: 15 additions & 1 deletion src/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Author: rja
#
# Changes:
# 2024-04-23 (rja)
# - implemented dump_ints
# 2024-04-21 (rja)
# - implemented vis_content and accompanying functions
# - implemented vis_bytes and dump_bytes
Expand Down Expand Up @@ -194,10 +196,20 @@ def dump_bytes(fname):
print(pos, "{:10d}".format(lint), sep='\t')


def dump_ints(fname):
with open(fname, "rb") as f:
# skip 16 byte header
f.seek(16)
pos = 16
while ((b := f.read(4))):
lint = int.from_bytes(b, byteorder='little', signed=False)
print(pos, "{:10d}".format(lint), sep='\t')
pos += 4

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='read .mp files.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('input', type=str, help='input file')
parser.add_argument('-c', '--command', choices=['offsets', 'extract', 'vis', 'dump_bytes', 'vis_bytes'], default='offsets')
parser.add_argument('-c', '--command', choices=['offsets', 'extract', 'vis', 'dump_bytes', 'vis_bytes', 'dump_ints'], default='offsets')
parser.add_argument('--offset', type=int, help='offset to extract')
parser.add_argument('--width', type=int, help='vis: image width', default=2**10)
parser.add_argument('--bpp', type=int, help='vis: bytes per pixel', default=2**10)
Expand All @@ -214,5 +226,7 @@ def dump_bytes(fname):
vis_content(args.input, args.out, args.bpp, args.width)
elif args.command == 'dump_bytes':
dump_bytes(args.input)
elif args.command == 'dump_ints':
dump_ints(args.input)
elif args.command == 'vis_bytes':
vis_bytes(args.input, args.out)

0 comments on commit 64fd5ed

Please sign in to comment.