-
Notifications
You must be signed in to change notification settings - Fork 0
/
extracffy.py
77 lines (64 loc) · 2.75 KB
/
extracffy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Extracffy's CLI.
"""
import argparse
import zipfile
from api import Extracffy
__author__ = "Raccffy"
__version__ = "1.1.1"
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="extracffy",
description="Reference decompiler module for reading and extracting "
"obfuscated Minecraft resource packs.")
parser.add_argument("resources",
help="Minecraft resource pack.")
parser.add_argument("-o", "--output",
help="ZIP file output.",
required=True)
parser.add_argument("-v", "--verbose",
action="store_true",
help="Enable debug messages.")
parser.add_argument("-c", "--compression-level",
type=int,
default=5,
choices=range(0, 10),
help="Sets compression level for output resource pack. Default: 5")
parser.add_argument("--crc32-check",
action="store_true",
help="Enable CRC32 check.")
parser.add_argument("--mismatched-hash-action",
choices=("err", "warn",),
default="err",
help='Select action when hash check fails. Default: "err"')
parser.add_argument("--version",
action="version",
help="Show program's version and exit.",
version=f"%(prog)s {__version__}")
args = parser.parse_args()
extracffy = Extracffy(args.resources)
extracffy_idx = extracffy.cd_read()
with zipfile.ZipFile(args.output, "w") as f:
for idx in extracffy_idx:
if args.verbose:
print(f"{str(idx)}")
current_file_name = str(idx)
try:
data = extracffy.extract(idx, args.crc32_check)
except ValueError as e:
if args.invalid_crc_action == "err":
raise RuntimeError("Hash check failed.")
elif args.invalid_crc_action == "warn":
print(e)
data = extracffy.extract(idx, False)
else:
raise RuntimeError("Unknown hash check fail action.")
if args.compression_level == 0:
f.writestr(current_file_name,
data,
compress_type=zipfile.ZIP_STORED)
else:
f.writestr(current_file_name,
data,
compress_type=zipfile.ZIP_DEFLATED,
compresslevel=args.compression_level)
print("Success!")