Skip to content

Include FMOD libraries for all available architectures? #39

Closed

Description

@szescxz

I'm using UnityPy on an ARM machine, and import UnityPy raises an OSError:

OSError: /usr/local/lib/python3.7/dist-packages/UnityPy/lib/FMOD/Linux/32bit/libfmod.so: cannot open shared object file: No such file or directory

Obviously the pointed file is for x86 only.
So:

  • Could you add an try...except block so it does not block importing?
  • Of course, including libraries for all architectures is also appreciated.

Activity

  1. K0lb3 commented on Mar 28, 2021

    @K0lb3
    Owner

    Thanks for the report.
    I will probably do both,
    include the arm & armhf libraries and a try..except for systems that aren't supported.

  2. K0lb3 commented on Mar 28, 2021

    @K0lb3
    Owner

    I don't really know much about Raspberry Pi or Linux on arm projects in general,
    so could you check if the following code would do:

    _dll = None
    
    try: # try to load fmod library
        # library root path
        ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    
        # determine system - Windows, Darwin, Linux, Android
        system = platform.system()
        if system == "Linux" and "ANDROID_BOOTLOGO" in os.environ:
            system = "Android"
        # determine architecture
        machine = platform.machine()
        arch = platform.architecture()[0]
        
        if system in ["Windows","Darwin"]:
            if arch == "32bit":
                arch = "x86"
            elif arch == "64bit":
                arch = "x64"
        elif system == "Linux":
            if arch == "32bit":
                arch = "x86"
                if "arm" in machine:
                    # Raspberry Pi and Linux on arm projects
                    arch = "armhf" if machine.endswith("l") else "arm"
            elif arch == "64bit":
                arch = "x86_64"
        elif system == "Android":
            # TODO
            pass
        else:
            raise NotImplementedError("unknown system")
    
        # build path and load library
        LIB_PATH = os.path.join(ROOT, "lib", "FMOD", system, arch)
        if system == 'Windows':
            _dll = WinDLL(os.path.join(LIB_PATH, "fmod.dll"))
        elif system in ["Linux","Android"]:
            _dll = CDLL(os.path.join(LIB_PATH, "libfmod.so"))
        elif system == "Darwin":
            _dll = CDLL(os.path.join(LIB_PATH, "libfmod.dylib"))    
    except:
        pass
        ```
        
    The _dll is only checked right before it's put to use in the new version.
    
            
  3. K0lb3 commented on Mar 28, 2021

    @K0lb3
    Owner

    You could also try to install the UnityPy/fmod-arm branch and see if it works.

  4. szescxz commented on Mar 29, 2021

    @szescxz
    Author

    You could also try to install the UnityPy/fmod-arm branch and see if it works.

    Seems working on a Raspberry Pi 3B+ running armv7l, 32-bit Python.
    Some thoughts:

    • The warning hint in the previous version should be preserved to let user know why the library wasn't loaded
    • On armv8l running 64-bit Python it would still choose the x86_64 Linux library (and it would fail silently due to the try...except block). Since there are no official binary file for 64-bit ARM (?), it should probably be treated as unsupported?
  5. K0lb3 commented on Mar 29, 2021

    @K0lb3
    Owner

    The warning hint in the previous version should be preserved to let user know why the library wasn't loaded

    It's shown as exception when the user tries to use the dll while it's not loaded, so the user will still know what to do.

    On armv8l running 64-bit Python it would still choose the x86_64 Linux library (and it would fail silently due to the try...except block). Since there are no official binary file for 64-bit ARM (?), it should probably be treated as unsupported?

    There is no 64bit ARM version of FMOD for Linux. It only offers arm, armhf, x86 and x86_64.
    I guess that 64bit ARM can still load 32bit arm?
    I'm not sure if 64bit can handle armhf tho.

  6. K0lb3 commented on Mar 29, 2021

    @K0lb3
    Owner

    I just tried it with an aarch64 docker....and failed to load all libraries,
    with arm, armhf and x86 throwing wrong elf error and x86_x84 failing due to another problem.

  7. K0lb3 commented on Mar 29, 2021

    @K0lb3
    Owner

    The arm64-v8a android build resulted in the same error as x86_64,
    but considering that it's no wrong elf error, I would assume that the problem is related to the docker.

    If you have a Linux on a real 64bit arm system can you try this yourself?

    • clone fmod-branch
    # python3
    import os, ctypes
    
    fmod_branch_path : str
    lib_path = os.path.join(fmod_branch_path, "Unity","lib")
    for sys in ["Linux", "Android"]:
        p = os.path.join(lib_path, sys)
        for so in (os.path.join(root, f) for root, dirs, files in os.walk(p) for f in files):
            try:
                ctypes.CDLL(so)
                print("Could load:", so)
            except:
                print("Failed to load:", so)
  8. szescxz commented on Mar 31, 2021

    @szescxz
    Author

    I guess that 64bit ARM can still load 32bit arm?

    Yes but they have to use 32-bit Python (64-bit Python cannot load 32-bit libraries, but it's possible to run 32-bit Python on a 64-bit machine), and since platform.architecture() returns the architecture of Python itself, we don't have to handle the fallback here.

    If you have a Linux on a real 64bit arm system can you try this yourself?

    Unfortunately I don't, I just think it's better to tell user that ARM64 isn't supported at the moment.
    Something like:

    elif system == "Linux":
        # Raspberry Pi and Linux on arm projects
        if "arm" in machine:
            if arch == "32bit":
                arch = "armhf" if machine.endswith("l") else "arm"
            elif arch == "64bit":
                # Raise an exception for now; Once it gets supported by FMOD we can just modify the code here
                raise NotImplementedError("ARM64 not supported")
        elif arch == "32bit":
            arch = "x86"
        elif arch == "64bit":
            arch = "x86_64"
  9. K0lb3 commented on Apr 8, 2021

    @K0lb3
    Owner

    Sorry that I forgot to reply.

    Yes but they have to use 32-bit Python (64-bit Python cannot load 32-bit libraries, but it's possible to run 32-bit Python on a 64-bit machine), and since platform.architecture() returns the architecture of Python itself, we don't have to handle the fallback here.

    I guess that this can be put in the exception message as well.
    Setting up an x86 python env shouldn't be a problem on Linux.

    I will merge the relevant changes as well as the Linux arm libraries with the next update in some days.

  10. added a commit that references this issue on Sep 14, 2025
    5fbee36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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