unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.49k stars 1.33k forks source link

Python module installers ImportError #208

Closed McLovi9 closed 8 years ago

McLovi9 commented 8 years ago

I tried "Python 2.7 module for Windows" installers and its not working out of the box.

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 81, in raise ImportError("ERROR: fail to load the dynamic library.")


I've tested on 32-bit XP and 64-bit Win7 the same problem

aquynh commented 8 years ago

can you copy this attached file to overwrite your C:\python27\Lib\site-packages\unicorn\unicorn.py, then run your Python code again to see what the output is?

unicorn.txt

McLovi9 commented 8 years ago

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

import unicorn

  1. Trying to load: C:\Python27\lib\site-packages\unicorn\libwinpthread-1.dll
  2. Trying to load: C:\Python27\lib\site-packages\unicorn\libgcc_s_dw2-1.dll
  3. Trying to load: C:\Python27\lib\site-packages\unicorn\libintl-8.dll
  4. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.so
  5. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.dylib
  6. Trying to load: C:\Python27\Lib\site-packages\unicorn\libwinpthread-1.dll
  7. Trying to load: C:\Python27\Lib\site-packages\unicorn\libgcc_s_dw2-1.dll
  8. Trying to load: C:\Python27\Lib\site-packages\unicorn\libintl-8.dll
  9. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.so
  10. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.dylib

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 85, in raise ImportError("ERROR: fail to load the dynamic library.") ImportError: ERROR: fail to load the dynamic library.

Mar10us commented 8 years ago

Try changing the order of the dll loading into: _all_windows_dlls = ("libwinpthread-1.dll", "libgcc_s_seh-1.dll", "libiconv-2.dll", "libintl-8.dll","libglib-2.0-0.dll") (located in unicorn.py line 23)

and add a (double) backslash behind the libpath on line 19

_lib_path = split(__file__)[0]+'\\'

Also: I removed "libgcc_s_dw2-1.dll" from the list because it doesnot exist in the zip or package

this mod works on win7x64

McLovi9 commented 8 years ago

no luck, I've tested on XP I assume its the same on my win7 x64

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

import unicorn

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 19, in lib_path = split(_file)[0]+'\' NameError: name '_file' is not defined

Mar10us commented 8 years ago

Did you copied the line from this site or did you added the backslashes manually? Seems you are missing a underscore... Add an extra underscore behind the var _file; it should have 2 underscores as on line 17

McLovi9 commented 8 years ago

I copied it from this site

McLovi9 commented 8 years ago

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 29, in _lib_file = join(_lib_path, dll) NameError: name '_lib_path' is not defined

Mar10us commented 8 years ago

copying directly from this site is not the best way to alter code... This time you are missing the start underscore on line 19; it should be _lib_path

_lib_path = split(__file__)[0]+'\\'

I edited the post with correct formatting...

McLovi9 commented 8 years ago

import unicorn

  1. Trying to load: C:\Python27\lib\site-packages\unicorn\libwinpthread-1.dll
  2. Trying to load: C:\Python27\lib\site-packages\unicorn\libiconv-2.dll
  3. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.so
  4. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.dylib
  5. Trying to load: C:\Python27\Lib\site-packages\unicorn\libwinpthread-1.dll
  6. Trying to load: C:\Python27\Lib\site-packages\unicorn\libiconv-2.dll
  7. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.so
  8. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.dylib

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 85, in raise ImportError("ERROR: fail to load the dynamic library.") ImportError: ERROR: fail to load the dynamic library.

Mar10us commented 8 years ago

stick to the proposed order of dll's:

_all_windows_dlls = ("libwinpthread-1.dll", "libgcc_s_seh-1.dll", "libiconv-2.dll", "libintl-8.dll","libglib-2.0-0.dll")

or try changing the order untils a dll loads correctly. The last successful loaded dll was libwinthread-1.dll in your case. It failed on libiconv-2.dll so its continuing with libunicorn.so

I added a print after the except line to debug which dll failed:

except OSError:
    print 'error loading='+ _lib_file
    pass
McLovi9 commented 8 years ago

I do stick to the proposed order of dll _all_windows_dlls = ("libwinpthread-1.dll", "libgcc_s_seh-1.dll", "libiconv-2.dll", "libintl-8.dll","libglib-2.0-0.dll")

Adding print 'error loading='+ _lib_file did not changed anything (nothing new in the log)

aquynh commented 8 years ago

@McLovi9, can you paste the output with the above DLL list?

McLovi9 commented 8 years ago

its the same (nothing new in the log)

import unicorn

  1. Trying to load: C:\Python27\lib\site-packages\unicorn\libwinpthread-1.dll
  2. Trying to load: C:\Python27\lib\site-packages\unicorn\libiconv-2.dll
  3. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.so
  4. Trying to load: C:\Python27\lib\site-packages\unicorn\libunicorn.dylib
  5. Trying to load: C:\Python27\Lib\site-packages\unicorn\libwinpthread-1.dll
  6. Trying to load: C:\Python27\Lib\site-packages\unicorn\libiconv-2.dll
  7. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.so
  8. Trying to load: C:\Python27\Lib\site-packages\unicorn\libunicorn.dylib

Traceback (most recent call last): File "<pyshell#0>", line 1, in import unicorn File "C:\Python27\lib\site-packages\unicorninit.py", line 4, in from unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError File "C:\Python27\lib\site-packages\unicorn\unicorn.py", line 86, in raise ImportError("ERROR: fail to load the dynamic library.") ImportError: ERROR: fail to load the dynamic library.

Sadly, I cant attach my unicorn.py file.

aquynh commented 8 years ago

for Win XP, can you use this order and report the result?

_all_windows_dlls = ("libwinpthread-1.dll", "libgcc_s_dw2-1.dll", "libiconv-2.dll", "libintl-8.dll","libglib-2.0-0.dll")
aquynh commented 8 years ago

for Win64, can you use this order?

_all_windows_dlls = ("libwinpthread-1.dll", "libgcc_s_seh-1.dll", "libiconv-2.dll", "libintl-8.dll", "libglib-2.0-0.dll")
aquynh commented 8 years ago

to keep it simple, overwrite your c:\python27\lib\site-packages\unicorn\unicorn.py with this file https://gist.githubusercontent.com/aquynh/eb0fc442f3e7e17e5bb0/raw/748279d75dbd919bf50f2375ae7a6d847e73fd55/unicorn.py on both your Win32 XP & Win64 7 to see if it solves your problem.

McLovi9 commented 8 years ago

wow, it seems to work! I mean import unicorn no error (tested on XP and Win7 x64). Thank you

aquynh commented 8 years ago

fixed this issue in Python binding & also uploaded new Python installers with this new fix. thanks.

egberts commented 8 years ago

When executing import unicorn, now getting ImportError on my CentOS 6.6...

$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import unicorn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/unicorn/__init__.py", line 4, in <module>
    from .unicorn import Uc, uc_version, uc_arch_supported, version_bind, debug, UcError
  File "/usr/lib/python2.6/site-packages/unicorn/unicorn.py", line 81, in <module>
    raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.

Same error message using the maintainer's unicorn.txt as unicorn.py inside /usr/lib/python/site-packages/unicorn.

Performed following command to get a feel of what Python is trying to open during this simple Python import unicorn statement:

echo "import unicorn" > test.py
chmod a+x test.py
strace -f test.py 2>&1 | grep open | grep -v "No such file"

Output is captured here: strace-opens.log.txt