diff options
| author | Camille Mougey <commial@gmail.com> | 2018-02-14 12:13:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-14 12:13:24 +0100 |
| commit | dcfadb31685d428618b88f19fcc96dd70cecfc8f (patch) | |
| tree | 038c6c2f545d5a77ecb6c68f030107f09d32450f | |
| parent | b0e9f5da9b4546a22169882e656bf2776eab9754 (diff) | |
| parent | 6702a6149c57c54bcece3fb1cd00b8c09af6e74a (diff) | |
| download | miasm-dcfadb31685d428618b88f19fcc96dd70cecfc8f.tar.gz miasm-dcfadb31685d428618b88f19fcc96dd70cecfc8f.zip | |
Merge pull request #678 from serpilliere/x86_fix_rcl
X86 fix rcl
| -rw-r--r-- | miasm2/arch/x86/sem.py | 51 | ||||
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 40 | ||||
| -rw-r--r-- | miasm2/ir/translators/C.py | 23 | ||||
| -rw-r--r-- | miasm2/jitter/Jitgcc.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/Jittcc.c | 14 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_aarch64.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_arm.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_mips32.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_msp430.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_x86.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/llvmconvert.py | 48 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.c | 129 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.h | 10 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 12 |
14 files changed, 159 insertions, 180 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 589c2eb9..93c4910a 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -473,21 +473,19 @@ def get_shift(dst, src): return shift -def _rotate_tpl(ir, instr, dst, src, op, left=False, include_cf=False): +def _rotate_tpl(ir, instr, dst, src, op, left=False): '''Template to generate a rotater with operation @op A temporary basic block is generated to handle 0-rotate @op: operation to execute @left (optional): indicates a left rotate if set, default is False - @include_cf (optional): if set, add cf to @op inputs, default is False ''' # Compute results shifter = get_shift(dst, src) - extended_args = (cf.zeroExtend(dst.size),) if include_cf else () - res = m2_expr.ExprOp(op, dst, shifter, *extended_args) + res = m2_expr.ExprOp(op, dst, shifter) # CF is computed with 1-less round than `res` new_cf = m2_expr.ExprOp( - op, dst, shifter - m2_expr.ExprInt(1, size=shifter.size), *extended_args) + op, dst, shifter - m2_expr.ExprInt(1, size=shifter.size)) new_cf = new_cf.msb() if left else new_cf[:1] # OF is defined only for @b == 1 @@ -523,12 +521,49 @@ def l_ror(ir, instr, dst, src): return _rotate_tpl(ir, instr, dst, src, '>>>') -def rcl(ir, instr, dst, src): - return _rotate_tpl(ir, instr, dst, src, '<<<c_rez', left=True, include_cf=True) +def rotate_with_carry_tpl(ir, instr, op, dst, src): + # Compute results + shifter = get_shift(dst, src).zeroExtend(dst.size + 1) + result = m2_expr.ExprOp(op, m2_expr.ExprCompose(dst, cf), shifter) + + new_cf = result[dst.size:dst.size +1] + new_dst = result[:dst.size] + + result_trunc = result[:dst.size] + if op == '<<<': + of_value = result_trunc.msb() ^ new_cf + else: + of_value = (dst ^ result_trunc).msb() + # OF is defined only for @b == 1 + new_of = m2_expr.ExprCond(src - m2_expr.ExprInt(1, size=src.size), + m2_expr.ExprInt(0, size=of.size), + of_value) + + + # Build basic blocks + e_do = [m2_expr.ExprAff(cf, new_cf), + m2_expr.ExprAff(of, new_of), + m2_expr.ExprAff(dst, new_dst) + ] + # Don't generate conditional shifter on constant + if isinstance(shifter, m2_expr.ExprInt): + if int(shifter) != 0: + return (e_do, []) + else: + return ([], []) + e = [] + lbl_do = m2_expr.ExprId(ir.gen_label(), ir.IRDst.size) + lbl_skip = m2_expr.ExprId(ir.get_next_label(instr), ir.IRDst.size) + e_do.append(m2_expr.ExprAff(ir.IRDst, lbl_skip)) + e.append(m2_expr.ExprAff( + ir.IRDst, m2_expr.ExprCond(shifter, lbl_do, lbl_skip))) + return (e, [IRBlock(lbl_do.name, [AssignBlock(e_do, instr)])]) +def rcl(ir, instr, dst, src): + return rotate_with_carry_tpl(ir, instr, '<<<', dst, src) def rcr(ir, instr, dst, src): - return _rotate_tpl(ir, instr, dst, src, '>>>c_rez', include_cf=True) + return rotate_with_carry_tpl(ir, instr, '>>>', dst, src) def _shift_tpl(op, ir, instr, a, b, c=None, op_inv=None, left=False, diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 9953ea4b..02b43c4b 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -48,11 +48,11 @@ def simp_cst_propagation(e_s, expr): tmp2 = mod_size2uint[int2.arg.size](int2.arg) out = mod_size2uint[int1.arg.size](tmp1 >> tmp2) elif op_name == '>>>': - out = (int1.arg >> (int2.arg % int2.size) | - int1.arg << ((int1.size - int2.arg) % int2.size)) + shifter = int2.arg % int2.size + out = (int1.arg >> shifter) | (int1.arg << (int2.size - shifter)) elif op_name == '<<<': - out = (int1.arg << (int2.arg % int2.size) | - int1.arg >> ((int1.size - int2.arg) % int2.size)) + shifter = int2.arg % int2.size + out = (int1.arg << shifter) | (int1.arg >> (int2.size - shifter)) elif op_name == '/': out = int1.arg / int2.arg elif op_name == '%': @@ -320,38 +320,6 @@ def simp_cst_propagation(e_s, expr): args.append(ExprOp(op_name, *arg)) return ExprCompose(*args) - # <<<c_rez, >>>c_rez - if op_name in [">>>c_rez", "<<<c_rez"]: - assert len(args) == 3 - dest, rounds, carry_flag = args - # Skipped if rounds is 0 - if rounds.is_int(0): - return dest - elif all(arg.is_int() for arg in args): - # The expression can be resolved - tmp = int(dest) - carry_flag = int(carry_flag) - size = dest.size - tmp_count = (int(rounds) & - (0x3f if size == 64 else 0x1f)) % (size + 1) - if op_name == ">>>c_rez": - while tmp_count != 0: - tmp_cf = tmp & 1; - tmp = (tmp >> 1) + (carry_flag << (size - 1)) - carry_flag = tmp_cf - tmp_count -= 1 - tmp &= int(dest.mask) - elif op_name == "<<<c_rez": - while tmp_count != 0: - tmp_cf = (tmp >> (size - 1)) & 1 - tmp = (tmp << 1) + carry_flag - carry_flag = tmp_cf - tmp_count -= 1 - tmp &= int(dest.mask) - else: - raise RuntimeError("Unknown operation: %s" % op_name) - return ExprInt(tmp, size=dest.size) - return ExprOp(op_name, *args) diff --git a/miasm2/ir/translators/C.py b/miasm2/ir/translators/C.py index 7a3080ca..95502a15 100644 --- a/miasm2/ir/translators/C.py +++ b/miasm2/ir/translators/C.py @@ -17,9 +17,6 @@ class TranslatorC(Translator): dct_rot = {'<<<': 'rot_left', '>>>': 'rot_right', } - dct_rotc = {'<<<c_rez': 'rcl_rez_op', - '>>>c_rez': 'rcr_rez_op', - } def from_ExprId(self, expr): @@ -118,14 +115,6 @@ class TranslatorC(Translator): else: raise NotImplementedError('Unknown op: %r' % expr.op) - elif len(expr.args) == 3 and expr.op in self.dct_rotc: - return '(%s(%s, %s, %s, %s) &0x%x)' % (self.dct_rotc[expr.op], - expr.args[0].size, - self.from_expr(expr.args[0]), - self.from_expr(expr.args[1]), - self.from_expr(expr.args[2]), - size2mask(expr.args[0].size)) - elif len(expr.args) >= 3 and expr.is_associative(): # ????? oper = ['(%s&0x%x)' % (self.from_expr(arg), size2mask(arg.size)) for arg in expr.args] @@ -144,7 +133,17 @@ class TranslatorC(Translator): def from_ExprCompose(self, expr): out = [] # XXX check mask for 64 bit & 32 bit compat - dst_cast = "uint%d_t" % expr.size + if expr.size in [8, 16, 32, 64, 128]: + size = expr.size + else: + # Uncommon expression size + size = expr.size + next_power = 1 + while next_power <= size: + next_power <<= 1 + size = next_power + + dst_cast = "uint%d_t" % size for index, arg in expr.iter_args(): out.append("(((%s)(%s & 0x%X)) << %d)" % (dst_cast, self.from_expr(arg), diff --git a/miasm2/jitter/Jitgcc.c b/miasm2/jitter/Jitgcc.c index 71023902..79274f24 100644 --- a/miasm2/jitter/Jitgcc.c +++ b/miasm2/jitter/Jitgcc.c @@ -59,7 +59,7 @@ PyObject* gcc_exec_bloc(PyObject* self, PyObject* args) else { if (BlockDst.is_local == 1) { fprintf(stderr, "return on local label!\n"); - exit(1); + exit(EXIT_FAILURE); } // retaddr is not jitted yet return retaddr; diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c index 88359147..61a6cda4 100644 --- a/miasm2/jitter/Jittcc.c +++ b/miasm2/jitter/Jittcc.c @@ -41,7 +41,7 @@ TCCState * tcc_init_state(void) tcc_state = tcc_new(); if (!tcc_state) { fprintf(stderr, "Impossible de creer un contexte TCC\n"); - exit(1); + exit(EXIT_FAILURE); } tcc_set_output_type(tcc_state, TCC_OUTPUT_MEMORY); @@ -184,7 +184,7 @@ PyObject* tcc_exec_bloc(PyObject* self, PyObject* args) else { if (BlockDst.is_local == 1) { fprintf(stderr, "return on local label!\n"); - exit(1); + exit(EXIT_FAILURE); } // retaddr is not jitted yet return retaddr; @@ -221,25 +221,25 @@ PyObject* tcc_compil(PyObject* self, PyObject* args) if (tcc_compile_string(tcc_state, func_code) != 0) { fprintf(stderr, "Error compiling !\n"); fprintf(stderr, "%s\n", func_code); - exit(1); + exit(EXIT_FAILURE); } /* XXX configure tinycc install with --disable-static */ if (tcc_relocate(tcc_state, TCC_RELOCATE_AUTO) < 0) { fprintf(stderr, "TCC relocate error\n"); - exit(1); + exit(EXIT_FAILURE); } entry = tcc_get_symbol(tcc_state, func_name); if (!entry){ fprintf(stderr, "Error getting symbol %s!\n", func_name); fprintf(stderr, "%s\n", func_name); - exit(1); + exit(EXIT_FAILURE); } ret = PyTuple_New(2); if (ret == NULL) { fprintf(stderr, "Error alloc %s!\n", func_name); fprintf(stderr, "%s\n", func_name); - exit(1); + exit(EXIT_FAILURE); } PyTuple_SetItem(ret, 0, PyLong_FromUnsignedLongLong((intptr_t) tcc_state)); @@ -267,7 +267,7 @@ PyObject* tcc_loop_exec(PyObject* self, PyObject* args) while (1) { if (!PyCallable_Check (func)) { fprintf(stderr, "function not callable!\n"); - exit(0); + exit(EXIT_FAILURE); } pArgs = PyTuple_New(2); diff --git a/miasm2/jitter/arch/JitCore_aarch64.c b/miasm2/jitter/arch/JitCore_aarch64.c index e10d847e..ff8241c6 100644 --- a/miasm2/jitter/arch/JitCore_aarch64.c +++ b/miasm2/jitter/arch/JitCore_aarch64.c @@ -332,7 +332,7 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) self->cpu = malloc(sizeof(vm_cpu_t)); if (self->cpu == NULL) { fprintf(stderr, "cannot alloc vm_cpu_t\n"); - exit(0); + exit(EXIT_FAILURE); } return 0; } diff --git a/miasm2/jitter/arch/JitCore_arm.c b/miasm2/jitter/arch/JitCore_arm.c index 84716c2d..6b167da5 100644 --- a/miasm2/jitter/arch/JitCore_arm.c +++ b/miasm2/jitter/arch/JitCore_arm.c @@ -277,7 +277,7 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) self->cpu = malloc(sizeof(vm_cpu_t)); if (self->cpu == NULL) { fprintf(stderr, "cannot alloc vm_cpu_t\n"); - exit(0); + exit(EXIT_FAILURE); } return 0; } diff --git a/miasm2/jitter/arch/JitCore_mips32.c b/miasm2/jitter/arch/JitCore_mips32.c index 04e4d883..19b24f1f 100644 --- a/miasm2/jitter/arch/JitCore_mips32.c +++ b/miasm2/jitter/arch/JitCore_mips32.c @@ -307,7 +307,7 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) self->cpu = malloc(sizeof(vm_cpu_t)); if (self->cpu == NULL) { fprintf(stderr, "cannot alloc vm_cpu_t\n"); - exit(0); + exit(EXIT_FAILURE); } return 0; } diff --git a/miasm2/jitter/arch/JitCore_msp430.c b/miasm2/jitter/arch/JitCore_msp430.c index d30655dd..7fe41413 100644 --- a/miasm2/jitter/arch/JitCore_msp430.c +++ b/miasm2/jitter/arch/JitCore_msp430.c @@ -279,7 +279,7 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) self->cpu = malloc(sizeof(vm_cpu_t)); if (self->cpu == NULL) { fprintf(stderr, "cannot alloc vm_cpu_t\n"); - exit(0); + exit(EXIT_FAILURE); } return 0; } diff --git a/miasm2/jitter/arch/JitCore_x86.c b/miasm2/jitter/arch/JitCore_x86.c index 407a01c7..5c929dab 100644 --- a/miasm2/jitter/arch/JitCore_x86.c +++ b/miasm2/jitter/arch/JitCore_x86.c @@ -437,7 +437,7 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) self->cpu = malloc(sizeof(vm_cpu_t)); if (self->cpu == NULL) { fprintf(stderr, "cannot alloc vm_cpu_t\n"); - exit(0); + exit(EXIT_FAILURE); } return 0; } diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 65c6aa07..9796b265 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -223,24 +223,6 @@ class LLVMContext_JIT(LLVMContext): itype = LLVMType.IntType(64) fc = {"llvm.ctpop.i8": {"ret": i8, "args": [i8]}, - "rot_left": {"ret": itype, - "args": [itype, - itype, - itype]}, - "rot_right": {"ret": itype, - "args": [itype, - itype, - itype]}, - "rcr_rez_op": {"ret": itype, - "args": [itype, - itype, - itype, - itype]}, - "rcl_rez_op": {"ret": itype, - "args": [itype, - itype, - itype, - itype]}, "x86_bsr": {"ret": itype, "args": [itype, itype]}, @@ -391,11 +373,7 @@ class LLVMFunction(): op_translate = {'cpuid': 'cpuid', } ## Add the size as first argument - op_translate_with_size = {'<<<': 'rot_left', - '>>>': 'rot_right', - '<<<c_rez': 'rcl_rez_op', - '>>>c_rez': 'rcr_rez_op', - 'bsr': 'x86_bsr', + op_translate_with_size = {'bsr': 'x86_bsr', 'bsf': 'x86_bsf', } ## Add the size as suffix @@ -790,6 +768,30 @@ class LLVMFunction(): self.update_cache(expr, ret) return ret + + if op in ['<<<', '>>>']: + assert len(expr.args) == 2 + # First compute rotation modulus size + count = self.add_ir(expr.args[1]) + value = self.add_ir(expr.args[0]) + itype = LLVMType.IntType(expr.size) + expr_size = itype(expr.size) + + shift = builder.urem(count, expr_size) + shift_inv = builder.sub(expr_size, shift) + + if op == '<<<': + part_a = builder.shl(value, shift) + part_b = builder.lshr(value, shift_inv) + else: + part_a = builder.lshr(value, shift) + part_b = builder.shl(value, shift_inv) + ret = builder.or_(part_a, part_b) + self.update_cache(expr, ret) + return ret + + + if op in ["int_16_to_double", "int_32_to_double", "int_64_to_double", "mem_16_to_double", "mem_32_to_double", "mem_64_to_double"]: arg = self.add_ir(expr.args[0]) diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c index c628aeff..3c324a08 100644 --- a/miasm2/jitter/vm_mngr.c +++ b/miasm2/jitter/vm_mngr.c @@ -245,7 +245,7 @@ static uint64_t memory_page_read(vm_mngr_t* vm_mngr, unsigned int my_size, uint6 ret = set_endian64(vm_mngr, ret); break; default: - exit(0); + exit(EXIT_FAILURE); break; } } @@ -277,7 +277,7 @@ static uint64_t memory_page_read(vm_mngr_t* vm_mngr, unsigned int my_size, uint6 ret = set_endian64(vm_mngr, ret); break; default: - exit(0); + exit(EXIT_FAILURE); break; } } @@ -330,7 +330,7 @@ static void memory_page_write(vm_mngr_t* vm_mngr, unsigned int my_size, *((uint64_t*)addr) = src&0xFFFFFFFFFFFFFFFFULL; break; default: - exit(0); + exit(EXIT_FAILURE); break; } } @@ -351,7 +351,7 @@ static void memory_page_write(vm_mngr_t* vm_mngr, unsigned int my_size, src = set_endian64(vm_mngr, src); break; default: - exit(0); + exit(EXIT_FAILURE); break; } while (my_size){ @@ -607,7 +607,7 @@ int vm_read_mem(vm_mngr_t* vm_mngr, uint64_t addr, char** buffer_ptr, uint64_t s *buffer_ptr = buffer; if (!buffer){ fprintf(stderr, "Error: cannot alloc read\n"); - exit(-1); + exit(EXIT_FAILURE); } /* read is multiple page wide */ @@ -681,7 +681,7 @@ unsigned int mul_lo_op(unsigned int size, unsigned int a, unsigned int b) case 8: mask = 0xff; break; case 16: mask = 0xffff; break; case 32: mask = 0xffffffff; break; - default: fprintf(stderr, "inv size in mul %d\n", size); exit(0); + default: fprintf(stderr, "inv size in mul %d\n", size); exit(EXIT_FAILURE); } a &= mask; @@ -698,7 +698,7 @@ unsigned int mul_hi_op(unsigned int size, unsigned int a, unsigned int b) case 8: mask = 0xff; break; case 16: mask = 0xffff; break; case 32: mask = 0xffffffff; break; - default: fprintf(stderr, "inv size in mul %d\n", size); exit(0); + default: fprintf(stderr, "inv size in mul %d\n", size); exit(EXIT_FAILURE); } a &= mask; @@ -760,24 +760,37 @@ uint64_t rot_left(uint64_t size, uint64_t a, uint64_t b) { uint64_t tmp; - b = b&0x3F; + b = b & 0x3F; b %= size; switch(size){ case 8: - tmp = (a << b) | ((a&0xFF) >> (size-b)); - return tmp&0xff; + tmp = (a << b) | ((a & 0xFF) >> (size - b)); + return tmp & 0xFF; case 16: - tmp = (a << b) | ((a&0xFFFF) >> (size-b)); - return tmp&0xffff; + tmp = (a << b) | ((a & 0xFFFF) >> (size - b)); + return tmp & 0xFFFF; case 32: - tmp = (a << b) | ((a&0xFFFFFFFF) >> (size-b)); - return tmp&0xffffffff; + tmp = (a << b) | ((a & 0xFFFFFFFF) >> (size - b)); + return tmp & 0xFFFFFFFF; case 64: - tmp = (a << b) | ((a&0xFFFFFFFFFFFFFFFF) >> (size-b)); - return tmp&0xFFFFFFFFFFFFFFFF; + tmp = (a << b) | ((a&0xFFFFFFFFFFFFFFFF) >> (size - b)); + return tmp & 0xFFFFFFFFFFFFFFFF; + + /* Support cases for rcl */ + case 9: + tmp = (a << b) | ((a & 0x1FF) >> (size - b)); + return tmp & 0x1FF; + case 17: + tmp = (a << b) | ((a & 0x1FFFF) >> (size - b)); + return tmp & 0x1FFFF; + case 33: + tmp = (a << b) | ((a & 0x1FFFFFFFF) >> (size - b)); + return tmp & 0x1FFFFFFFF; + /* TODO XXX: support rcl in 64 bit mode */ + default: fprintf(stderr, "inv size in rotleft %"PRIX64"\n", size); - exit(0); + exit(EXIT_FAILURE); } } @@ -785,62 +798,38 @@ uint64_t rot_right(uint64_t size, uint64_t a, uint64_t b) { uint64_t tmp; - b = b&0x3F; + b = b & 0x3F; b %= size; switch(size){ case 8: - tmp = ((a&0xFF) >> b) | (a << (size-b)); - return tmp&0xff; + tmp = ((a & 0xFF) >> b) | (a << (size - b)); + return tmp & 0xff; case 16: - tmp = ((a&0xFFFF) >> b) | (a << (size-b)); - return tmp&0xffff; + tmp = ((a & 0xFFFF) >> b) | (a << (size - b)); + return tmp & 0xFFFF; case 32: - tmp = ((a&0xFFFFFFFF) >> b) | (a << (size-b)); - return tmp&0xffffffff; + tmp = ((a & 0xFFFFFFFF) >> b) | (a << (size - b)); + return tmp & 0xFFFFFFFF; case 64: - tmp = ((a&0xFFFFFFFFFFFFFFFF) >> b) | (a << (size-b)); - return tmp&0xFFFFFFFFFFFFFFFF; + tmp = ((a & 0xFFFFFFFFFFFFFFFF) >> b) | (a << (size - b)); + return tmp & 0xFFFFFFFFFFFFFFFF; + + /* Support cases for rcr */ + case 9: + tmp = ((a & 0x1FF) >> b) | (a << (size - b)); + return tmp & 0x1FF; + case 17: + tmp = ((a & 0x1FFFF) >> b) | (a << (size - b)); + return tmp & 0x1FFFF; + case 33: + tmp = ((a & 0x1FFFFFFFF) >> b) | (a << (size - b)); + return tmp & 0x1FFFFFFFF; + /* TODO XXX: support rcr in 64 bit mode */ + default: fprintf(stderr, "inv size in rotright %"PRIX64"\n", size); - exit(0); - } -} - - -unsigned int rcl_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf) -{ - uint64_t tmp; - uint64_t tmp_count; - uint64_t tmp_cf; - - tmp = a; - // TODO 64bit mode - tmp_count = (b & 0x1f) % (size + 1); - while (tmp_count != 0) { - tmp_cf = (tmp >> (size - 1)) & 1; - tmp = (tmp << 1) + cf; - cf = tmp_cf; - tmp_count -= 1; - } - return tmp; -} - -unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf) -{ - uint64_t tmp; - uint64_t tmp_count; - uint64_t tmp_cf; - - tmp = a; - // TODO 64bit mode - tmp_count = (b & 0x1f) % (size + 1); - while (tmp_count != 0) { - tmp_cf = tmp & 1; - tmp = (tmp >> 1) + (cf << (size - 1)); - cf = tmp_cf; - tmp_count -= 1; + exit(EXIT_FAILURE); } - return tmp; } unsigned int x86_bsr(uint64_t size, uint64_t src) @@ -852,7 +841,7 @@ unsigned int x86_bsr(uint64_t size, uint64_t src) return i; } fprintf(stderr, "sanity check error bsr\n"); - exit(0); + exit(EXIT_FAILURE); } unsigned int x86_bsf(uint64_t size, uint64_t src) @@ -863,7 +852,7 @@ unsigned int x86_bsf(uint64_t size, uint64_t src) return i; } fprintf(stderr, "sanity check error bsf\n"); - exit(0); + exit(EXIT_FAILURE); } @@ -884,7 +873,7 @@ unsigned int cpuid(unsigned int a, unsigned int reg_num) { if (reg_num >3){ fprintf(stderr, "not implemented cpuid reg %x\n", reg_num); - exit(-1); + exit(EXIT_FAILURE); } if (a == 0){ @@ -918,7 +907,7 @@ unsigned int cpuid(unsigned int a, unsigned int reg_num) } else{ fprintf(stderr, "WARNING not implemented cpuid index %X!\n", a); - //exit(-1); + //exit(EXIT_FAILURE); } return 0; } @@ -1400,7 +1389,7 @@ struct code_bloc_node * create_code_bloc_node(uint64_t ad_start, uint64_t ad_sto cbp = malloc(sizeof(*cbp)); if (!cbp){ fprintf(stderr, "Error: cannot alloc cbp\n"); - exit(-1); + exit(EXIT_FAILURE); } cbp->ad_start = ad_start; @@ -1630,7 +1619,7 @@ void add_memory_breakpoint(vm_mngr_t* vm_mngr, uint64_t ad, uint64_t size, unsig mpn_a = malloc(sizeof(*mpn_a)); if (!mpn_a) { fprintf(stderr, "Error: cannot alloc\n"); - exit(0); + exit(EXIT_FAILURE); } mpn_a->ad = ad; mpn_a->size = size; diff --git a/miasm2/jitter/vm_mngr.h b/miasm2/jitter/vm_mngr.h index 757c3b3e..71ecc246 100644 --- a/miasm2/jitter/vm_mngr.h +++ b/miasm2/jitter/vm_mngr.h @@ -216,8 +216,6 @@ unsigned int umul16_hi(unsigned short a, unsigned short b); uint64_t rot_left(uint64_t size, uint64_t a, uint64_t b); uint64_t rot_right(uint64_t size, uint64_t a, uint64_t b); -unsigned int rcl_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf); -unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf); #define UDIV(sizeA) \ @@ -226,7 +224,7 @@ unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsig uint ## sizeA ## _t r; \ if (b == 0) { \ fprintf(stderr, "Should not happen\n"); \ - exit(0); \ + exit(EXIT_FAILURE); \ } \ r = a/b; \ return r; \ @@ -239,7 +237,7 @@ unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsig uint ## sizeA ## _t r; \ if (b == 0) { \ fprintf(stderr, "Should not happen\n"); \ - exit(0); \ + exit(EXIT_FAILURE); \ } \ r = a%b; \ return r; \ @@ -252,7 +250,7 @@ unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsig int ## sizeA ## _t r; \ if (b == 0) { \ fprintf(stderr, "Should not happen\n"); \ - exit(0); \ + exit(EXIT_FAILURE); \ } \ r = a/b; \ return r; \ @@ -265,7 +263,7 @@ unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsig int ## sizeA ## _t r; \ if (b == 0) { \ fprintf(stderr, "Should not happen\n"); \ - exit(0); \ + exit(EXIT_FAILURE); \ } \ r = a%b; \ return r; \ diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index b4f5b783..e4c3f2e9 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -301,18 +301,6 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (expr_cmps(ExprInt(-10, 32), ExprInt(-5, 32)), ExprInt(0, 1)), - (ExprOp("<<<c_rez", i1, i0, i0), - i1), - (ExprOp("<<<c_rez", i1, i1, i0), - ExprInt(2, 32)), - (ExprOp("<<<c_rez", i1, i1, i1), - ExprInt(3, 32)), - (ExprOp(">>>c_rez", icustom, i0, i0), - icustom), - (ExprOp(">>>c_rez", icustom, i1, i0), - ExprInt(0x91A2B3C, 32)), - (ExprOp(">>>c_rez", icustom, i1, i1), - ExprInt(0x891A2B3C, 32)), (ExprOp("idiv", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], ExprInt(0xc6, 8)), (ExprOp("imod", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], |