about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2012-05-10 13:53:07 +0200
committerserpilliere <devnull@localhost>2012-05-10 13:53:07 +0200
commit72818eae793542894435b23d2766e52476da58fe (patch)
tree31bb2fb6419ec8f9623f54db7164a51387a229db
parent1380aa2b0b8d5376e5825302a851ee40edc8ffed (diff)
downloadmiasm-72818eae793542894435b23d2766e52476da58fe.tar.gz
miasm-72818eae793542894435b23d2766e52476da58fe.zip
whitespace cleanup
Diffstat (limited to '')
-rwxr-xr-xmiasm/tools/emul_helper.py116
-rw-r--r--miasm/tools/to_c_helper.py122
2 files changed, 119 insertions, 119 deletions
diff --git a/miasm/tools/emul_helper.py b/miasm/tools/emul_helper.py
index ba16eabf..72a88e98 100755
--- a/miasm/tools/emul_helper.py
+++ b/miasm/tools/emul_helper.py
@@ -33,17 +33,17 @@ log_emu_helper.addHandler(console_handler)
 log_emu_helper.setLevel(logging.WARN)
 
 def hexdump(a, offset = 0):
-    out ="" 
+    out =""
     for i,c in enumerate(a):
         if i%0x10==0:
             out+="\n%.8X "%(offset+i)
-            
+
         out+="%.2X "%ord(c)
     return out
-      
+
 
 def tohex(a):
-        
+
     try:
         a = int(a)
     except:
@@ -54,7 +54,7 @@ def tohex(a):
         a = struct.pack('L', a)
     a = struct.unpack('L', a)[0]
     return hex(a)
-    
+
 
 jcc = ['jz', 'je', 'jnz', 'jp', 'jnp', 'jg', 'jge', 'ja', 'jae', 'jb', 'jbe', 'jl', 'jle', 'js', 'jns', 'jo', 'jno', 'loop', 'loopne', 'jecxz']
 
@@ -71,7 +71,7 @@ def dump_reg(p):
             out+=str(x)+' %.8X  '%int(p[x].arg)
         else:
             out+=str(x)+' %s  '%p[x]
-                      
+
     return out
 
 
@@ -86,7 +86,7 @@ def dump_mem(p):
     todo.sort()
     for x in todo:
         out.append('%s    %s'%(str(x), str(p[x])))
-                      
+
     return "\n".join(out)
 
 def mem_read(evaluator, env, src_address, mem_size):
@@ -95,7 +95,7 @@ def mem_read(evaluator, env, src_address, mem_size):
         raise "cannot read", str(src_address)
     src_address_l = int(src_address.arg)
     try:
-        
+
         if mem_size == 32:
             ret = uint32(env.get_d(src_address_l))
         elif mem_size == 16:
@@ -236,13 +236,13 @@ def emul_imp_init(machine, libbase = 0xCCC00000, malloc_next_ad = 0xEEE00000):
     #for loadlibrary & getprocaddress emul
     machine.lib_bases = {}
     machine.lib_bases_func_index = {}
-    machine.lib_base = libbase    
+    machine.lib_base = libbase
     machine.func_loaded = {}
 
     #for malloc & free emul
     machine.malloc_next_ad = malloc_next_ad;
-    
-    
+
+
 def emul_loadlibrary(machine, env):
     my_esp = machine.eval_expr(machine.pool[esp], {})
     libname_ad = env.get_d(my_esp+4)
@@ -285,7 +285,7 @@ def emul_getprocaddress(machine, env):
         log.debug(machine.lib_bases)
         raise 'unknown base lib! %s'%str(libbase_ad)
     func_ad = machine.lib_bases_func_index[libbase_ad]
-    
+
     machine.lib_bases_func_index[libbase_ad]+=1
     machine.eval_instr(mov(eax, ExprInt(uint32(func_ad))))
 
@@ -302,7 +302,7 @@ def hook_import_func(env, imported_func, start_address_hook = 0xAABB0000):
         env.set_d(f, start_address_hook)
         func_hook_ptr[start_address_hook] = imported_func[f]
         start_address_hook+=0x10000
-        
+
     return func_hook_ptr
 
 def dump_imp(machine):
