angr: Error using simuvex unicorn plugin on MacOS

I get an error when using the unicorn engine for the analysis:

s = p.factory.blank_state(addr=0x401260, add_options=simuvex.o.unicorn, remove_options={simuvex.o.LAZY_SOLVES})

I installed Angr in a pypy virtualenv so had to install unicorn manually (not available in pip), but I tried several unicorn scripts and they work ok and when installing Angr, it finds it:

Requirement already satisfied (use --upgrade to upgrade): unicorn in /Users/alvaro/virtualenvs/angr_pypy/site-packages/unicorn-1.0-py2.7.egg (from simuvex->angr)

but when I select the unicorn engine I get the following error (add_options=simuvex.o.unicorn):

Traceback (most recent call last):
  File "app_main.py", line 75, in run_toplevel
  File "solve_rock_angr.py", line 40, in <module>
    print main()
  File "solve_rock_angr.py", line 25, in main
    pg.explore(find=0x401428, avoid=0x40186d)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path_group.py", line 806, in explore
    n=n)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path_group.py", line 830, in run
    return self.step(n=n, step_func=step_func, until=until_func, stash=stash)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path_group.py", line 520, in step
    pg = pg._one_step(stash=stash, selector_func=selector_func, successor_func=successor_func, check_func=check_func, **kwargs)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path_group.py", line 311, in _one_step
    r = self._one_path_step(a, successor_func=successor_func, check_func=check_func, **kwargs)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path_group.py", line 208, in _one_path_step
    successors = a.step(**kwargs)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path.py", line 337, in step
    self._make_sim_run(throw=throw)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/path.py", line 368, in _make_sim_run
    self._run = self._project.factory.sim_run(self.state, **self._run_args)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/angr/factory.py", line 167, in sim_run
    r = SimUnicorn(state, stop_points=stops)
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/simuvex/s_unicorn.py", line 29, in __init__
    self.state.unicorn.setup()
  File "/Users/alvaro/virtualenvs/angr_pypy/site-packages/simuvex/plugins/unicorn_engine.py", line 825, in setup
    self._uc_state = _UC_NATIVE.alloc(self.uc._uch, self.cache_key)
AttributeError: 'NoneType' object has no attribute 'alloc'

_UC_NATIVE seems to reference sim_unicorn.dylib in MacOS. Is this a simuvex library? I can only find libunicorn.dylib in my system.

Thanks, A

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 44 (31 by maintainers)

Most upvoted comments

Sorry for my reply late to this thread. I finally solved the issue as there was some confusion going on with the filenames and paths. So here is the thing, after I did pip install angr, there exists the following files

  • /Library/Python/2.7/site-packages/unicorn/lib/libunicorn.dylib
  • /Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib

Then I did run the following commands

  • sudo install_name_tool -change libunicorn.1.dylib /Library/Python/2.7/site-packages/unicorn/lib/libunicorn.dylib /Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib

  • sudo install_name_tool -change libpyvex.dylib /Library/Python/2.7/site-packages/pyvex/lib/libpyvex.dylib /Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib

And now I can import angr without any anger! šŸ˜‰ Thanks a lot @ltfish @rhelmot for being consistently patient with me. šŸ‘ šŸ˜Š

@ltfish Pardon my ignorance but Iā€™m not familiar with DYLIB_LIBRARY_PATH.

Iā€™m installing angr as follows:

