Skip to content

Instantly share code, notes, and snippets.

@lbr77
Last active October 25, 2024 02:29
Show Gist options
  • Save lbr77/df5b3d068c270108bb56e395b33af769 to your computer and use it in GitHub Desktop.
Save lbr77/df5b3d068c270108bb56e395b33af769 to your computer and use it in GitHub Desktop.
A script for decoding Wallpaper Engine scene.pkg file.
#!/bin/python3
# From https://wetranslate.thiscould.work/scene.pkg/ and
# Exactly from https://github.com/redpfire/we
import io
import zipfile
class File:
def __init__(self,content:bytes):
self.content = content
self.offset = 0
def readInt(self):
num = int.from_bytes(self.content[self.offset:self.offset+4],byteorder="little")
self.offset += 4
return num
def readStr(self):
len = self.readInt()
str = self.content[self.offset:self.offset+len].decode()
self.offset += len
return str
def readFileInfo(self):
name = self.readStr()
offset = self.readInt()
len = self.readInt()
return {
"name":name,
"offset":offset,
"length":len
}
def readBinary(self,offset,length):
return self.content[self.offset+offset:self.offset+offset+length]
class PkgReaderV1:
def __init__(self,content:bytes):
self.content = File(content)
self.version = self.get_version()
self.fileCount = self.get_file_count()
self.files = []
self.get_file_info()
self.get_file_content()
self.zipfile = self.generate_zip()
def get_version(self):
return self.content.readStr()
def get_file_count(self):
return self.content.readInt()
def get_file_info(self):
for _ in range(self.fileCount):
self.files.append(self.content.readFileInfo())
def get_file_content(self):
for file in self.files:
file["content"] = self.content.readBinary(file["offset"],file["length"])
def generate_zip(self):
zip_data = io.BytesIO()
with zipfile.ZipFile(zip_data,"w") as f:
for file in self.files:
f.writestr(file["name"],file["content"])
return zip_data
def save(self):
with open("scene.zip","wb") as f:
f.write(self.zipfile.getvalue())
if __name__ == "__main__":
with open("scene.pkg","rb") as f:
fileContent = f.read()
pkg = PkgReaderV1(fileContent)
pkg.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment