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

NameError: global name 'KS_MODE_32' is not defined #6

Closed
AxDSan opened this issue Mar 30, 2017 · 9 comments
Closed

NameError: global name 'KS_MODE_32' is not defined #6

AxDSan opened this issue Mar 30, 2017 · 9 comments

Comments

@AxDSan
Copy link

AxDSan commented Mar 30, 2017

Prologue: Installed metame using pip install metame as recommended, ran metame and got the error.

Box: Linux kali 4.6.0-kali1-amd64 #1 SMP Debian 4.6.4-1kali1 (2016-07-21) x86_64 GNU/Linux (straight from Kali Linux VMWare Image Nightly Build)

Error Log:

root@kali:~# metame -i /root/Desktop/untitled.exe -o untitled_metamorphic.exe
[INFO] Opening file with r2
[INFO] Analyzing functions with r2
Function too big at 0x7c073377
Traceback (most recent call last):
  File "/usr/local/bin/metame", line 5, in <module>
    metame.main()
  File "/usr/local/lib/python2.7/dist-packages/metame/__init__.py", line 20, in main
    patches = r.iterate_fcn()
  File "/usr/local/lib/python2.7/dist-packages/metame/r2parser.py", line 32, in iterate_fcn
    arch = x86handler.X86Handler(self.bits, self.debug, self.force)
  File "/usr/local/lib/python2.7/dist-packages/metame/x86handler.py", line 73, in __init__
    ks_mode = KS_MODE_32 if self.bits == 32 else KS_MODE_64
NameError: global name 'KS_MODE_32' is not defined
@a0rtega
Copy link
Owner

a0rtega commented Mar 31, 2017

This looks like the same problem as #3. Can you check if your Keystone installation is correct?

@AxDSan
Copy link
Author

AxDSan commented Mar 31, 2017

I checked, last time I ran metame and installed everything I had some problems with Keystone indeed, however I paused metame installation and installed Keystone successfully and then went onto metame and restarted the installation and it installed properly, however the issue still appeared.

This is what shows up after trying to install keystone-engine:

root@kali:~# pip install keystone-engine
Requirement already satisfied: keystone-engine in /usr/local/lib/python2.7/dist-packages

I will redo everything installing keystone from git and will report back.

@AxDSan
Copy link
Author

AxDSan commented Mar 31, 2017

Followed everything straight from https://github.com/keystone-engine/keystone/blob/master/docs/COMPILE-NIX.md

and now I get #5

root@kali:~# metame -i /root/Desktop/untitled.exe -o /root/Desktop/untitled_.exe 
Traceback (most recent call last):
  File "/usr/local/bin/metame", line 5, in <module>
    metame.main()
  File "/usr/local/lib/python2.7/dist-packages/metame/__init__.py", line 5, in main
    import metame.r2parser as r2parser
  File "/usr/local/lib/python2.7/dist-packages/metame/r2parser.py", line 2, in <module>
    import metame.x86handler as x86handler
  File "/usr/local/lib/python2.7/dist-packages/metame/x86handler.py", line 6, in <module>
    from keystone import *
  File "/usr/local/lib/python2.7/dist-packages/keystone/__init__.py", line 4, in <module>
    from .keystone import Ks, ks_version, ks_arch_supported, version_bind, debug, KsError, __version__
  File "/usr/local/lib/python2.7/dist-packages/keystone/keystone.py", line 74, in <module>
    raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.

@live4java
Copy link

Quite a bit later, I know, but I have been seeing the exact same error under multiple attempted installs under Kali and Ubuntu installations. I've installed from scratch, a couple times start to finish, installing metame last after radare2 and keystone.

Could this be related to OpenStack having a "keystone" module as well?

@a0rtega
Copy link
Owner

a0rtega commented Mar 19, 2018

Yes, that seems to be the problem. I commented it in #3 as well.

@a0rtega a0rtega closed this as completed Mar 19, 2018
@SNFC
Copy link

SNFC commented Mar 29, 2018

@live4java sorry did you find a solution by now?

@cryptid11
Copy link

same NameError: name 'Ks' is not defined just pipinstalling keystone, after keystone-engine then the new ImportError: ERROR: fail to load the dynamic library., that is solved with this so, you have to compile and install also shared libraries...

question is, wtf dont they say this already in the INSTALL.md? lol

I think case is closed.

@cryptid11
Copy link

cryptid11 commented Jan 23, 2019

edit, actually I do that on ubuntu and it turns out that for some obscure reasons the init file remain empty, and even following the stuff in previous message doesnt works, so to solve put:

# Keystone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from . import arm_const, arm64_const, mips_const, sparc_const, hexagon_const, systemz_const, ppc_const, x86_const
from .keystone_const import *
from .keystone import Ks, ks_version, ks_arch_supported, version_bind, debug, KsError, __version__

in /usr/local/lib/python3.5/dist-packages/keystone/__init__.py

PS possibly related to https://docs.angr.io/introductory-errata/install#attributeerror-module-object-has-no-attribute-ks_arch_x-86

@marconilenza
Copy link

In case you are still having trouble with that, try replacing:

from keystone import *

with:

from keystone.keystone_const import KS_ARCH_X86, KS_MODE_64
from keystone.keystone import Ks

It should work.

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

6 participants