What is an OZIP file? An OZIP file is a proprietary compressed image format used primarily by Android OEMs (like Asus, ZTE, and older Motorola devices) for firmware updates and system images. It is often an encrypted or transformed version of a standard EXT4, sparse image, or ZIP archive.
# Check magic if data[:4] != OZIP_MAGIC: raise ValueError("Not a valid OZIP file")
def detect_ozip_type(filepath): """Detect OZIP variant by reading header.""" with open(filepath, 'rb') as f: header = f.read(12) ozip extractor tool
# Often just raw ext4 or sparse image output_img = os.path.join(output_dir, 'system.img') with open(output_img, 'wb') as out: out.write(data) print(f"[+] Extracted ZTE OZIP to: output_img") Main function ------------------------------------------------------------ def main(): if len(sys.argv) < 2: print("Usage: ozip_extractor.py <input.ozip> [output_directory]") print("\nExample: ozip_extractor.py firmware.ozip ./extracted") sys.exit(1)
# The decrypted content is often a zip file or raw ext4 image # Try to detect ZIP header if decrypted[:2] == b'PK': output_zip = os.path.join(output_dir, 'extracted.zip') with open(output_zip, 'wb') as out: out.write(decrypted) print(f"[+] Extracted as ZIP: output_zip") # Attempt to unzip automatically import zipfile with zipfile.ZipFile(output_zip, 'r') as zip_ref: zip_ref.extractall(output_dir) print(f"[+] Unzipped contents to output_dir") else: # Assume it's an ext4 image output_img = os.path.join(output_dir, 'system.img') with open(output_img, 'wb') as out: out.write(decrypted) print(f"[+] Extracted as raw image: output_img") def extract_zte_ozip(input_path, output_dir): """Extract ZTE-specific OZIP (simpler header removal).""" with open(input_path, 'rb') as f: # ZTE OZIP has a 4-byte header 'ZTE\x00' then raw data header = f.read(4) if header != b'ZTE\x00': raise ValueError("Not a ZTE OZIP file") data = f.read() What is an OZIP file
input_file = sys.argv[1] if not os.path.exists(input_file): print(f"[-] File not found: input_file") sys.exit(1)
print(f"[*] Processing: input_file") ozip_type, version = detect_ozip_type(input_file) print(f"[*] Detected type: ozip_type") # Check magic if data[:4]
output_dir = sys.argv[2] if len(sys.argv) > 2 else "ozip_output" Path(output_dir).mkdir(parents=True, exist_ok=True)