about summary refs log tree commit diff stats
path: root/example/ida/utils.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-09-07 12:45:49 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2017-09-07 12:45:49 +0200
commit7d09562e0ad14d4bcc00d858d117064ff5d7adbf (patch)
tree5ef30a9196c6f0d10c7428593182d8b10b5bc613 /example/ida/utils.py
parentd806661d8407f580578e51194dbf3c3520b399b2 (diff)
downloadmiasm-7d09562e0ad14d4bcc00d858d117064ff5d7adbf.tar.gz
miasm-7d09562e0ad14d4bcc00d858d117064ff5d7adbf.zip
Example/ida: fix size issue
Diffstat (limited to 'example/ida/utils.py')
-rw-r--r--example/ida/utils.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/example/ida/utils.py b/example/ida/utils.py
index a7d2418a..3f7c3c8a 100644
--- a/example/ida/utils.py
+++ b/example/ida/utils.py
@@ -5,30 +5,28 @@ from miasm2.analysis.machine import Machine
 from miasm2.ir.translators import Translator
 import miasm2.expression.expression as m2_expr
 
-def max_size_to_size(max_size):
-    for size in [16, 32, 64]:
-        if (1 << size) - 1 == max_size:
-            return size
-    return None
-
 def guess_machine():
     "Return an instance of Machine corresponding to the IDA guessed processor"
 
     processor_name = GetLongPrm(INF_PROCNAME)
-    max_size = GetLongPrm(INF_START_SP)
-    size = max_size_to_size(max_size)
+    info = idaapi.get_inf_structure()
+
+    if info.is_64bit():
+        size = 64
+    elif info.is_32bit():
+        size = 32
+    else:
+        size = None
 
     if processor_name == "metapc":
+        size2machine = {
+            64: "x86_64",
+            32: "x86_32",
+            None: "x86_16",
+        }
+
+        machine = Machine(size2machine[size])
 
-        # HACK: check 32/64 using INF_START_SP
-        if max_size == 0x80:  # TODO XXX check
-            machine = Machine("x86_16")
-        elif size == 32:
-            machine = Machine("x86_32")
-        elif size == 64:
-            machine = Machine("x86_64")
-        else:
-            raise ValueError('cannot guess 32/64 bit! (%x)' % max_size)
     elif processor_name == "ARM":
         # TODO ARM/thumb
         # hack for thumb: set armt = True in globals :/