moz2d_dump2bin.py (990B)
1 #!/usr/bin/env python 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 import os 7 from argparse import ArgumentParser 8 from pathlib import Path 9 from re import match 10 from tempfile import mkstemp 11 12 13 def main(): 14 aparse = ArgumentParser() 15 aparse.add_argument( 16 "stdout", 17 type=Path, 18 help="stdout file from Firefox run with MOZ2D_CAPTURE=1", 19 ) 20 args = aparse.parse_args() 21 22 with args.stdout.open() as dump: 23 for line in dump: 24 result = match(r"^<dump>([0-9A-Fa-f]+)</dump>\s*$", line) 25 if result is not None: 26 data = bytes.fromhex(result.group(1)) 27 fd, fn = mkstemp(prefix="moz2d-", suffix=".bin", dir=".") 28 os.write(fd, data) 29 os.close(fd) 30 print(f"wrote {fn}") 31 32 33 if __name__ == "__main__": 34 main()