Skip to content

Loading APK file leads to crash on WebFile signature check due to library files #360

@stypr

Description

@stypr

Code

# signature check
signature = reader.read_string_to_null()
if not signature.startswith(("UnityWebData", "TuanjieWebData")):
raise ValueError(f"Invalid WebFile signature: {signature!r}. Expected 'UnityWebData' or 'TuanjieWebData'.")
self.signature = signature

Error

Stacktrace

  File "./update_apphash.py", line 171, in read_app_hash
    env = UnityPy.load(os.path.join(os.getcwd(), path_to_apk))
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 57, in __init__
    self.load_zip_file(arg)
    ~~~~~~~~~~~~~~~~~~^^^^^
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 171, in load_zip_file
    self.load_assets(z.namelist(), lambda x: z.open(x, "r"))  # type: ignore
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 295, in load_assets
    self.load_file(data, name=path)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 150, in load_file
    f = self.load_zip_file(file)
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 171, in load_zip_file
    self.load_assets(z.namelist(), lambda x: z.open(x, "r"))  # type: ignore
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 295, in load_assets
    self.load_file(data, name=path)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/UnityPy/environment.py", line 152, in load_file
    f = parse_file(reader, self, name=stream_name, typ=typ, is_dependency=is_dependency)
  File "/usr/local/lib/python3.14/site-packages/UnityPy/helpers/ImportHelper.py", line 143, in parse_file
    f = files.WebFile(reader, parent, name=name, is_dependency=is_dependency)
  File "/usr/local/lib/python3.14/site-packages/UnityPy/files/WebFile.py", line 42, in __init__
    raise ValueError(f"Invalid WebFile signature: {signature!r}. Expected 'UnityWebData' or 'TuanjieWebData'.")
ValueError: Invalid WebFile signature: ''. Expected 'UnityWebData' or 'TuanjieWebData'.

Bug

When directly loading APK file by UnityPy.load, APK containing library related files like okhttp3/internal/publicsuffix/publicsuffixes.gz will cause the script to crash with ValueError.

It turns out that previous versions (1.23.0 and lower) did work as it just gave return statement. The latest version (1.24.2) now pops an error while reading gzip files because of the newer commit (e480609 commit).

I would like to know if this commit was mandatory.

Can we revert this commit, or have a return with a warning instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions