1
0
mirror of synced 2024-11-13 17:40:47 +01:00
bemaniutils/bemani/utils/binutils.py
2024-01-02 02:46:24 +00:00

45 lines
1.1 KiB
Python

import argparse
import sys
from bemani.protocol.binary import BinaryEncoding
from bemani.protocol.lz77 import Lz77
def main() -> None:
parser = argparse.ArgumentParser(description="A utility to convert binxml files to their XML representation.")
parser.add_argument(
"-i",
"--infile",
help="File containing an XML or binary node structure. Use - for stdin.",
type=str,
default=None,
required=True,
)
parser.add_argument(
"-c",
"--compressed",
help="File data is compressed with LZ77.",
action="store_true",
default=False,
)
args = parser.parse_args()
if args.infile == "-":
# Load from stdin
packet = sys.stdin.buffer.read()
else:
with open(args.infile, mode="rb") as myfile:
packet = myfile.read()
myfile.close()
if args.compressed:
packet = Lz77().decompress(packet)
benc = BinaryEncoding()
filexml = benc.decode(packet)
print(filexml)
if __name__ == "__main__":
main()