@@ -321,18 +321,18 @@ def emul_malloc(machine, env):
     pool_type =env.get_d(my_esp+0x4)
     alloc_size =env.get_d(my_esp+0x8)
     tag =env.get_d(my_esp+0xc)
-    
+
     machine.eval_instr(ret(ExprInt(uint32(0xc))))
     my_eip = machine.eval_expr(machine.pool[eip], {})
     del machine.pool[eip]
-    
+
     ret_alloc_ad = machine.malloc_next_ad
     m_data = mempool(machine.malloc_next_ad, machine.malloc_next_ad+alloc_size, 'RW', name = "malloc %.8X"%alloc_size)
     machine.malloc_next_ad += ((alloc_size+0xFFF)&(~0xFFF))
-    
+
     log.warn('alloc(%X) tag %X poolt %X from %X esp %X ret %X:'%(int(alloc_size), int(tag), int(pool_type), int(my_eip), int(my_esp), int(machine.malloc_next_ad)))
     machine.eval_instr(mov(eax, ExprInt(uint32(ret_alloc_ad))))
-    
+
     env.mems.append(m_data)
     log.warn(str(env))
     return my_eip
@@ -365,34 +365,34 @@ def emul_heapcreate(machine, env):
     floptions =env.get_d(my_esp+4)
     dwinitialsize =env.get_d(my_esp+8)
     dwmaximumsize =env.get_d(my_esp+12)
-    
+
     machine.eval_instr(ret(ExprInt(uint32(12))))
     my_eip = machine.eval_expr(machine.pool[eip], {})
     del machine.pool[eip]
-    
-    
+
+
     log.warn('heapcreate(%X %X %X) from %X esp %X ret %X:'%(floptions, dwinitialsize, dwmaximumsize, int(my_eip), my_esp, 0xdeadcafe))
     machine.eval_instr(mov(eax, ExprInt(uint32(0xdeadcafe))))
-    
+
     return my_eip
-    
+
 def emul_heapalloc(machine, env):
     my_esp = machine.get_reg(esp)
     hheap =env.get_d(my_esp+4)
     dwflags =env.get_d(my_esp+8)
-    alloc_size =env.get_d(my_esp+12) 
-   
+    alloc_size =env.get_d(my_esp+12)
+
     machine.eval_instr(ret(ExprInt(uint32(12))))
     my_eip = machine.eval_expr(machine.pool[eip], {})
     del machine.pool[eip]
-    
+
     ret_alloc_ad = machine.malloc_next_ad
     m_data = mempool(machine.malloc_next_ad, machine.malloc_next_ad+alloc_size, 'RW', name = "heapalloc %.8X"%alloc_size)
     machine.malloc_next_ad += ((alloc_size+0xFFF)&(~0xFFF))
-    
+
     log.warn('heapalloc(%X %X %X) from %X esp %X ret %X:'%(hheap, dwflags, alloc_size, int(my_eip), my_esp, machine.malloc_next_ad))
     machine.eval_instr(mov(eax, ExprInt(uint32(ret_alloc_ad))))
-    
+
     env.mems.append(m_data)
     log.warn(str(env))
     return my_eip
@@ -419,20 +419,20 @@ def emul_virtualalloc(machine, env):
     my_esp = machine.get_reg(esp)
     lpaddress =env.get_d(my_esp+4)
     alloc_size =env.get_d(my_esp+8)
-    flallocationtype =env.get_d(my_esp+12) 
-    flprotect =env.get_d(my_esp+16) 
-   
+    flallocationtype =env.get_d(my_esp+12)
+    flprotect =env.get_d(my_esp+16)
+
     machine.eval_instr(ret(ExprInt(uint32(16))))
     my_eip = machine.eval_expr(machine.pool[eip], {})
     del machine.pool[eip]
-    
+
     ret_alloc_ad = machine.malloc_next_ad
     m_data = mempool(machine.malloc_next_ad, machine.malloc_next_ad+alloc_size, 'RW', name = "virtualalloc %.8X"%alloc_size)
     machine.malloc_next_ad += ((alloc_size+0xFFF)&(~0xFFF))
-    
+
     log.warn('virtualalloc(%X %X %X %X) from %X esp %X ret %X:'%(lpaddress, alloc_size, flallocationtype, flprotect, int(my_eip), my_esp, machine.malloc_next_ad))
     machine.eval_instr(mov(eax, ExprInt(uint32(ret_alloc_ad))))
