about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2012-07-27 20:32:13 +0200
committerserpilliere <devnull@localhost>2012-07-27 20:32:13 +0200
commit699fef619157212209d4f0fdcc2ecf69bb0cdd19 (patch)
treeb958bff69f006a496e8b64408c46539450c29ca9
parent61fa2b382970497e7dffff6bc0f667e8bb070bd7 (diff)
downloadmiasm-699fef619157212209d4f0fdcc2ecf69bb0cdd19.tar.gz
miasm-699fef619157212209d4f0fdcc2ecf69bb0cdd19.zip
arch: dis function has a new generic API!
-rw-r--r--miasm/arch/arm_arch.py6
-rw-r--r--miasm/arch/ia32_arch.py28
-rw-r--r--miasm/arch/java_arch.py18
-rw-r--r--miasm/arch/ppc_arch.py5
4 files changed, 32 insertions, 25 deletions
diff --git a/miasm/arch/arm_arch.py b/miasm/arch/arm_arch.py
index 1bc1fc53..9b446334 100644
--- a/miasm/arch/arm_arch.py
+++ b/miasm/arch/arm_arch.py
@@ -613,7 +613,7 @@ class arm_mnemo_metaclass(type):
         raise ValueError('ambiquity %s'%str(ret))
 
 
-    def dis(cls, bin, amode = None, sex = None):
+    def dis(cls, bin, attrib = {}):
         if type(bin) == str:
             bin = bin_stream(bin)
         elif not isinstance(bin, bin_stream):
@@ -907,6 +907,10 @@ class arm_mn(object):
 
             self.parse_args(full_mnemo)
 
+    def get_attrib(self):
+        return {}
+
+
     def parse_opts(self, rest):
         pass
     def str2name(self, n):
diff --git a/miasm/arch/ia32_arch.py b/miasm/arch/ia32_arch.py
index 3c1906a2..41577bcc 100644
--- a/miasm/arch/ia32_arch.py
+++ b/miasm/arch/ia32_arch.py
@@ -1278,18 +1278,17 @@ x86mndb = x86allmncs()
 class x86_mnemo_metaclass(type):
     rebuilt_inst = True
 
-    def dis(cls, op, admode = u32, opmode = u32, sex = 0):
+
+    def dis(cls, op, attrib = {}):
         i = cls.__new__(cls)
-        i.__init__(admode, opmode, sex)
-        i.opmode = opmode
-        i.admode = admode
+        i.__init__(attrib)
         u = i._dis(op)
         if not u:
             return None
         return i
     def asm(cls, l, symbol_off = []):
         i = cls.__new__(cls)
-        i.__init__(admode = u32, opmode = u32, sex = 0)
+        i.__init__() # admode = u32, opmode = u32, sex = 0)
         return i._asm(l, symbol_off)
 
 
@@ -1357,12 +1356,17 @@ class x86_mnemo_metaclass(type):
 
 class x86_mn:
     __metaclass__ = x86_mnemo_metaclass
-    def __init__(self, admode = u32, opmode = u32, sex = 0):
-        self.admode = admode
-        self.opmode = opmode
+    def __init__(self, attrib = {}):
+        self.opmode = attrib.get('opmode', u32)
+        self.admode = attrib.get('opmode', u32)
         self.mnemo_mode = self.opmode
         self.cmt = ""
 
+
+    def get_attrib(self):
+        return {"opmode":self.opmode,
+                "admode":self.admode}
+
     @classmethod
     def prefix2hex(self, prefix):
         return reduce(lambda x,y:x+chr(y), prefix, "")
@@ -1458,14 +1462,9 @@ class x86_mn:
             raise ValueError('unknown mnemo mode %s'%str(im))
 
     def _dis(self, bin):
-
-
-
         if type(bin) == str:
             from miasm.core.bin_stream import bin_stream
-
             bin = bin_stream(bin)
-
         init_offset = bin.offset
 
         try:
@@ -2295,8 +2294,7 @@ if __name__ == '__main__':
 
 
     instr = x86mnemo.dis('0fa9'.replace(' ', '').decode('hex'),
-                         admode=x86_afs.u16,
-                         opmode=x86_afs.u16)
+                         {"admode":x86_afs.u16,"opmode":x86_afs.u16})
     print instr
     print instr.arg
     print instr.l
diff --git a/miasm/arch/java_arch.py b/miasm/arch/java_arch.py
index 3672b778..3bbe0077 100644
--- a/miasm/arch/java_arch.py
+++ b/miasm/arch/java_arch.py
@@ -393,10 +393,10 @@ mnemonic('iflt', 155, 3, "if 'value' is less than 0, branch to the 16-bit instru
 class java_mnemo_metaclass(type):
     rebuilt_inst = False
     
-    def dis(cls, op, admode=None, sex=0, offset=0, ):
+    def dis(cls, op, attrib = {} ):
         i = cls.__new__(cls)
-        i.__init__(sex)
-        u = i._dis(op, offset)
+        i.__init__(0)
+        u = i._dis(op)
         if not u: return None
         return i
     
@@ -457,8 +457,10 @@ class java_mnemo_metaclass(type):
 class java_mn:
     __metaclass__ = java_mnemo_metaclass
     def __init__(self, sex=0):
-        self.sex = sex
-    
+        self.sex = 0
+    def get_attrib(self):
+        return {}
+
     def breakflow(self):
         return self.m.breakflow
     def splitflow(self):
@@ -551,15 +553,15 @@ class java_mn:
             return out
         return "%-15s" % self.m.name + " ".join(map(str, arg))
     
-    def _dis(self, bin, offset=0):
+    def _dis(self, bin):
         if type(bin) is str:
             from miasm.core.bin_stream import bin_stream
             bin = bin_stream(bin)
-        self.offset = bin.offset + offset
+        self.offset = bin.offset
         try:
             self.m = mnemo_db[ord(bin.readbs(1))]
             self.arg = self.m.argfmt.get(bin, sex=self.sex, address=self.offset)
-            self.l = bin.offset + offset - self.offset
+            self.l = bin.offset  - self.offset
         except Exception as e:
             log.warning(e.message)
             return False
diff --git a/miasm/arch/ppc_arch.py b/miasm/arch/ppc_arch.py
index 94c564ad..455dbebf 100644
--- a/miasm/arch/ppc_arch.py
+++ b/miasm/arch/ppc_arch.py
@@ -443,7 +443,7 @@ class ppc_mnemo_metaclass(type):
         raise ValueError('ambiquity %s'%str(ret))
 
 
-    def dis(cls, bin, *kargs):
+    def dis(cls, bin, attrib = {}):
         if type(bin) == str:
             bin = bin_stream(bin)
         elif not isinstance(bin, bin_stream):
@@ -786,6 +786,9 @@ class ppc_mn(object):
 
             self.parse_args(full_mnemo)
 
+    def get_attrib(self):
+        return {}
+
     def parse_opts(self, rest):
         if rest:
             raise ValueError('should not have rest here ', rest)