K0lb3 / UnityPy

UnityPy is python module that makes it possible to extract/unpack and edit Unity assets
MIT License
761 stars 113 forks source link

Crashes when reading RGB24 Texture2D #211

Closed JunkBeat closed 8 months ago

JunkBeat commented 9 months ago

Here's my code. No error is given, the script just crashes:

def readTexture2D(obj: Texture2D):
    try:
        data = obj.read()
        img = data.image
    except Exception as e:
        print(f"[Error] Unable to load image: {e}")
        return

For now I'm using a stub to avoid problems:

tree = obj.read_typetree()
if tree["m_TextureFormat"] == 3:
    raise Exception("[Error] Unsupported format (RGB24)")  

Assets: https://drive.google.com/file/d/1hbofMD1ZEZZGCN6V8bntgrhpumdAumQh/view?usp=sharing Python version: 3.10.2 UnityPy version: 1.10.3

K0lb3 commented 8 months ago

I can't replicate this. My test script finishes without any issue showing up.

import UnityPy

env = UnityPy.load("resources.assets")
for obj in env.objects:
    if obj.type.name == "Texture2D":
        print(x, x.m_TextureFormat)
        x = obj.read()
        x2 = obj.read_typetree()
        x.image

print("done")
K0lb3 commented 8 months ago

Furthermore....the data is being passed to PIL, so the issue is most likely not related to UnityPy, as it uses no unsafe code itself.