about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xexample/disas_and_graph.py23
-rw-r--r--miasm/arch/ia32_arch.py23
-rw-r--r--miasm/arch/ia32_reg.py2
3 files changed, 35 insertions, 13 deletions
diff --git a/example/disas_and_graph.py b/example/disas_and_graph.py
index 57ea3f90..6f505df3 100755
--- a/example/disas_and_graph.py
+++ b/example/disas_and_graph.py
@@ -31,9 +31,9 @@ parser.add_option('-a', "--address", dest="address", metavar="ADDRESS",
                   help="address to disasemble")
 parser.add_option('-m', "--architecture", dest="machine",metavar="MACHINE",
                   help="architecture to use for disasm: arm, x86, ppc, java")
-parser.add_option('-M', "--architecture-options", dest="machine-options",
+parser.add_option('-M', "--architecture-options", dest="machine_options",
                   metavar="MACHINEOPTS",
-                  help="architecture options (16/32/64 bits, ...)")
+                  help="architecture options (u16/u32/u64 bits, ...)")
 parser.add_option('-r', "--rawfile", dest="rawfile", action="store_true",
                   default=False, metavar=None,
                   help="dont use PE/ELF/CLASS autodetect, disasm raw file")
@@ -116,7 +116,13 @@ elif data.startswith("\xca\xfe\xba\xbe"):
 
 
 else:
-    raise ValueError('cannot autodetect file type')
+    print 'WARNING cannot autodetect file type, using raw'
+    in_str = bin_stream.bin_stream(data)
+    if ad_to_dis == None:
+        ad_to_dis = 0
+    else:
+        ad_to_dis = int(ad_to_dis, 16)
+    mnemo = ia32_arch.x86_mn
 
 
 if options.machine:
@@ -148,8 +154,17 @@ for (n,f), ad in dll_dyn_funcs.items():
 
 
 def my_disasm_callback(ad):
+    admode = opmode = u32
+    if options.machine_options:
+        if options.machine_options in ['u16', 'u32']:
+            admode = opmode = options.machine_options
+        else:
+            raise ValueError('bad machine options')
     all_bloc = asmbloc.dis_bloc_all(mnemo, in_str, ad, set(),
-                                    symbol_pool=symbol_pool)
+                                    symbol_pool=symbol_pool,
+                                    amode = admode)
+    g = asmbloc.bloc2graph(all_bloc)
+    open('graph.txt', 'w').write(g)
     if mnemo == ia32_arch.x86_mn:
         for b in all_bloc:
             for l in b.lines:
diff --git a/miasm/arch/ia32_arch.py b/miasm/arch/ia32_arch.py
index 8023e274..58187932 100644
--- a/miasm/arch/ia32_arch.py
+++ b/miasm/arch/ia32_arch.py
@@ -46,8 +46,8 @@ tab_size2int = {x86_afs.u08:uint8,
                 x86_afs.s08:int8,
                 x86_afs.s16:int16,
                 x86_afs.s32:int32}
-                
-                
+
+tab_max_uint = {x86_afs.u08:0xFF, x86_afs.u16:0xFFFF, x86_afs.u32:0xFFFFFFFF, x86_afs.u64:0xFFFFFFFFFFFFFFFFL}
 
 
 
@@ -135,13 +135,13 @@ w8 = "w8"
 se = "se"
 sw = "sw"
 ww = "ww"
-sg = "sg"
-dr = "dr"
-cr = "cr"
-ft = "ft"
+sg = "sg" # segment reg
+dr = "dr" # debug reg
+cr = "cr" # control reg
+ft = "ft" # float
 w64= "w64"
-sd = "sd" #single/double
-wd = "wd" #word/dword
+sd = "sd" # single/double
+wd = "wd" # word/dword
 
 
 bkf = "breakflow"
@@ -1354,7 +1354,12 @@ class x86_mn:
             return []
         a = self.arg[0]
         if is_imm(a) and not x86_afs.symb in a:
-            dst = (self.offset+self.l+a[x86_afs.imm])&0xFFFFFFFF
+            print hex(self.offset), hex(self.l+a[x86_afs.imm])
+            print hex(self.offset+self.l+a[x86_afs.imm])
+            print self.size_ad
+            print tab_max_uint[self.size_ad]
+            print hex((self.offset+self.l+a[x86_afs.imm])&tab_max_uint[self.size_ad])
+            dst = (self.offset+self.l+a[x86_afs.imm])&tab_max_uint[self.size_ad]
             out = [dst]
         else:
             out = [a]
diff --git a/miasm/arch/ia32_reg.py b/miasm/arch/ia32_reg.py
index 9c49691e..2910c328 100644
--- a/miasm/arch/ia32_reg.py
+++ b/miasm/arch/ia32_reg.py
@@ -38,6 +38,8 @@ class afs_desc:
         self.u32 = "u32"
         self.s32 = "s32"
         self.s32 = "s32"
+        self.s64 = "s64"
+        self.u64 = "u64"
 
         self.f32 = "f32"
         self.f64 = "f64"