summaryrefslogtreecommitdiff
path: root/other/burneye2/morph.h
blob: 2f88e546667285452fbf99525d24f14f4819e938 (plain)
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
/* morph.h - burneye code morphing functionality, include file
 *
 * by scut
 */

#ifndef	MORPH_H
#define	MORPH_H

#define	MORPH_VERSION	"0.0.1"


typedef struct {
	ia32_function **	flist;
	unsigned int		flist_count;

	ia32_function *		func;
	ia32_bblock *		bblock;
} morph;


/* morph_abstract
 *
 * move all functions and bblockes to extra allocated memory blocks.
 *
 * return number of bytes allocated
 */

unsigned int
morph_abstract (morph *mr);


/* morph_br_extend
 *
 * extend the current morphed bblock in `mr' by `len' bytes at its end.
 *
 * XXX: note that the last extended bytes are set to nop (0x90), hence you have
 *	to modify them directly afterwards, else further bblock morphing
 *	operations will not work.
 * return in any case
 */

void
morph_br_extend (morph *mr, int len);


/* morph_br_fix
 *
 * fix the current bblock of `mr' within the function `func' to correct all
 * bblock mappings (i.e. convert abstract bblock pointers to instruction level)
 *
 * return in any case
 */

void
morph_br_fix (morph *mr, ia32_function *func);


/* morph_func_sort
 *
 * sort the function list array within `mr' by virtual start addresses
 *
 * return in any case
 */

void
morph_func_sort (morph *mr);


/* morph_br_sort
 *
 * sort bblock array `brlist', which is `br_len' items long by the virtual
 * start address
 *
 * return in any case
 */

void
morph_br_sort (ia32_bblock **brlist, unsigned int br_len);


/* morph_displ_boundcheck
 *
 * check whether the displacement value `displ_val' will fit into an
 * instruction displacement encoding of `displ_size' bits.
 *
 * return 0 if it does fit
 * return 1 if it is out of bounds
 */

int
morph_displ_boundcheck (int displ_val, unsigned int displ_size);

#endif