a0rtega / metame

metame is a metamorphic code engine for arbitrary executables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NameError: global name 'KS_MODE_32' is not defined

AxDSan opened this issue · comments

commented

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

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

commented

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.

commented

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.

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?

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

commented

@live4java sorry did you find a solution by now?

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.

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

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.