-    
+
     env.mems.append(m_data)
     log.warn(str(env))
     return my_eip
@@ -443,8 +443,8 @@ def emul_virtualfree(machine, env):
     address_free =env.get_d(my_esp+4)
     dwsize =env.get_d(my_esp+8)
     dwfreetype =env.get_d(my_esp+12)
-    
-    
+
+
 
     machine.eval_instr(ret(ExprInt(uint32(12))))
     my_eip = machine.eval_expr(machine.pool[eip], {})
@@ -486,27 +486,27 @@ def emul_getmodulehandlea(machine, env):
     else:
         machine.eval_instr(mov(eax, ExprInt(uint32(0x0))))
         log.warn("unknown lib: %s"%str(libname))
-        
+
     log.warn(str(env))
 
     return my_eip
 
 def emul_kddisabledebugger(machine, env):
     my_esp = machine.get_reg(esp)
-    
+
     machine.eval_instr(ret())
     my_eip = machine.eval_expr(machine.pool[eip], {})
     del machine.pool[eip]
-    
-    
+
+
     log.warn('emul_kddisabledebugger from %X esp %X '%(int(my_eip), int(my_esp)))
     machine.eval_instr(mov(eax, ExprInt(uint32(0))))
-    
+
     log.warn(str(env))
     return my_eip
-    
-    
-    
+
+
+
 def sav_machine(machine, env, my_eip, snap_fmt_name):
 
     print 'SAVE**************tsc: %.10d***************'%machine.pool[tsc1].arg
@@ -514,7 +514,7 @@ def sav_machine(machine, env, my_eip, snap_fmt_name):
     env_s = StringIO.StringIO()
     env.to_file(env_s)
     env_s.flush()
-    fname = snap_fmt_name+".env" 
+    fname = snap_fmt_name+".env"
     open(fname%(machine.pool[tsc1].arg), 'wb').write(zlib.compress(env_s.getvalue(), 9))
     machine_s = StringIO.StringIO()
     machine.to_file(machine_s)
@@ -522,23 +522,23 @@ def sav_machine(machine, env, my_eip, snap_fmt_name):
     fname = snap_fmt_name+".machine"
     open(fname%(machine.pool[tsc1].arg), 'wb').write(zlib.compress(machine_s.getvalue(), 9))
     del machine.pool[eip]
-    
-    
+
+
 def load_machine(snap_fmt_name, step):
 
-    fname = snap_fmt_name+".env" 
+    fname = snap_fmt_name+".env"
     env_s = StringIO.StringIO(zlib.decompress(open(fname%step, 'rb').read()))
     env = mempool_manager.from_file(env_s)
-    fname = snap_fmt_name+".machine"        
+    fname = snap_fmt_name+".machine"
     machine_s = StringIO.StringIO(zlib.decompress(open(fname%step, 'rb').read()))
     machine = eval_int.from_file(machine_s, globals())
     my_eip = machine.pool[eip]
     del machine.pool[eip]
     print 'LOAD**************tsc: %.10X***************'%machine.pool[tsc1].arg
     print "machine eip: %.8X"%int(my_eip.arg)
-    
+
     return machine, env, my_eip
-     
+
 def emul_full_expr(e, l, my_eip, env, machine):
     if ((not 0xF2 in l.prefix) and (not 0xF3 in l.prefix)) or \
            not l.m.name[:-1] in ["ins", "outs", "movs", "lods", "stos", "cmps", "scas"]:
@@ -549,7 +549,7 @@ def emul_full_expr(e, l, my_eip, env, machine):
         if 0x66 in l.prefix and l.m.name[-1]== "d":
             raise "not impl 16 bit string"
         zf_w = zf in reduce(lambda x,y:x+y, [list(x.get_w()) for x in e], [])
-        
+
         while True:
 
             my_ecx = machine.eval_expr(machine.pool[ecx], {})
@@ -563,7 +563,7 @@ def emul_full_expr(e, l, my_eip, env, machine):
             my_esi = machine.eval_expr(machine.pool[esi], {})
             my_edi = machine.eval_expr(machine.pool[edi], {})
             tmp,mem_dst =  emul_expr(machine, e, my_eip)
