Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
arch_x86.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "config.h"
20 #include "string.h"
21 #include "common.h"
22 #include "arch.h"
23 #include "arch_x86.h"
24 
25 static char *x86_reg_names[ARCH_X86_REG_COUNT] = {
26  "eax","ecx","edx","ebx","esp","ebp","esi","edi","eip","eflags",
27  NULL,
28  "st0","st1","st2","st3","st4","st5","st6","st7",
29  NULL,NULL,
30  "xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7",
31  "mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7",
32  "x87cw","x87sw","mxcsr",
33  "es","cs","ss","ds","fs","gs",
34  "cr0","cr1","cr2","cr3","cr4",
35  "dr0","dr1","dr2","dr3",NULL,NULL,"dr6","dr7",
36  "efer",
37 };
38 
39 static REG x86_common_to_arch[COMMON_REG_COUNT] = {
40  [CREG_IP] = REG_X86_EIP,
41  [CREG_SP] = REG_X86_ESP,
42  [CREG_BP] = REG_X86_EBP,
45 };
46 
47 static uint8_t x86_reg_sizes[ARCH_X86_REG_COUNT] = {
48  4,4,4,4,4,4,4,4,4,4,
49  0,
50  10,10,10,10,10,10,10,10,
51  0,0,
52  16,16,16,16,16,16,16,16,
53  16,16,16,16,16,16,16,16,
54  4,4,4,
55  4,4,4,4,4,4,
56  4,4,4,4,4,
57  4,4,4,4,0,0,4,4,
58  4,
59 };
60 
61 static int x86_so_d0[] = { -1, };
62 static int x86_so_d1[] = {
67 };
68 static int x86_so_d2[] = {
71 };
72 static int *x86_snprintf_ordering[ARCH_SNPRINTF_DETAIL_LEVELS] = {
73  x86_so_d0,x86_so_d1,x86_so_d2,
74 };
75 static uint8_t x86_bpi[] = { 0xcc, };
76 static uint8_t x86_ri[] = { 0xc3, };
77 static uint8_t x86_fri[] = { 0xc9,0xc3, };
78 
79 struct arch arch_x86 = {
80  .type = ARCH_X86,
81 
82  .endian = ENDIAN_LITTLE,
83  .wordsize = 4,
84  .ptrsize = 4,
85 
86  .regcount = ARCH_X86_REG_COUNT,
87 
88  .reg_sizes = x86_reg_sizes,
89  .common_to_arch = x86_common_to_arch,
90  .reg_names = x86_reg_names,
91 
92  .snprintf_ordering = { x86_so_d0,x86_so_d1,x86_so_d2, },//x86_snprintf_ordering,
93  .max_snprintf_ordering = 2,
94 
95  .breakpoint_instrs = x86_bpi,
96  .breakpoint_instrs_len = 1,
97  .breakpoint_instr_count = 1,
98 
99  .ret_instrs = x86_ri,
100  .ret_instrs_len = 1,
101  .ret_instr_count = 1,
102 
103  /* LEAVE, RET */
104  .full_ret_instrs = x86_fri,
105  .full_ret_instrs_len = 2,
106  .full_ret_instr_count = 2,
107 };
arch_type_t type
Definition: arch.h:117
#define REG_X86_CR1
Definition: arch_x86.h:100
#define REG_X86_DS
Definition: arch_x86.h:86
#define REG_X86_EDI
Definition: arch_x86.h:44
#define REG_X86_ECX
Definition: arch_x86.h:38
#define REG_X86_ES
Definition: arch_x86.h:83
#define REG_X86_DR2
Definition: arch_x86.h:107
Definition: arch.h:74
#define REG_X86_DR3
Definition: arch_x86.h:108
#define REG_X86_EBP
Definition: arch_x86.h:42
#define REG_X86_CR4
Definition: arch_x86.h:103
#define REG_X86_SS
Definition: arch_x86.h:85
#define REG_X86_CR3
Definition: arch_x86.h:102
#define REG_X86_MSR_EFER
Definition: arch_x86.h:114
#define REG_X86_EAX
Definition: arch_x86.h:37
#define REG_X86_GS
Definition: arch_x86.h:88
#define REG_X86_ESP
Definition: arch_x86.h:41
#define REG_X86_DR1
Definition: arch_x86.h:106
#define REG_X86_EDX
Definition: arch_x86.h:39
#define REG_X86_EFLAGS
Definition: arch_x86.h:46
#define REG_X86_CS
Definition: arch_x86.h:84
struct arch arch_x86
Definition: arch_x86.c:79
#define REG_X86_DR0
Definition: arch_x86.h:105
#define REG_X86_EBX
Definition: arch_x86.h:40
#define REG_X86_DR6
Definition: arch_x86.h:111
#define REG_X86_EIP
Definition: arch_x86.h:45
#define REG_X86_CR2
Definition: arch_x86.h:101
#define REG_X86_DR7
Definition: arch_x86.h:112
#define ARCH_X86_REG_COUNT
Definition: arch_x86.h:34
Definition: arch.h:102
int8_t REG
Definition: common.h:93
#define COMMON_REG_COUNT
Definition: arch.h:80
Definition: arch.h:116
#define REG_X86_CR0
Definition: arch_x86.h:99
#define REG_X86_ESI
Definition: arch_x86.h:43
#define REG_X86_FS
Definition: arch_x86.h:87
#define ARCH_SNPRINTF_DETAIL_LEVELS
Definition: arch.h:114
Definition: arch.h:78
Definition: arch.h:75
Definition: arch.h:76