|
miasm
Reverse engineering framework
|
Go to the documentation of this file.
21 #if defined(_WIN32) || defined(_WIN64)
22 #define _CRT_SECURE_NO_WARNINGS
26 #define _MIASM_EXPORT __declspec(dllexport)
37 #define __BYTE_ORDER __BYTE_ORDER__
38 #define __BIG_ENDIAN BIG_ENDIAN
39 #define __LITTLE_ENDIAN LITTLE_ENDIAN
40 #elif defined(__NetBSD__) || defined(__OpenBSD__)
41 #define __BYTE_ORDER _BYTE_ORDER
42 #define __BIG_ENDIAN _BIG_ENDIAN
43 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
44 #elif defined(_WIN32) || defined(_WIN64)
45 #define __BYTE_ORDER __LITTLE_ENDIAN
46 #define __BIG_ENDIAN '>'
47 #define __LITTLE_ENDIAN '<'
48 #elif defined(__ANDROID__)
49 #define __BYTE_ORDER __BYTE_ORDER__
50 #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
51 #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
55 #define Endian16_Swap(value) \
56 ((((uint16_t)((value) & 0x00FF)) << 8) | \
57 (((uint16_t)((value) & 0xFF00)) >> 8))
59 #define Endian32_Swap(value) \
60 ((((uint32_t)((value) & 0x000000FF)) << 24) | \
61 (((uint32_t)((value) & 0x0000FF00)) << 8) | \
62 (((uint32_t)((value) & 0x00FF0000)) >> 8) | \
63 (((uint32_t)((value) & 0xFF000000)) >> 24))
65 #define Endian64_Swap(value) \
66 (((((uint64_t)value)<<56) & 0xFF00000000000000ULL) | \
67 ((((uint64_t)value)<<40) & 0x00FF000000000000ULL) | \
68 ((((uint64_t)value)<<24) & 0x0000FF0000000000ULL) | \
69 ((((uint64_t)value)<< 8) & 0x000000FF00000000ULL) | \
70 ((((uint64_t)value)>> 8) & 0x00000000FF000000ULL) | \
71 ((((uint64_t)value)>>24) & 0x0000000000FF0000ULL) | \
72 ((((uint64_t)value)>>40) & 0x000000000000FF00ULL) | \
73 ((((uint64_t)value)>>56) & 0x00000000000000FFULL))
80 #define BREAKPOINT_READ 1
81 #define BREAKPOINT_WRITE 2
83 #define BREAK_SIGALARM 1<<5
85 #define MAX_MEMORY_PAGE_POOL_TAB 0x100000
86 #define MEMORY_PAGE_POOL_MASK_BIT 12
87 #define VM_BIG_ENDIAN 1
88 #define VM_LITTLE_ENDIAN 2
113 struct memory_breakpoint_info_head memory_breakpoint_pool;
166 #define EXCEPT_DO_NOT_UPDATE_PC (1<<25)
169 #define EXCEPT_CODE_AUTOMOD (1<<0)
170 #define EXCEPT_SOFT_BP (1<<1)
171 #define EXCEPT_INT_XX (1<<2)
173 #define EXCEPT_BREAKPOINT_MEMORY (1<<10)
175 #define EXCEPT_BREAKPOINT_INTERN (EXCEPT_BREAKPOINT_MEMORY)
177 #define EXCEPT_NUM_UPDT_EIP (1<<11)
179 #define EXCEPT_UNK_MEM_AD ((1<<12) | EXCEPT_DO_NOT_UPDATE_PC)
180 #define EXCEPT_THROW_SEH ((1<<13) | EXCEPT_DO_NOT_UPDATE_PC)
181 #define EXCEPT_UNK_EIP ((1<<14) | EXCEPT_DO_NOT_UPDATE_PC)
182 #define EXCEPT_ACCESS_VIOL ((1<<14) | EXCEPT_DO_NOT_UPDATE_PC)
183 #define EXCEPT_INT_DIV_BY_ZERO ((1<<16) | EXCEPT_DO_NOT_UPDATE_PC)
184 #define EXCEPT_PRIV_INSN ((1<<17) | EXCEPT_DO_NOT_UPDATE_PC)
185 #define EXCEPT_ILLEGAL_INSN ((1<<18) | EXCEPT_DO_NOT_UPDATE_PC)
186 #define EXCEPT_UNK_MNEMO ((1<<19) | EXCEPT_DO_NOT_UPDATE_PC)
187 #define EXCEPT_INT_1 ((1<<20) | EXCEPT_DO_NOT_UPDATE_PC)
PyObject * get_memory_read(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:452
void init_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:743
void func_loadlib_fake(void)
void func_virtualfree_memory_page(void)
unsigned int load_segment_limit_ok(unsigned int d)
struct memory_page_node * memory_pages_array
Definition: vm_mngr.h:116
PyObject * get_memory_write(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:457
void add_mem_write(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t size)
Definition: vm_mngr.c:370
unsigned int load_segment_limit(unsigned int d)
l
Definition: single_instr.py:7
int is_mem_mapped(vm_mngr_t *vm_mngr, uint64_t ad)
#define Endian16_Swap(value)
Definition: vm_mngr.h:55
void MEM_WRITE_32_PASSTHROUGH(uint64_t addr, unsigned int src)
int vm_read_mem(vm_mngr_t *vm_mngr, uint64_t addr, char **buffer_ptr, size_t size)
Definition: vm_mngr.c:514
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *vm_mngr, uint64_t ad, int raise_exception)
Definition: vm_mngr.c:139
m
Definition: expr_grapher.py:11
void _func_malloc_memory_page(void)
void dump_memory_breakpoint_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:940
uint64_t set_endian64(vm_mngr_t *vm_mngr, uint64_t val)
Definition: vm_mngr.c:98
void vm_MEM_WRITE_64(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t src)
Definition: vm_mngr.c:478
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *, uint64_t ad, int raise_exception)
Definition: vm_mngr.c:139
void reset_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:776
void dump_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:724
void memory_access_list_reset(struct memory_access_list *access)
Definition: vm_mngr.c:47
unsigned int access_segment_ok(unsigned int d)
uint64_t ad
Definition: vm_mngr.h:154
void add_mem_read(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t size)
Definition: vm_mngr.c:365
Definition: vm_mngr.h:145
void vm_MEM_WRITE_32(vm_mngr_t *vm_mngr, uint64_t addr, unsigned int src)
Definition: vm_mngr.c:473
void add_code_bloc(vm_mngr_t *vm_mngr, struct code_bloc_node *cbp)
Definition: vm_mngr.c:715
_MIASM_EXPORT void check_invalid_code_blocs(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:375
int is_mpn_in_tab(vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
Definition: vm_mngr.c:811
void add_memory_breakpoint(vm_mngr_t *vm_mngr, uint64_t ad, uint64_t size, unsigned int access)
Definition: vm_mngr.c:954
void MEM_WRITE_16_PASSTHROUGH(uint64_t addr, unsigned short src)
int find_page_node(struct memory_page_node *array, uint64_t key, int imin, int imax)
Definition: vm_mngr.c:118
PyObject * get_memory_pylist(vm_mngr_t *vm_mngr, struct memory_access_list *memory_list)
Definition: vm_mngr.c:435
void reset_memory_page_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:761
unsigned short vm_MEM_LOOKUP_16(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:491
i
Definition: modint.py:70
struct memory_access * array
Definition: vm_mngr.h:105
char * name
Definition: vm_mngr.h:96
void vm_MEM_WRITE_16(vm_mngr_t *vm_mngr, uint64_t addr, unsigned short src)
Definition: vm_mngr.c:468
#define PAGE_READ
Definition: vm_mngr.h:162
size_t size
Definition: vm_mngr.h:93
void hexdump(char *m, unsigned int l)
Definition: vm_mngr.c:984
struct memory_page_node * create_memory_page_node(uint64_t ad, size_t size, unsigned int access, const char *name)
Definition: vm_mngr.c:664
void reset_memory_access(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:790
void _func_virtualfree_memory_page(void)
uint32_t set_endian32(vm_mngr_t *vm_mngr, uint32_t val)
Definition: vm_mngr.c:90
int vm_write_mem(vm_mngr_t *vm_mngr, uint64_t addr, char *buffer, size_t size)
Definition: vm_mngr.c:594
uint64_t access
Definition: vm_mngr.h:156
PyObject * get_memory_read(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:452
#define PAGE_EXEC
Definition: vm_mngr.h:164
#define Endian32_Swap(value)
Definition: vm_mngr.h:59
LIST_ENTRY(code_bloc_node) next
ad_start
Definition: shellcode.py:115
unsigned int _get_memory_page_max_address_py(void)
void remove_memory_page(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:865
LIST_HEAD(code_bloc_list_head, code_bloc_node)
char * dump(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:892
#define EXCEPT_CODE_AUTOMOD
Definition: vm_mngr.h:169
#define LIST_REMOVE(elm, field)
Definition: queue.h:370
size_t allocated
Definition: vm_mngr.h:106
void memory_access_list_init(struct memory_access_list *access)
Definition: vm_mngr.c:40
void * ad_hp
Definition: vm_mngr.h:95
void memory_access_list_add(struct memory_access_list *access, uint64_t start, uint64_t stop)
Definition: vm_mngr.c:57
void vm_MEM_WRITE_08(vm_mngr_t *vm_mngr, uint64_t addr, unsigned char src)
Definition: vm_mngr.c:462
uint64_t exception_flags
Definition: vm_mngr.h:121
ad
Definition: full.py:147
unsigned int get_memory_page_max_address_py(void)
void check_invalid_code_blocs(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:375
void dump_memory_breakpoint_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:940
d
Definition: basic_op.py:30
int midpoint(int imin, int imax)
Definition: vm_mngr.c:112
void vm_throw(vm_mngr_t *vm_mngr, unsigned long flags)
void check_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:404
void vm_MEM_WRITE_64(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t src)
Definition: vm_mngr.c:478
unsigned int load_tr_segment_selector(unsigned int d)
def ret(arg1)
Definition: sem.py:1796
unsigned char vm_MEM_LOOKUP_08(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:484
int write_num
Definition: vm_mngr.h:130
unsigned int _get_memory_page_from_min_ad_py(unsigned int size)
void dump_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:724
void _func_virtualalloc_memory_page(void)
void reset_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:796
uint64_t size
Definition: vm_mngr.h:155
void add_mem_read(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t size)
Definition: vm_mngr.c:365
start
Definition: arm_sc.py:36
unsigned int access_segment(unsigned int d)
void add_memory_breakpoint(vm_mngr_t *vm_mngr, uint64_t ad, uint64_t size, unsigned int access)
Definition: vm_mngr.c:954
uint16_t set_endian16(vm_mngr_t *vm_mngr, uint16_t val)
Definition: vm_mngr.c:82
unsigned short vm_MEM_LOOKUP_16(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:491
void init_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:743
uint64_t vm_MEM_LOOKUP_64(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:505
struct code_bloc_node * create_code_bloc_node(uint64_t ad_start, uint64_t ad_stop)
Definition: vm_mngr.c:698
_MIASM_EXPORT void reset_memory_access(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:790
struct code_bloc_list_head code_bloc_pool
int is_mapped(vm_mngr_t *vm_mngr, uint64_t addr, size_t size)
Definition: vm_mngr.c:632
unsigned int get_memory_page_max_user_address_py(void)
int memory_pages_number
Definition: vm_mngr.h:115
def j(arg1)
Definition: sem.py:156
void remove_memory_breakpoint(vm_mngr_t *vm_mngr, uint64_t ad, unsigned int access)
Definition: vm_mngr.c:970
int vm_write_mem(vm_mngr_t *vm_mngr, uint64_t addr, char *buffer, size_t size)
Definition: vm_mngr.c:594
name
Definition: export_llvm.py:70
#define LIST_INIT(head)
Definition: queue.h:342
void add_memory_page(vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
Definition: vm_mngr.c:836
void MEM_WRITE_08_PASSTHROUGH(uint64_t addr, unsigned char src)
void vm_MEM_WRITE_08(vm_mngr_t *vm_mngr, uint64_t addr, unsigned char src)
Definition: vm_mngr.c:462
unsigned int get_memory_page_max_address(void)
void reset_code_bloc_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:776
PyObject * addr2BlocObj(vm_mngr_t *vm_mngr, uint64_t addr)
void dump_code_bloc(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:335
uint64_t get_mem_base_addr(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t *addr_base)
last
Definition: test_types.py:289
void add_range_to_list(struct memory_access_list *access, uint64_t addr1, uint64_t addr2)
Definition: vm_mngr.c:344
#define EXCEPT_ACCESS_VIOL
Definition: vm_mngr.h:182
void init_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:755
#define LIST_FIRST(head)
Definition: queue.h:330
Definition: vm_mngr.h:153
int is_mpn_in_tab(vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
Definition: vm_mngr.c:811
void reset_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:796
ptr
Definition: expr_c.py:44
void reset_memory_page_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:761
unsigned int MEM_LOOKUP(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t addr)
uint64_t start
Definition: vm_mngr.h:100
uint64_t code_bloc_pool_ad_max
Definition: vm_mngr.h:119
void vm_MEM_WRITE_16(vm_mngr_t *vm_mngr, uint64_t addr, unsigned short src)
Definition: vm_mngr.c:468
void init_memory_page_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:736
stderr
Definition: dse_crackme.py:320
int sex
Definition: vm_mngr.h:111
PyObject * get_memory_write(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:457
void add_mem_write(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t size)
Definition: vm_mngr.c:370
struct memory_page_node * create_memory_page_node(uint64_t ad, size_t size, unsigned int access, const char *name)
Definition: vm_mngr.c:664
void print_val(uint64_t base, uint64_t addr)
Definition: vm_mngr.c:106
uint16_t set_endian16(vm_mngr_t *vm_mngr, uint16_t val)
Definition: vm_mngr.c:82
int vm_read_mem(vm_mngr_t *vm_mngr, uint64_t addr, char **buffer_ptr, size_t size)
Definition: vm_mngr.c:514
uint64_t vm_read_mem_ret_buf(vm_mngr_t *vm_mngr, uint64_t addr, size_t size, char *buffer)
Definition: vm_mngr.c:559
Definition: vm_mngr.h:136
ad_stop
Definition: shellcode.py:116
#define _MIASM_EXPORT
Definition: JitCore_x86.h:6
uint64_t vm_MEM_LOOKUP_64(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:505
Definition: vm_mngr.h:104
base
Definition: arch.py:499
unsigned int vm_MEM_LOOKUP_32(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:498
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:361
char * dump(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:892
int is_mapped(vm_mngr_t *vm_mngr, uint64_t addr, size_t size)
Definition: vm_mngr.c:632
size_t num
Definition: vm_mngr.h:107
void remove_memory_breakpoint(vm_mngr_t *vm_mngr, uint64_t ad, unsigned int access)
Definition: vm_mngr.c:970
void memory_access_list_init(struct memory_access_list *access)
Definition: vm_mngr.c:40
void memory_access_list_add(struct memory_access_list *access, uint64_t start, uint64_t stop)
Definition: vm_mngr.c:57
void func_virtualalloc_memory_page(void)
void add_memory_page(vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
Definition: vm_mngr.c:836
_MIASM_EXPORT void check_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:404
#define Endian64_Swap(value)
Definition: vm_mngr.h:65
uint64_t ad_code
Definition: vm_mngr.h:148
void vm_MEM_WRITE_32(vm_mngr_t *vm_mngr, uint64_t addr, unsigned int src)
Definition: vm_mngr.c:473
unsigned char vm_MEM_LOOKUP_08(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:484
flags
Definition: minidump_to_pe.py:38
unsigned short MEM_LOOKUP_16_PASSTHROUGH(uint64_t addr)
stop
Definition: arm_sc.py:37
#define MIN(a, b)
Definition: vm_mngr.c:35
#define EXCEPT_BREAKPOINT_MEMORY
Definition: vm_mngr.h:173
void init_memory_breakpoint(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:755
key
Definition: full.py:209
#define BREAKPOINT_READ
Definition: vm_mngr.h:80
uint64_t code_bloc_pool_ad_min
Definition: vm_mngr.h:118
addr
Definition: dis_binary.py:24
uint32_t set_endian32(vm_mngr_t *vm_mngr, uint32_t val)
Definition: vm_mngr.c:90
PyObject * func
Definition: vm_mngr.h:137
unsigned int get_memory_page_from_min_ad_py(unsigned int size)
_MIASM_EXPORT uint64_t get_exception_flag(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:1025
unsigned int _get_memory_page_max_user_address_py(void)
unsigned int get_memory_page_max_user_address(void)
void init_memory_page_pool(vm_mngr_t *vm_mngr)
Definition: vm_mngr.c:736
uint64_t exception_flags_new
Definition: vm_mngr.h:122
Definition: vm_mngr.h:110
struct code_bloc_node * create_code_bloc_node(uint64_t ad_start, uint64_t ad_stop)
Definition: vm_mngr.c:698
uint64_t ad_start
Definition: vm_mngr.h:146
void remove_memory_page(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:865
uint64_t ad_stop
Definition: vm_mngr.h:147
void _func_getproc_fake(void)
uint64_t set_endian64(vm_mngr_t *vm_mngr, uint64_t val)
Definition: vm_mngr.c:98
unsigned int MEM_LOOKUP_32_PASSTHROUGH(uint64_t addr)
void func_getproc_fake(void)
#define LIST_EMPTY(head)
Definition: queue.h:328
val
Definition: example_types.py:218
void MEM_WRITE_64_PASSTHROUGH(uint64_t addr, uint64_t src)
void memory_access_list_reset(struct memory_access_list *access)
Definition: vm_mngr.c:47
unsigned int vm_MEM_LOOKUP_32(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:498
void _func_loadlib_fake(void)
#define _MIASM_EXPORT
Definition: vm_mngr.h:28
void func_malloc_memory_page(void)
uint64_t MEM_LOOKUP_64_PASSTHROUGH(uint64_t addr)
uint64_t access
Definition: vm_mngr.h:94
void add_code_bloc(vm_mngr_t *vm_mngr, struct code_bloc_node *cbp)
Definition: vm_mngr.c:715
#define BREAKPOINT_WRITE
Definition: vm_mngr.h:81
size
Definition: shellcode.py:32
b
Definition: basic_op.py:10
unsigned char MEM_LOOKUP_08_PASSTHROUGH(uint64_t addr)
void func_free_memory_page(void)
void _func_free_memory_page(void)
LIST_ENTRY(memory_breakpoint_info) next
uint64_t stop
Definition: vm_mngr.h:101
uint64_t ad
Definition: vm_mngr.h:92
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
void hexdump(char *m, unsigned int l)
Definition: vm_mngr.c:984
#define PAGE_WRITE
Definition: vm_mngr.h:163