-            
+
             info = l.opmode, l.admode
             machine.eval_instr(mov(info, ecx, ExprOp('-', my_ecx, ExprInt(uint32(1)))))
             machine.eval_expr(machine.pool[ecx], {})
@@ -578,7 +578,7 @@ def emul_full_expr(e, l, my_eip, env, machine):
             machine.pool[tsc1].arg+=uint32(1)
 
     return my_eip, mem_dst
-    
+
 
 def guess_func_destack(all_bloc):
     ret_destack = None
@@ -587,7 +587,7 @@ def guess_func_destack(all_bloc):
         if not l.m.name.startswith('ret'):
             continue
         if len(l.arg) == 0:
-            a = 0  
+            a = 0
         elif len(l.arg) ==1:
             a = l.arg[0][x86_afs.imm]
         else:
@@ -644,7 +644,7 @@ def digest_allbloc_instr(all_bloc, segm_to_do = {}):
                 print b
                 raise ValueError('diff bloc in same label')
             all_bloc.remove(b)
-        
+
     for b in all_bloc:
         for l in b.lines:
             if l.offset in instrs:
@@ -654,7 +654,7 @@ def digest_allbloc_instr(all_bloc, segm_to_do = {}):
             args = []
             ex = get_instr_expr(l, ExprInt(uint32(l.offset+l.l)), args, segm_to_do = segm_to_do)
 
-                
+
             instrs[l.offset] = (l, ex)
     return instrs
 
@@ -672,10 +672,10 @@ def x86_machine(mem_read_wrap = None, mem_write_wrap = None):
                         dr7:ExprInt(uint32(0)),
                         cr0:init_cr0,
                         #my_ret_addr:my_ret_addri
-                        
+
                         },
                        mem_read_wrap,
                        mem_write_wrap,
-                       
+
                        )
     return machine
diff --git a/miasm/tools/to_c_helper.py b/miasm/tools/to_c_helper.py
index 3fa44b99..5ae2e2a9 100644
--- a/miasm/tools/to_c_helper.py
+++ b/miasm/tools/to_c_helper.py
@@ -392,7 +392,7 @@ def Exp2C(exprs, l = None, addr2label = None, gen_exception_code = False):
             post_instr.append("if (vmcpu.vm_exception_flags) { /*eip = 0x%X; */return vmcpu.eip; }"%(l.offset))
         else:
             post_instr.append(code_deal_exception_post_instr % (patch_c_id(eip), (l.offset&mask_int), (l.offset + l.l)&mask_int))
-    
+
     """
     print "1"
     print out
@@ -401,8 +401,8 @@ def Exp2C(exprs, l = None, addr2label = None, gen_exception_code = False):
     print "3"
     print post_instr
     """
-    
-        
+
+
 
     #eip manip after all modifications
     return out+out_eip, post_instr
