2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from bemani.protocol.binary import BinaryEncoding
|
2023-02-17 03:58:33 +01:00
|
|
|
from bemani.protocol.lz77 import Lz77
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
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,
|
|
|
|
)
|
2023-02-17 03:58:33 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-c",
|
|
|
|
"--compressed",
|
|
|
|
help="File data is compressed with LZ77.",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if args.infile == "-":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Load from stdin
|
|
|
|
packet = sys.stdin.buffer.read()
|
|
|
|
else:
|
|
|
|
with open(args.infile, mode="rb") as myfile:
|
|
|
|
packet = myfile.read()
|
|
|
|
myfile.close()
|
|
|
|
|
2023-02-17 03:58:33 +01:00
|
|
|
if args.compressed:
|
|
|
|
packet = Lz77().decompress(packet)
|
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
benc = BinaryEncoding()
|
|
|
|
filexml = benc.decode(packet)
|
|
|
|
print(filexml)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if __name__ == "__main__":
|
2019-12-08 22:43:49 +01:00
|
|
|
main()
|