Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error installing on Apple Silicon #3

Open
lwerdna opened this issue Feb 26, 2024 · 2 comments
Open

Error installing on Apple Silicon #3

lwerdna opened this issue Feb 26, 2024 · 2 comments
Assignees

Comments

@lwerdna
Copy link
Owner

lwerdna commented Feb 26, 2024

BinaryNinja Log during installation:

[Default]   File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ctypes/__init__.py", line 376, in __init__
[Default]     self._handle = _dlopen(self._name, mode)
[Default]                    ^^^^^^^^^^^^^^^^^^^^^^^^^
[Default] OSError: dlopen(/Users/andrewl/Library/Application Support/Binary Ninja/python311/site-packages/capstone/lib/libcapstone.dylib, 0x0006): tried: '/Users/andrewl/Library/Application Support/Binary Ninja/python311/site-packages/capstone/lib/libcapstone.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/andrewl/Library/Application Support/Binary Ninja/python311/site-packages/capstone/lib/libcapstone.dylib' (no such file), '/Users/andrewl/Library/Application Support/Binary Ninja/python311/site-packages/capstone/lib/libcapstone.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

The wheel or whatever ends up with a dylib only for x86_64 instead of arm64.

When you delete plugins, the dependencies aren't deleted. So you can verify by removing keypatch, navigating to ~/Library/Application Support/Binary Ninja/python311/site-packages, deleting capstone and capstone-5.0.1.dist-info, then command palette for "Install python3 module...", enter capstone. The directories will reappear and:

$ file ./capstone/lib/libcapstone.dylib
./capstone/lib/libcapstone.dylib: Mach-O 64-bit dynamically linked shared library x86_64

Another test is to look how Binja actually installs stuff, how it invokes PIP:

[Default] Running pip ['/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin/python3.11', '-m', 'pip', '--isolated', '--disable-pip-version-check', 'install', '--upgrade', '--upgrade-strategy', 'only-if-needed', '--target', '/Users/andrewl/Library/Application Support/Binary Ninja/python311/site-packages', 'capstone']

We can then replicate this call outside of Binja and verify:

$ pip --isolated --disable-pip-version-check install --upgrade --upgrade-strategy only-if-needed --target /tmp/test capstone
$ file /tmp/test/capstone/lib/libcapstone.dylib
/tmp/test/capstone/lib/libcapstone.dylib: Mach-O 64-bit dynamically linked shared library x86_64

Capstone seems aware of this issue: Universal wheel for macOS contains only x86_64 build #2154.

@lwerdna lwerdna self-assigned this Feb 26, 2024
@lwerdna
Copy link
Owner Author

lwerdna commented Feb 26, 2024

Workaround: Install capstone with brew and then copy its arm64 .dylib into your pip installation.

$ brew install capstone
$ file /opt/homebrew/Cellar/capstone/5.0.1/lib/libcapstone.5.dylib
/opt/homebrew/Cellar/capstone/5.0.1/lib/libcapstone.5.dylib: Mach-O 64-bit dynamically linked shared library arm64

Use brew ls -v capstone if you're having difficulty seeing where it installed the dylib.

$ cd ~/Library/Application\ Support/Binary\ Ninja/python311/site-packages
$ cp /opt/homebrew/Cellar/capstone/5.0.1/lib/libcapstone.5.dylib ./capstone/lib/libcapstone.dylib

And restart Binja and log should show:

...
[Core] Loaded native plugin debuggercore
[Plugin Repository: community] Loaded python3 plugin 'lwerdna_keypatch_binja'
[Core] Loaded native plugin pythonplugin
...

@lwerdna
Copy link
Owner Author

lwerdna commented Feb 27, 2024

Another way to get the correct arm64 dylib is with:

$ pip install --target /tmp/test "git+https://github.com/capstone-engine/capstone#subdirectory=bindings/python/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant