Last active
May 26, 2021 13:55
-
-
Save lgolubyev/d365501ffb0d660e414361043041b3d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lz4.block | |
import sys | |
import struct | |
import os | |
def print_usage_and_exit(): | |
sys.exit("usage: py .\\decompressor.py target_path") | |
cwd = os.path.abspath(os.getcwd()) | |
def decompress(filePath): | |
input_filepath = filePath | |
output_path = os.path.join("extracted", ""); | |
if(not os.path.exists(output_path)): | |
os.mkdir(output_path) | |
output_filepath = os.path.join(output_path, os.path.basename(filePath)) | |
header_expected_magic = b'XALZ' | |
with open(input_filepath, "rb") as xalz_file: | |
data = xalz_file.read() | |
if data[:4] != header_expected_magic: | |
sys.exit("The input file does not contain the expected magic bytes, aborting ...") | |
header_index = data[4:8] | |
header_uncompressed_length = struct.unpack('<I', data[8:12])[0] | |
payload = data[12:] | |
print("header index: %s" % header_index) | |
print("compressed payload size: %s bytes" % len(payload)) | |
print("uncompressed length according to header: %s bytes" % header_uncompressed_length) | |
decompressed = lz4.block.decompress(payload, uncompressed_size=header_uncompressed_length) | |
with open(output_filepath, "wb") as output_file: | |
output_file.write(decompressed) | |
output_file.close() | |
print("result written to file") | |
if __name__ == "__main__": | |
n = 0 | |
for file in os.listdir(cwd): | |
try: | |
if(file.endswith(".dll")): | |
decompress(file) | |
n += 1; | |
except: | |
print("failed to decompress " + os.path.basename(file)) | |
print("\\nDecompressed ", n, " assemblies!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment