-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand_format.h
134 lines (115 loc) · 3.99 KB
/
command_format.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//@ @\\
//@ _ _ _ _ _ _ _ @\\
//@ /\ \ /\ \ / /\ / /\ / /\ /\_\/\_\ _ @\\
//@ / \ \____ \ \ \ / / \ / / \ / / \ / / / / //\_\ @\\
//@ / /\ \_____\ /\ \_\ / / /\ \__ / / /\ \ / / /\ \__ /\ \/ \ \/ / / @\\
//@ / / /\/___ / / /\/_/ / / /\ \___\ / / /\ \ \ / / /\ \___\ / \____\__/ / @\\
//@ / / / / / / / / / \ \ \ \/___// / / \ \ \ \ \ \ \/___// /\/________/ @\\
//@ / / / / / / / / / \ \ \ / / /___/ /\ \ \ \ \ / / /\/_// / / @\\
//@ / / / / / / / / / _ \ \ \ / / /_____/ /\ \ _ \ \ \ / / / / / / @\\
//@ \ \ \__/ / /___/ / /__ /_/\__/ / / / /_________/\ \ \ /_/\__/ / / / / / / / / @\\
//@ \ \___\/ //\__\/_/___\\ \/___/ / / / /_ __\ \_\\ \/___/ / \/_/ / / / @\\
//@ \/_____/ \/_________/ \_____\/ \_\___\ /____/_/ \_____\/ \/_/ @\\
//@ @\\
//@ @\\
//@ DisASM @\\
//@ @ Vlad Salnikov (XXXRef), 2013 @\\
//@ xxxref.com @\\
//@ @\\
#include <stdio.h>
//TODO change char -> TYPE_BYTE
typedef struct {
char scale;
char index;
char base;
unsigned char sib;
} SIB;
typedef struct {
char mod;
char reg;
char rm;
unsigned char modrm;// HEX view of modrm
} MODRM;
typedef struct {
unsigned bit0:1;//TODO: implement as bit field?
unsigned bit1:1;
unsigned bit2:1;
unsigned bit3:1;
unsigned bit4:1;
unsigned bit5:1;
unsigned bit6:1;
unsigned bit7:1;
}SByte;
typedef union{
char byte;
SByte ubyte;
} UByte;
typedef struct {
unsigned char bytenum;
unsigned char*hex_bytes;//array of command bytes
char*bytes;//binary view
} OPCODE;
typedef struct {
unsigned char prefixcount;//number of prefixes
unsigned char*p;//pointer to prefix array
unsigned char lnr;//lock and repeat prefixes-f0, f2, f3
unsigned char segr;//segment redefinition prefixes-2e, 36,3e,26,64,65
unsigned char opr;//operand size redefenition prefix-66
unsigned char sr;//address size redefenition prefix-67
} PREFIX;
typedef struct {
char w;
char s;
char d;
char reg;
char tttn;
char eee;//special purpose registers
char uuu;//sreg3 (3 bits)
char ff;//sreg2 (2 bits)
}SPECIALFIELDS;
typedef struct {
PREFIX prefix;
OPCODE opcode;
SPECIALFIELDS sf;
MODRM modrm;
SIB sib;
char*com_text;
char**parameters;
char*par;
int par_count;
} SCommand;
void SCommandInit(SCommand*command){
int i=0;
command->prefix.prefixcount=0;
command->prefix.p=NULL;
command->prefix.lnr=255; //TODO values in hex representation
command->prefix.segr=255;
command->prefix.opr=255;
command->prefix.sr=255;
command->opcode.bytenum=0;
command->opcode.bytes=(char*)malloc(25); //24 bits + 0
for(;i<25;i++){
command->opcode.bytes[i]=0;
}
command->opcode.hex_bytes=(char*)malloc(3);
command->sf.w=-128;
command->sf.s=-128;
command->sf.d=-128;
command->sf.uuu=-128;
command->sf.ff=-128;
command->sf.reg=-128;
command->sf.eee=-128;
command->sf.tttn=-128;
command->modrm.mod=-128;
command->modrm.reg=-128;
command->modrm.rm=-128;
command->sib.scale=-128;
command->sib.index=-128;
command->sib.base=-128;
command->sib.sib=255;
command->com_text=NULL;
command->parameters=NULL;
command->par=NULL;
command->par_count=0;
return;
}