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
|
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
#include <utility.h>
int
main (int argc, char *argv[])
{
FILE * fp;
unsigned char * elf_input;
unsigned int elf_input_size;
unsigned int mutations = 23;
if (argc != 3) {
fprintf (stderr, "usage: %s <in> <out>\n\n", argv[0]);
exit (EXIT_FAILURE);
}
fp = fopen (argv[1], "rb");
if (fp == NULL) {
perror ("fopen input");
exit (EXIT_FAILURE);
}
fseek (fp, 0, SEEK_END);
elf_input_size = ftell (fp);
elf_input = calloc (1, elf_input_size);
fseek (fp, 0, SEEK_SET);
fread (elf_input, 1, elf_input_size, fp);
fclose (fp);
be_randinit ();
while (mutations-- > 0) {
unsigned int * rptr;
rptr = (unsigned int *)
&elf_input[be_random (elf_input_size - 4)];
// printf ("0x%04x\n", ((unsigned char *) rptr) - elf_input);
switch (be_random (2)) {
case (0):
*rptr -= be_random (0x100);
break;
case (1):
*rptr = be_random (0xffffffff);
break;
default:
exit (EXIT_FAILURE);
}
}
elf_input_size += be_random (3);
fp = fopen (argv[2], "wb");
if (fp == NULL) {
perror ("fopen output");
exit (EXIT_FAILURE);
}
fwrite (elf_input, 1, elf_input_size, fp);
fclose (fp);
exit (EXIT_SUCCESS);
}
|