From 64fd5ed2e9045eff57948dcb6c27305d0f4f4c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=A4schke?= Date: Tue, 23 Apr 2024 15:31:43 +0200 Subject: [PATCH] printing 4 bytes --- .../2024-04-23-searching-for-the-index.markdown | 8 ++++++++ src/mp.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/_posts/2024-04-23-searching-for-the-index.markdown b/_posts/2024-04-23-searching-for-the-index.markdown index f2e2168..92a6fd8 100644 --- a/_posts/2024-04-23-searching-for-the-index.markdown +++ b/_posts/2024-04-23-searching-for-the-index.markdown @@ -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) diff --git a/src/mp.py b/src/mp.py index c9f037c..d587a88 100755 --- a/src/mp.py +++ b/src/mp.py @@ -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 @@ -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) @@ -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)