diff options
Diffstat (limited to 'miasm2/jitter')
| -rw-r--r-- | miasm2/jitter/Jittcc.c | 6 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore.py | 2 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.c | 77 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.h | 48 |
4 files changed, 33 insertions, 100 deletions
diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c index 2a85375d..955491ad 100644 --- a/miasm2/jitter/Jittcc.c +++ b/miasm2/jitter/Jittcc.c @@ -88,8 +88,7 @@ PyObject* tcc_set_emul_lib_path(PyObject* self, PyObject* args) include_array_count ++; include_array = realloc(include_array, include_array_count * sizeof(char*)); - if (include_array == NULL) - { + if (include_array == NULL) { fprintf(stderr, "cannot realloc char* include_array\n"); exit(EXIT_FAILURE); } @@ -107,8 +106,7 @@ PyObject* tcc_set_emul_lib_path(PyObject* self, PyObject* args) lib_array_count ++; lib_array = realloc(lib_array, lib_array_count * sizeof(char*)); - if (lib_array == NULL) - { + if (lib_array == NULL) { fprintf(stderr, "cannot realloc char* lib_array\n"); exit(EXIT_FAILURE); } diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 741760cd..9c35f829 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -47,7 +47,6 @@ class JitCore(object): self.log_regs = False self.log_newbloc = False self.segm_to_do = set() - self.job_done = set() self.jitcount = 0 self.addr2obj = {} self.addr2objref = {} @@ -140,7 +139,6 @@ class JitCore(object): addr = addr.offset # Prepare disassembler - self.mdis.job_done.clear() self.mdis.lines_wd = self.options["jit_maxline"] self.mdis.dis_bloc_callback = self.disasm_cb diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c index 1114185b..59cbdf6e 100644 --- a/miasm2/jitter/vm_mngr.c +++ b/miasm2/jitter/vm_mngr.c @@ -103,6 +103,10 @@ void memory_access_list_add(struct memory_access_list * access, uint64_t start, else access->allocated *= 2; access->array = realloc(access->array, access->allocated * sizeof(struct memory_access)); + if (access->array == NULL) { + fprintf(stderr, "cannot realloc struct memory_access access->array\n"); + exit(EXIT_FAILURE); + } } access->array[access->num].start = start; access->array[access->num].stop = stop; @@ -669,66 +673,6 @@ int is_mapped(vm_mngr_t* vm_mngr, uint64_t addr, uint64_t size) return 1; } -int shift_right_arith(unsigned int size, int a, unsigned int b) -{ - int i32_a; - short i16_a; - char i8_a; - switch(size){ - case 8: - i8_a = a; - return (i8_a >> b)&0xff; - case 16: - i16_a = a; - return (i16_a >> b)&0xffff; - case 32: - i32_a = a; - return (i32_a >> b)&0xffffffff; - default: - fprintf(stderr, "inv size in shift %d\n", size); - exit(0); - } -} - -uint64_t shift_right_logic(uint64_t size, - uint64_t a, uint64_t b) -{ - uint64_t u32_a; - unsigned short u16_a; - unsigned char u8_a; - switch(size){ - case 8: - u8_a = a; - return (u8_a >> b)&0xff; - case 16: - u16_a = a; - return (u16_a >> b)&0xffff; - case 32: - u32_a = a; - return (u32_a >> b)&0xffffffff; - default: - fprintf(stderr, "inv size in shift %"PRIx64"\n", size); - exit(0); - } -} - -uint64_t shift_left_logic(uint64_t size, uint64_t a, uint64_t b) -{ - switch(size){ - case 8: - return (a<<b)&0xff; - case 16: - return (a<<b)&0xffff; - case 32: - return (a<<b)&0xffffffff; - case 64: - return (a<<b)&0xffffffffffffffff; - default: - fprintf(stderr, "inv size in shift %"PRIx64"\n", size); - exit(0); - } -} - unsigned int mul_lo_op(unsigned int size, unsigned int a, unsigned int b) { unsigned int mask; @@ -1602,6 +1546,11 @@ void add_memory_page(vm_mngr_t* vm_mngr, struct memory_page_node* mpn_a) vm_mngr->memory_pages_array = realloc(vm_mngr->memory_pages_array, sizeof(struct memory_page_node) * (vm_mngr->memory_pages_number+1)); + if (vm_mngr->memory_pages_array == NULL) { + fprintf(stderr, "cannot realloc struct memory_page_node vm_mngr->memory_pages_array\n"); + exit(EXIT_FAILURE); + } + memmove(&vm_mngr->memory_pages_array[i+1], &vm_mngr->memory_pages_array[i], @@ -1629,8 +1578,8 @@ char* dump(vm_mngr_t* vm_mngr) buf_final = malloc(total_len); if (buf_final == NULL) { - fprintf(stderr, "Error: cannot alloc\n"); - exit(0); + fprintf(stderr, "Error: cannot alloc char* buf_final\n"); + exit(EXIT_FAILURE); } strcpy(buf_final, intro); for (i=0; i< vm_mngr->memory_pages_number; i++) { @@ -1653,8 +1602,8 @@ char* dump(vm_mngr_t* vm_mngr) total_len += length + 1 + 1; buf_final = realloc(buf_final, total_len); if (buf_final == NULL) { - fprintf(stderr, "Error: cannot alloc\n"); - exit(0); + fprintf(stderr, "cannot realloc char* buf_final\n"); + exit(EXIT_FAILURE); } strcat(buf_final, buf); } diff --git a/miasm2/jitter/vm_mngr.h b/miasm2/jitter/vm_mngr.h index 74ad49ad..757c3b3e 100644 --- a/miasm2/jitter/vm_mngr.h +++ b/miasm2/jitter/vm_mngr.h @@ -199,10 +199,7 @@ unsigned int my_imul08(unsigned int a, unsigned int b); int is_mapped(vm_mngr_t* vm_mngr, uint64_t addr, uint64_t size); void vm_throw(vm_mngr_t* vm_mngr, unsigned long flags); -int shift_right_arith(unsigned int size, int a, unsigned int b); -uint64_t shift_right_logic(uint64_t size, uint64_t a, uint64_t b); -uint64_t shift_left_logic(uint64_t size, uint64_t a, uint64_t b); unsigned int mul_lo_op(unsigned int size, unsigned int a, unsigned int b); unsigned int mul_hi_op(unsigned int size, unsigned int a, unsigned int b); unsigned int imul_lo_op_08(char a, char b); @@ -402,32 +399,23 @@ unsigned int load_segment_limit(unsigned int d); unsigned int load_segment_limit_ok(unsigned int d); unsigned int load_tr_segment_selector(unsigned int d); -#define shift_right_arith_08(a, b)\ - ((((char)(a)) >> ((int)(b)&0x1f))&0xff) -#define shift_right_arith_16(a, b)\ - ((((short)(a)) >> ((int)(b)&0x1f))&0xffff) -#define shift_right_arith_32(a, b)\ - ((((int)(a)) >> ((int)(b)&0x1f))&0xffffffff) -#define shift_right_arith_64(a, b)\ - ((((int64_t)(a)) >> ((int64_t)(b)&0x3f))&0xffffffffffffffff) - - -#define shift_right_logic_08(a, b)\ - ((((unsigned char)(a)) >> ((unsigned int)(b)&0x1f))&0xff) -#define shift_right_logic_16(a, b)\ - ((((unsigned short)(a)) >> ((unsigned int)(b)&0x1f))&0xffff) -#define shift_right_logic_32(a, b)\ - ((((unsigned int)(a)) >> ((unsigned int)(b)&0x1f))&0xffffffff) -#define shift_right_logic_64(a, b)\ - ((((uint64_t)(a)) >> ((uint64_t)(b)&0x3f))&0xffffffffffffffff) - -#define shift_left_logic_08(a, b)\ - (((a)<<((b)&0x1f))&0xff) -#define shift_left_logic_16(a, b)\ - (((a)<<((b)&0x1f))&0xffff) -#define shift_left_logic_32(a, b)\ - (((a)<<((b)&0x1f))&0xffffffff) -#define shift_left_logic_64(a, b)\ - (((a)<<((b)&0x3f))&0xffffffffffffffff) + + +#define SHIFT_RIGHT_ARITH(size, value, shift) \ + ((uint ## size ## _t)((((uint64_t) (shift)) > ((size) - 1))? \ + (((int ## size ## _t) (value)) < 0 ? -1 : 0) : \ + (((int ## size ## _t) (value)) >> (shift)))) + +#define SHIFT_RIGHT_LOGIC(size, value, shift) \ + ((uint ## size ## _t)((((uint64_t) (shift)) > ((size) - 1))? \ + 0 : \ + (((uint ## size ## _t) (value)) >> (shift)))) + +#define SHIFT_LEFT_LOGIC(size, value, shift) \ + ((uint ## size ## _t)((((uint64_t) (shift)) > ((size) - 1))? \ + 0 : \ + (((uint ## size ## _t) (value)) << (shift)))) + + #endif |