diff options
Diffstat (limited to 'miasm/tools')
| -rwxr-xr-x | miasm/tools/emul_helper.py | 2 | ||||
| -rw-r--r-- | miasm/tools/emul_lib/libcodenat.c | 37 | ||||
| -rw-r--r-- | miasm/tools/emul_lib/libcodenat.h | 1 | ||||
| -rw-r--r-- | miasm/tools/to_c_helper.py | 30 |
4 files changed, 67 insertions, 3 deletions
diff --git a/miasm/tools/emul_helper.py b/miasm/tools/emul_helper.py index e91e8c1e..f452cc79 100755 --- a/miasm/tools/emul_helper.py +++ b/miasm/tools/emul_helper.py @@ -56,7 +56,7 @@ def tohex(a): return hex(a) -jcc = ['jz', 'je', 'jnz', 'jp', 'jnp', 'jg', 'jge', 'ja', 'jae', 'jb', 'jbe', 'jl', 'jle', 'js', 'jns', 'jo', 'jno', 'loop', 'loopne'] +jcc = ['jz', 'je', 'jnz', 'jp', 'jnp', 'jg', 'jge', 'ja', 'jae', 'jb', 'jbe', 'jl', 'jle', 'js', 'jns', 'jo', 'jno', 'loop', 'loopne', 'jecxz'] def dump_pool(p): log_emu_helper.error('/-------------\\') diff --git a/miasm/tools/emul_lib/libcodenat.c b/miasm/tools/emul_lib/libcodenat.c index b241debb..170726e8 100644 --- a/miasm/tools/emul_lib/libcodenat.c +++ b/miasm/tools/emul_lib/libcodenat.c @@ -794,6 +794,7 @@ unsigned int cpuid(unsigned int a, unsigned int reg_num) return 0; } +#define DEBUG_MIASM_DOUBLE double mem_32_to_double(unsigned int m) { @@ -802,6 +803,9 @@ double mem_32_to_double(unsigned int m) f = *((float*)&m); d = f; +#ifdef DEBUG_MIASM_DOUBLE + printf("%d %e\n", m, d); +#endif return d; } @@ -810,6 +814,9 @@ double mem_64_to_double(uint64_t m) { double d; d = *((double*)&m); +#ifdef DEBUG_MIASM_DOUBLE + printf("%"PRId64" %e\n", m, d); +#endif return d; } @@ -818,6 +825,9 @@ double int_32_to_double(unsigned int m) double d; d = (double)m; +#ifdef DEBUG_MIASM_DOUBLE + printf("%d %e\n", m, d); +#endif return d; } @@ -826,6 +836,9 @@ double int_64_to_double(uint64_t m) double d; d = (double)m; +#ifdef DEBUG_MIASM_DOUBLE + printf("%"PRId64" %e\n", m, d); +#endif return d; } @@ -834,6 +847,9 @@ int double_to_int_32(double d) int i; i = (int)d; +#ifdef DEBUG_MIASM_DOUBLE + printf("%e %d\n", d, i); +#endif return i; } @@ -841,6 +857,19 @@ double fadd(double a, double b) { double c; c = a + b; +#ifdef DEBUG_MIASM_DOUBLE + printf("%e %e %e\n", a, b, c); +#endif + return c; +} + +double fdiv(double a, double b) +{ + double c; + c = a / b; +#ifdef DEBUG_MIASM_DOUBLE + printf("%e %e %e\n", a, b, c); +#endif return c; } @@ -875,6 +904,9 @@ unsigned int double_to_mem_32(double d) float f; f = d; m = *((unsigned int*)&f); +#ifdef DEBUG_MIASM_DOUBLE + printf("%d %e\n", m, d); +#endif return m; } @@ -882,6 +914,9 @@ uint64_t double_to_mem_64(double d) { uint64_t m; m = *((uint64_t*)&d); +#ifdef DEBUG_MIASM_DOUBLE + printf("%"PRId64" %e\n", m, d); +#endif return m; } @@ -1095,6 +1130,8 @@ unsigned int get_memory_page_next(unsigned int n_ad) return ad; } + + unsigned int get_memory_page_from_min_ad(unsigned int size) { struct memory_page_node * mpn; diff --git a/miasm/tools/emul_lib/libcodenat.h b/miasm/tools/emul_lib/libcodenat.h index bb014d90..c1ae4e7a 100644 --- a/miasm/tools/emul_lib/libcodenat.h +++ b/miasm/tools/emul_lib/libcodenat.h @@ -376,6 +376,7 @@ double int2double(unsigned int m); //PyObject* _vm_exec_blocs(PyObject* my_eip); double fadd(double a, double b); +double fdiv(double a, double b); unsigned int fcom_c0(double a, double b); unsigned int fcom_c1(double a, double b); unsigned int fcom_c2(double a, double b); diff --git a/miasm/tools/to_c_helper.py b/miasm/tools/to_c_helper.py index ed41f6c8..7c45f50d 100644 --- a/miasm/tools/to_c_helper.py +++ b/miasm/tools/to_c_helper.py @@ -120,6 +120,18 @@ my_C_id = [ float_stack_ptr, ] + +float_id_e = [ + float_st0, + float_st1, + float_st2, + float_st3, + float_st4, + float_st5, + float_st6, + float_st7, + ] + id2Cid = {} for x in my_C_id: id2Cid[x] = ExprId('vmcpu.'+str(x)) @@ -203,8 +215,12 @@ def Exp2C(exprs, l = None, addr2label = None, gen_exception_code = False): if isinstance(dst, ExprId): id_to_update.append(dst) str_dst = id2new(patch_c_id(dst)) - out.append('%s = (%s)&0x%X;'%(str_dst, str_src, - my_size_mask[src.get_size()])) + if dst in float_id_e: + # dont mask float affectation + out.append('%s = (%s);'%(str_dst, str_src)) + else: + out.append('%s = (%s)&0x%X;'%(str_dst, str_src, + my_size_mask[src.get_size()])) elif isinstance(dst, ExprMem): str_dst = str_dst.replace('MEM_LOOKUP', 'MEM_WRITE') out_mem.append('%s, %s);'%(str_dst[:-1], str_src)) @@ -951,6 +967,16 @@ def flush_all_blocs(known_blocs): vm_reset_exception() return known_blocs, code_addr + +def dump_stack(): + esp = vm_get_gpreg()['esp'] + print 'esp', hex(esp) + a = vm_get_str(esp, 0x20) + while a: + x = struct.unpack('I', a[:4])[0] + a = a[4:] + print hex(x) + import random def c_emul_bloc(known_blocs, my_eip): |