Commits

Victor Stinner  committed 37aa0ed

support distorm3

  • Participants
  • Parent commits b4b41d7

Comments (0)

Files changed (2)

 python-ptrace 0.6.3
 -------------------
 
+ * Support distrom3
  * Rename strace.py option --socketcall to --socket, and fix this option for
    FreeBSD and Linux/64 bits
  * Add MANIFEST.in: include all files in source distribution (tests, cptrace

File ptrace/disasm.py

 
 try:
     from ptrace.cpu_info import CPU_I386, CPU_X86_64
-    from ptrace.pydistorm import Decode
-    if CPU_X86_64:
-        from ptrace.pydistorm import Decode64Bits as DecodeBits
-        MAX_INSTR_SIZE = 11
-    elif CPU_I386:
-        from ptrace.pydistorm import Decode32Bits as DecodeBits
-        MAX_INSTR_SIZE = 8
-    else:
-        raise ImportError()
+    try:
+        from distorm3 import Decode
+        if CPU_X86_64:
+            from distorm3 import Decode64Bits as DecodeBits
+            MAX_INSTR_SIZE = 11
+        elif CPU_I386:
+            from distorm3 import Decode32Bits as DecodeBits
+            MAX_INSTR_SIZE = 8
+        else:
+            raise ImportError("CPU not supported")
+        DISTORM3 = True
+    except ImportError, err:
+        DISTORM3 = False
+        from ptrace.pydistorm import Decode
+        if CPU_X86_64:
+            from ptrace.pydistorm import Decode64Bits as DecodeBits
+            MAX_INSTR_SIZE = 11
+        elif CPU_I386:
+            from ptrace.pydistorm import Decode32Bits as DecodeBits
+            MAX_INSTR_SIZE = 8
+        else:
+            raise ImportError("CPU not supported")
     from ptrace import PtraceError
 
     class Instruction:
          - text (str): string representing the whole instruction
         """
         def __init__(self, instr):
-            self.address = instr.offset
-            self.size = instr.size
-            self.mnemonic = str(instr.mnemonic)
-            self.operands = str(instr.operands)
-            self.hexa = str(instr.instructionHex)
-            self.text = "%s %s" % (self.mnemonic, self.operands)
+            if DISTORM3:
+                self.address, self.size, self.text, self.hexa = instr
+            else:
+                self.address = instr.offset
+                self.size = instr.size
+                self.hexa = unicode(instr.instructionHex)
+                self.text = u"%s %s" % (instr.mnemonic, instr.operands)
 
         def __str__(self):
             return self.text
         raise PtraceError("Unable to disassemble %r" % code)
 
     HAS_DISASSEMBLER = True
-except (ImportError, OSError):
+except (ImportError, OSError), err:
     # OSError if libdistorm64.so doesn't exist
     HAS_DISASSEMBLER = False