Skip to content

Commit

Permalink
improve txt for ZTUAC
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Dec 8, 2024
1 parent 1c457e4 commit cde39f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions __version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# this file is auto-generated by the pre-commit hook increment_version.py
VERSION = "2024.12.08"
COMMIT_HASH = "c02af5cce"
COMMIT_TIME = "Sun Dec 8 11:56:19 2024 +0100"
COMMIT_HASH = "1c457e408"
COMMIT_TIME = "Sun Dec 8 12:04:27 2024 +0100"
19 changes: 14 additions & 5 deletions modules/formats/TXT.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ def extract(self, out_dir):
# unk = 128, usually
size, unk = struct.unpack("<2B", b[:2])
data = b[2:2+size*2]
elif self.mime_version in (2, 3):
# version 2 (PC1, JWE1) & 3 (PZ, JWE2, WH)
size = struct.unpack("<I", b[:4])[0]
data = b[4:4+size]
elif self.mime_version >= 4:
# PC2
size = struct.unpack("<Q", b[:8])[0]
data = b[8:8+size]
else:
# version 2 (PC1, JWE1) & 3 (PZ, JWE2, WH)
size = struct.unpack("<I", b[:4])[0]
data = b[4:4+size]
raise AttributeError(f"Unknown TXT format {self.mime_version}")
out_path = out_dir(self.name)
with open(out_path, "wb") as f:
f.write(data)
Expand All @@ -37,6 +39,13 @@ def extract(self, out_dir):
def _get_data(self, file_path):
"""Loads and returns the data for a TXT"""
raw_txt_bytes = self.get_content(file_path)
fmt = "<I" if self.mime_version in (2, 3) else "<Q"
root_entry = struct.pack(fmt, len(raw_txt_bytes)) + raw_txt_bytes + b"\x00"
if self.mime_version == 1:
prefix = struct.pack("<2B", len(raw_txt_bytes), 128)
elif self.mime_version in (2, 3):
prefix = struct.pack("<I", len(raw_txt_bytes))
elif self.mime_version == 4:
prefix = struct.pack("<Q", len(raw_txt_bytes))
else:
raise AttributeError(f"Unknown TXT format {self.mime_version}")
root_entry = prefix + raw_txt_bytes + b"\x00"
return root_entry + get_padding(len(root_entry), alignment=8)

0 comments on commit cde39f3

Please sign in to comment.