āžœ  ~ pip install angr --no-cache-dir --no-binary all    
Collecting angr
  Downloading angr-6.7.1.13.post2.tar.gz (269kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 276kB 1.2MB/s 
Requirement already satisfied: capstone in /Library/Python/2.7/site-packages (from angr)
Requirement already satisfied: networkx in /Library/Python/2.7/site-packages (from angr)
Collecting futures (from angr)
  Downloading futures-3.0.5-py2-none-any.whl
Requirement already satisfied: progressbar in /Library/Python/2.7/site-packages (from angr)
Collecting mulpyplexer (from angr)
  Downloading mulpyplexer-0.07.tar.gz
Collecting cooldict (from angr)
  Downloading cooldict-1.02.tar.gz
Collecting ana (from angr)
  Downloading ana-0.03.zip
Collecting archinfo>=6.7.1.13 (from angr)
  Downloading archinfo-6.7.1.13.tar.gz
Collecting pyvex>=6.7.1.13.post2 (from angr)
  Downloading pyvex-6.7.1.13.post2.tar.gz (49kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 51kB 7.2MB/s 
Collecting claripy>=6.7.1.13.post2 (from angr)
  Downloading claripy-6.7.1.13.post2.tar.gz (94kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 102kB 3.3MB/s 
Collecting simuvex>=6.7.1.13.post2 (from angr)
  Downloading simuvex-6.7.1.13.post2.tar.gz (186kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 194kB 686kB/s 
Collecting cle>=6.7.1.13.post2 (from angr)
  Downloading cle-6.7.1.13.post2.tar.gz (42kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 51kB 5.5MB/s 
Collecting cachetools (from angr)
  Downloading cachetools-2.0.0-py2.py3-none-any.whl
Collecting decorator>=3.4.0 (from networkx->angr)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Requirement already satisfied: pycparser in /Library/Python/2.7/site-packages (from pyvex>=6.7.1.13.post2->angr)
Requirement already satisfied: cffi>=1.0.3 in /Library/Python/2.7/site-packages (from pyvex>=6.7.1.13.post2->angr)
Collecting angr-only-z3-custom==9002 (from claripy>=6.7.1.13.post2->angr)
  Downloading angr-only-z3-custom-9002.tar.gz
Requirement already satisfied: bintrees in /Library/Python/2.7/site-packages (from simuvex>=6.7.1.13.post2->angr)
Collecting enum34 (from simuvex>=6.7.1.13.post2->angr)
  Downloading enum34-1.1.6-py2-none-any.whl
Requirement already satisfied: dpkt-fix in /Library/Python/2.7/site-packages (from simuvex>=6.7.1.13.post2->angr)
Collecting unicorn (from simuvex>=6.7.1.13.post2->angr)
  Downloading unicorn-1.0.0rc2.tar.gz (1.7MB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 1.7MB 6.0MB/s 
Requirement already satisfied: pyelftools in /Library/Python/2.7/site-packages (from cle>=6.7.1.13.post2->angr)
Requirement already satisfied: idalink in /Library/Python/2.7/site-packages (from cle>=6.7.1.13.post2->angr)
Collecting pefile (from cle>=6.7.1.13.post2->angr)
  Downloading pefile-2016.3.28.tar.gz (58kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 61kB 13.0MB/s 
Collecting z3-solver (from angr-only-z3-custom==9002->claripy>=6.7.1.13.post2->angr)
  Downloading z3-solver-4.5.1.0.tar.gz (3.7MB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 3.7MB 3.9MB/s 
Requirement already satisfied: rpyc in /Library/Python/2.7/site-packages (from idalink->cle>=6.7.1.13.post2->angr)
Requirement already satisfied: future in /Library/Python/2.7/site-packages (from pefile->cle>=6.7.1.13.post2->angr)
Collecting plumbum (from rpyc->idalink->cle>=6.7.1.13.post2->angr)
  Downloading plumbum-1.6.3-py2.py3-none-any.whl (99kB)
    100% |ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ| 102kB 14.3MB/s 
Installing collected packages: futures, mulpyplexer, ana, cooldict, archinfo, pyvex, z3-solver, angr-only-z3-custom, claripy, cachetools, enum34, unicorn, simuvex, pefile, cle, angr, decorator, plumbum
  Running setup.py install for mulpyplexer ... done
  Running setup.py install for ana ... done
  Running setup.py install for cooldict ... done
  Running setup.py install for archinfo ... done
  Running setup.py install for pyvex ... done
  Running setup.py install for z3-solver ... done
  Running setup.py install for angr-only-z3-custom ... done
  Running setup.py install for claripy ... done
  Running setup.py install for unicorn ... done
  Running setup.py install for simuvex ... done
  Running setup.py install for pefile ... done
  Running setup.py install for cle ... done
  Running setup.py install for angr ... done
Successfully installed ana-0.3 angr-6.7.1.13.post2 angr-only-z3-custom-9002 archinfo-6.7.1.13 cachetools-2.0.0 claripy-6.7.1.13.post2 cle-6.7.1.13.post2 cooldict-1.2 decorator-4.0.11 enum34-1.1.6 futures-3.0.5 mulpyplexer-0.7 pefile-2016.3.28 plumbum-1.6.3 pyvex-6.7.1.13.post2 simuvex-6.7.1.13.post2 unicorn-1.0.0rc2 z3-solver-4.5.1.0

and this is what Iā€™m getting in the Python REPL

āžœ  ~ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> try:
...     import angr
... except Exception as e:
...     print "Error: " + str(e)
... 
<type 'exceptions.OSError'> dlopen(/Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib, 6): Library not loaded: libunicorn.1.dylib
  Referenced from: /Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib
  Reason: unsafe use of relative rpath libunicorn.1.dylib in /Library/Python/2.7/site-packages/simuvex/lib/sim_unicorn.dylib with restricted binary <traceback object at 0x108350ea8>
>>> 

What do you suggest I should do?