@@ -424,8 +424,8 @@ def bloc2C(all_bloc, addr2label = None, gen_exception_code = False, dbg_instr =
                 if tick_dbg!=None:
                     out.append('if (my_tick > %d)'%tick_dbg)
                 out.append(r'fprintf(stdout, "%s\n");'%str(b.label.name))
-        
-        
+
+
         for l in b.lines:
             if l.offset in label_done:
                 continue
@@ -435,17 +435,17 @@ def bloc2C(all_bloc, addr2label = None, gen_exception_code = False, dbg_instr =
                 out.append("%s:"%addr2label(l.offset))
             else:
                 out.append("loc_%.16X:"%(l.offset&mask_int))
-                
+
             o, post_instr = Exp2C(ex, l, addr2label, gen_exception_code)
-            
 
-            
+
+
 
             #if add_return:
             #    o.append('return;');
             #if add_call:
             #    o.append('%s();'%add_call);
-    
+
             if (0xF2 in l.prefix or 0xF3 in l.prefix) and l.m.name in ["ins", "outs", "movsb", "movsw", "movsd", "lodsb", "lodsw", "lodsd", "stosb", "stosw", "stosd" ]+ [ "cmpsb", "cmpsw", "cmpsd", "scasb", "scasw", "scasd" ]:
                 zf_w = zf in reduce(lambda x,y:x+y, [list(x.get_w()) for x in ex], [])
                 my_o = ["while (1){"]
@@ -454,7 +454,7 @@ def bloc2C(all_bloc, addr2label = None, gen_exception_code = False, dbg_instr =
                 my_o.append(code_deal_exception_post_instr % (patch_c_id(eip), (l.offset&mask_int), (l.offset&mask_int)))
 
 
-                #my_o.append(r'fprintf(stderr, "ecx %.8X\n", ecx );')            
+                #my_o.append(r'fprintf(stderr, "ecx %.8X\n", ecx );')
                 my_o+= ['if (%s==0) break;'%patch_c_id(ecx)]
                 my_o+=o
                 my_o+= ['%s--;'%patch_c_id(ecx)]
@@ -466,7 +466,7 @@ def bloc2C(all_bloc, addr2label = None, gen_exception_code = False, dbg_instr =
 
 
                 my_o += ["}"]
-    
+
                 o = my_o
 
             o+= post_instr
@@ -486,15 +486,15 @@ def bloc2C(all_bloc, addr2label = None, gen_exception_code = False, dbg_instr =
 
             out+=o
 
-        
+
         for c in b.bto:
             if c.c_t == asmbloc.asm_constraint.c_next:
                 out.append("GOTO_STATIC(0x%.16X);"%(c.label.offset&mask_int))
-        
+
         """
         #in case of bad disasm, no next, so default next instr
         #XXX BUG if  no line!!!
-        
+
         if b.lines:
             l = b.lines[-1]
             out.append("GOTO_STATIC(%s);"%(addr2label(l.offset + l.l)))
@@ -531,7 +531,7 @@ def gen_x86_core():
     txt += '#include "%s/libcodenat.h"\n'%lib_dir
 
     txt += r'''
-    
+
 //#define RAISE(errtype,msg) { PyErr_SetString(errtype,msg); RE_RAISE; }
 //#define RE_RAISE           { return NULL; }
 
@@ -541,12 +541,12 @@ def gen_x86_core():
 
 '''
     return txt
-        
+
 
 def gen_C_source(funcs_code, known_mems, dyn_dispatcher):
     c_source = dyn_dispatcher
     c_source+= "\n".join(funcs_code)
-    
+
     kmems = gen_known_mems_code(known_mems)
     c_source = gen_x86_core()+"\n".join(kmems)+c_source
     return c_source
@@ -567,14 +567,14 @@ def del_bloc_in_range(all_blocs, ad1, ad2):
         # XXX no lines in bloc?
         if not b.lines:
             continue
-        
+
         if b.lines[0].offset>=ad2 or b.lines[-1].offset + b.lines[-1].l <= ad1:
             bloc_out.append(b)
         else:
             #print 'inv bloc', b.label
             pass
     return bloc_out
-    
+
 def merge_memory_ranges(t):
     i = 0
     while i < len(t)-1:
@@ -609,7 +609,7 @@ def merge_memory_ranges(t):
             t[i] = rA1, rA2
         else:
             i+=1
-            
+
 
 def gen_code_addr_tab(t):
     out = []
@@ -618,10 +618,10 @@ def gen_code_addr_tab(t):
     out += ["unsigned int code_addr_tab[2*%d] = {"%len(t)]
     for r in t:
         out += ["\t0x%.8X, 0x%.8X,"%(r)]
-        
+
     out += ['};']
     return '\n'.join(out)+'\n'
-    
+
 def asm2C(f_name, known_mems, dyn_func, in_str, x86_mn, symbol_pool, func_to_dis, dont_dis = [], follow_call = False, dontdis_retcall = False, log_mn = False, log_reg = False, log_lbl = False, filtered_ad = [], tick_dbg = None, code_addr = [], all_bloc_funcs = []):
 
     funcs_code = []
@@ -629,8 +629,8 @@ def asm2C(f_name, known_mems, dyn_func, in_str, x86_mn, symbol_pool, func_to_dis
 
     all_bloc_funcs+=asmbloc.dis_multi_func(in_str, x86_mn, symbol_pool, func_to_dis, dont_dis, follow_call, dontdis_retcall)
 
-    
-        
+
+
     for b in all_bloc_funcs:
         if b.label.offset in dont_dis:
             continue
@@ -645,7 +645,7 @@ def asm2C(f_name, known_mems, dyn_func, in_str, x86_mn, symbol_pool, func_to_dis
         if (l.m.name.startswith('call') or l.m.name.startswith('jmp')) and not x86_afs.symb in l.arg[0]:
 
             #print "TOTO", hex(l.offset), l, l.arg[0]
-            
+
             #deal dyn call
             instr = x86_mn.dis(x86_mn.asm('mov eax, eax')[0])
             #XXX HACK to be unik address
@@ -655,16 +655,16 @@ def asm2C(f_name, known_mems, dyn_func, in_str, x86_mn, symbol_pool, func_to_dis
 
             #print instr, str(instr)
             #instr.offset = 0x1337beef
-            
+
             #b.lines[-1:-1] = [instr]
             #l.arg[0] = {x86_afs.symb:func_deal_dyn}
 
 
             #if dyn func is not in ref, add it (todo in gen C)
         '''
-    
+
         for l in b.lines:
-    
+
             #test imm redirect mem ad
             for a in l.arg:
                 if not x86_afs.imm in a: continue
@@ -687,16 +687,16 @@ def asm2C(f_name, known_mems, dyn_func, in_str, x86_mn, symbol_pool, func_to_dis
 
                 if not l_name:
                     continue
-                
+
                 label = asmbloc.asm_label(l_name, i)
                 a[x86_afs.symb] = {label:1}
                 del a[x86_afs.imm]
-                
+
 
     code_addr += blocs_to_memory_ranges(all_bloc_funcs)
     merge_memory_ranges(code_addr)
-    
-    
+
+
     allb = all_bloc_funcs#reduce(lambda x,y:x+y, all_bloc_funcs.values(), [])
     f_dec, out = bloc_gen_C_func(allb, f_name, None, True, log_mn, log_reg, log_lbl, filtered_ad, tick_dbg)
     funcs_dec.append(f_dec)
@@ -759,7 +759,7 @@ def dispatch_table_from_f_blocs(all_f_b):
 def gen_dynamic_dispatcher(dispatch_table):
     offsets = dispatch_table.keys()
     offsets.sort()
-    
+
     out1 = []
     out1 += ["#define FUNC_DYNAMIC"]
     out1 += ['void* tab_eip_label[(%d+1)*2] = '%len(dispatch_table)]
@@ -773,9 +773,9 @@ def gen_dynamic_dispatcher(dispatch_table):
     out2 = []
     out2 += ["void * get_label_from_eip(void** tab_eip_label)"]
     out2 += ['{']
-    
+
     out2 += ['\tvoid *labelref = NULL;']
-    
+
     out2 += ['\tunsigned int i = 0;']
     out2 += ['\twhile (tab_eip_label[2*i]!= NULL && tab_eip_label[2*i+1]!=NULL){']
     out2 += ['\t\tif (tab_eip_label[i*2] == (void*)vmcpu.eip){']
@@ -789,7 +789,7 @@ def gen_dynamic_dispatcher(dispatch_table):
     #out2 += [r'exit(0);']
     out2 += ['return labelref;']
     out2 += ['}']
-    
+
 
     out = []
 
@@ -801,17 +801,17 @@ def gen_dynamic_dispatcher(dispatch_table):
     out += ["return (PyObject*)vm_get_exception(vm_exception_flags);"]
     out += ['}']
     out += ['goto *labelref;']
-    
+
     """
     out += ['{']
     #out += [r'fprintf(stderr, "search dst: %X\n", eip);']
-    
+
     out += ['switch(eip){']
     for o in offsets:
         out+=['case 0x%.8X:'%o]
         out+=['goto %s;'%dispatch_table[o]]
         out+=['break;']
-    
+
     out += ['case 0x1337beef:']
     out += [r'fprintf(stderr, "return reached %X\n", eip);']
     out += ['return NULL;']
@@ -822,9 +822,9 @@ def gen_dynamic_dispatcher(dispatch_table):
     out += ['break;']
     out += ['}']
     out += ['}']
-    """    
+    """
     return out1, out2
-        
+
 def gen_dyn_func_manager(dyn_func, dis_func):
     total_func_num = len(dyn_func)+len(dis_func)
     out = "int (*tab_func[%d][2])(void) = {"%(total_func_num)
@@ -835,12 +835,12 @@ def gen_dyn_func_manager(dyn_func, dis_func):
 
         dec_f_ptr += "unsigned int dyn_func_%.8X;\n"%(f_ad)
         init_f_ptr+= "dyn_func_%.8X = (unsigned int)&%s;\n"%(f_ad, f_name)
-           
+
     for f_ad in dis_func:
         out+="{0x%.8X, func_%.8X},"%(f_ad, f_ad)
     out+="};"
-        
-        
+
+
     code = "\n"
     code += "#define DYN_FUNC_NUM %d"%total_func_num
     code += r"""
@@ -849,7 +849,7 @@ void func_dyn_manager(void)
 {
     unsigned int i;
 """ + out + r"""
-    
+
     for (i=0;i<DYN_FUNC_NUM;i++){
         if (dyn_dst == tab_func[i][0]){
             fprintf(stderr, "i %d v@%X r@%X\n", i, tab_func[i][0], tab_func[i][1]);
@@ -857,7 +857,7 @@ void func_dyn_manager(void)
             return;
         }
     }
-    
+
     fprintf(stderr, "unknown dyn dst!\n");
     exit(0);
 }
@@ -872,26 +872,26 @@ def insert_printf(c_source, label):
         print l
         if l.startswith(label):
             c_source[i+1:i+1] = ['printf("reached %s\\n");'%label]
-        
+
 
 
 
 def gen_label_declaration(known_mems):
     lab_dec = []
-    
+
     for m_ad, m_val in known_mems.items():
         dec_name = "char tab_%.8X[0x%X]"%(m_ad, len(m_val))
         data = m_val
         dec_name+=' = {'+', '.join(["0x%.2X"%ord(x) for x in data])+'};'
         lab_dec.append(dec_name)
 
-    
+
     return lab_dec
 
 
 def gen_call_func(funcname, args, precode = "", postcode = ""):
     out = ""
-    
+
 def gen_known_mems_code(known_mems):
     code = []
     for m_ad, m_val in known_mems.items():
@@ -907,7 +907,7 @@ def gen_known_mems_code(known_mems):
     code.append("void init_tab_mem(void)")
     code.append("{")
     code.append("unsigned int ret;")
-    
+
     for m_ad, m_val in known_mems.items():
         #code.append("tab_%.8X = malloc(0x%.8X);\n"%(m_ad, len(m_val)))
         code.append("ret = posix_memalign(&tab_%.8X, 0x10000, 0x%.8X);"%(m_ad, len(m_val)))
@@ -915,13 +915,13 @@ def gen_known_mems_code(known_mems):
         code.append(r'    fprintf(stderr, "cannot alloc");')
         code.append(r'    exit(-1);')
         code.append(r'}')
-        
+
 
         code.append("memcpy(tab_%.8X, tab_data_%.8X, 0x%.8X);"%(m_ad, m_ad, len(m_val)))
     code.append("}\n")
     """
-    
-    
+
+
 
     return code
 
@@ -944,7 +944,7 @@ if __name__ == '__main__':
         print x
     print '#'*80
 
-    
+
 
 
 def _compile(self):
@@ -974,11 +974,11 @@ def _compile(self):
               )
     except SystemExit, e:
         raise BuildError(e)
-        
+
     os.chdir(self._homeDir)
-    
 
-    
+
+
 
 
 from miasm.tools.codenat import *
@@ -1006,14 +1006,14 @@ def updt_bloc_emul(known_blocs, in_str, my_eip, symbol_pool, code_blocs_mem_rang
     known_blocs[my_eip] = bn
 
     ###### update code ranges ###
-    
+
     code_addr = blocs_to_memory_ranges([bn.b])
     code_blocs_mem_range += code_addr
     merge_memory_ranges(code_blocs_mem_range)
     reset_code_bloc_pool_py()
     for a, b in  code_blocs_mem_range:
             vm_add_code_bloc(a, b)
-'''    
+'''
 
 ttt = 0
 def updt_bloc_emul(known_blocs, in_str, my_eip, symbol_pool, code_blocs_mem_range, dont_dis = [], job_done = None, log_mn = False, log_regs = False, segm_to_do = {}, **kargs):
@@ -1134,7 +1134,7 @@ upw = lambda x: struct.unpack('H', x)[0]
 #try:
 if True:
     from emul_lib.libcodenat_interface import *
-    
+
     #vm_init_regs = libcodenat.vm_init_regs
 #except:
 #    print "WARNING! unable to build libcodenat C interface!!"