-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix.c
69 lines (64 loc) · 1.61 KB
/
prefix.c
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "prefix.h"
#include "opcode.h"
void check_prefix(unsigned char * inst, struct prefixes * prfx){
assert(inst != NULL);
switch(inst[0]){
case PREFIX_LOCK:
prfx->LOCK = 1;
break;
case PREFIX_REPN: // BND shares this same prefix number
prfx->REPN = 1;
break;
case PREFIX_REP:
prfx->REP = 1;
break;
case PREFIX_CS: // BRANCHN shares prefix
prfx->CS = 1;
break;
case PREFIX_SS:
prfx->SS = 1;
break;
case PREFIX_DS: // BRANCH shares prefix
prfx->DS = 1;
break;
case PREFIX_ES:
prfx->ES = 1;
break;
case PREFIX_FS:
prfx->FS = 1;
break;
case PREFIX_GS:
prfx->GS = 1;
break;
case PREFIX_OP_SIZE_OVERRIDE:
prfx->OPERAND_OVERRIDE = 1;
break;
case PREFIX_ADDR_SIZE_OVERRIDE:
prfx->ADDRESS_OVERRIDE = 1;
break;
default:
check_rex(inst, prfx);
return;
}
check_prefix(&inst[1], prfx);
return;
}
void check_rex(unsigned char * inst, struct prefixes * prfx){
assert(inst != NULL);
if((inst[0] & 0xf0) == REX_PREFIX){ // Clear last 4 bits
prfx->REX = inst[0];
check_opcode(&inst[1], prfx);
}
else{
check_opcode(inst, prfx);
}
return;
}
void check_vex_C4(unsigned char * inst){
printf("WE HAVE A VEX");
assert(0);
return;
}