August 20, 20241 yr Supporter I try to decompress the compressed file of a certain game, LZMA compressed file Because it has a four-byte LZMA identifier followed by a four-byte decompression size I skipped these bytes and tried to use python's lzma library to decompress, but it said that the compressed file was not in the correct format Does it require special treatment? Can you discuss the specific decompression logic? Thank you very much. I attach a compressed file here. Additional: This game is Ace Racing from NetEase, developed using messiah. The other compression algorithm zzz4 (lz4) has been successfully processed and decompressed in python by referring to other scripts, but lzma keeps giving me the error message that it cannot be decompressed, so I need Understand his compression algorithm and logic lzma.zip
August 20, 20241 yr Supporter Solution Works fine in quickbms. try this script: idstring "LZMA" comtype lzma get UNCOMPRESSED_SIZE long get ARCHIVE_SIZE asize xmath COMPRESSED_SIZE "ARCHIVE_SIZE - 8" SavePos DATA_OFFSET get NAME basename get EXTENSION extension string NAME + ".decompressed." + EXTENSION clog NAME DATA_OFFSET COMPRESSED_SIZE UNCOMPRESSED_SIZE So maybe something is wrong with Python's lzma library that you're using.
August 21, 20241 yr Author Supporter There are many different variants of lzma, and I considered that I was using the wrong processing method, or incorrect modules, and was unable to decompress them in python, because I didn't know what version he was using, because I referred to the common lzma header, can't seem to find a matching type
August 21, 20241 yr Supporter 39 minutes ago, wq223 said: There are many different variants of lzma, and I considered that I was using the wrong processing method, or incorrect modules, and was unable to decompress them in python, because I didn't know what version he was using, because I referred to the common lzma header, can't seem to find a matching type It uses standard one. you can use it with pylzma module. here, the decompressor and compressor in python. need install pylzma module and tkinter because of viadagem com janelinha that i did" import os import struct import pylzma import tkinter as tk from tkinter import filedialog, messagebox # Function to decompress LZMA def decompress_lzma(input_file): with open(input_file, 'rb') as f: # Check if the file has the 'LZMA' magic name magic_name = f.read(4) if magic_name != b'LZMA': raise ValueError("File does not have the 'LZMA' magic name") # Get the uncompressed size (UNCOMPRESSED_SIZE) uncompressed_size = struct.unpack('<I', f.read(4))[0] # Get the total file size (ARCHIVE_SIZE) f.seek(0, os.SEEK_END) archive_size = f.tell() # Calculate the compressed size (COMPRESSED_SIZE) compressed_size = archive_size - 8 # Save the starting position of the compressed data (DATA_OFFSET) data_offset = f.seek(8, os.SEEK_SET) # Create the output file name basename, extension = os.path.splitext(input_file) output_file = f"{basename}.decompressed{extension}" # Read the compressed data f.seek(data_offset) compressed_data = f.read(compressed_size) # Decompress the data decompressed_data = pylzma.decompress(compressed_data, maxlength=uncompressed_size) # Write the decompressed data to the output file with open(output_file, 'wb') as out_f: out_f.write(decompressed_data) return output_file # Function to compress a file using LZMA def compress_lzma(input_file): with open(input_file, 'rb') as f: # Read the input file data data = f.read() # Compress the data using the desired parameters compressed_data = pylzma.compress( data, eos=True, dictionary=23, # 2 MB dictionary size (within the valid range of 0-27) fastBytes=32, literalContextBits=3, #3 same used in your game 4 you get better compression literalPosBits=0, algorithm = 2 ) # Create the output file name basename, extension = os.path.splitext(input_file) output_file = f"{basename}.lzma" # Write the LZMA header and compressed data with open(output_file, 'wb') as out_f: # Write the 'LZMA' magic name out_f.write(b'LZMA') # Write the uncompressed size out_f.write(struct.pack('<I', len(data))) # Write the compressed data out_f.write(compressed_data) return output_file # Function to handle file selection and decompression def decompress_file(): input_file = filedialog.askopenfilename(filetypes=[("LZMA Files", "*.lzma"), ("All Files", "*.*")]) if input_file: try: output_file = decompress_lzma(input_file) messagebox.showinfo("Success", f"File decompressed and saved as: {output_file}") except Exception as e: messagebox.showerror("Error", str(e)) # Function to handle file selection and compression def compress_file(): input_file = filedialog.askopenfilename(filetypes=[("All Files", "*.*")]) if input_file: try: output_file = compress_lzma(input_file) messagebox.showinfo("Success", f"File compressed and saved as: {output_file}") except Exception as e: messagebox.showerror("Error", str(e)) # Create the main application window root = tk.Tk() root.title("LZMA Compressor/Decompressor") # Set the size of the window root.geometry("400x100") # width x height # Create and place the buttons compress_button = tk.Button(root, text="Compress File", command=compress_file) compress_button.pack(pady=10) decompress_button = tk.Button(root, text="Decompress File", command=decompress_file) decompress_button.pack(pady=10) # Start the Tkinter event loop root.mainloop() lzma.py
August 21, 20241 yr Author Supporter Thank you very much for your script, now I finally understand the logic
Create an account or sign in to comment