-
Notifications
You must be signed in to change notification settings - Fork 12
/
mangle.c
64 lines (40 loc) · 1.23 KB
/
mangle.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
#include "libcommon/common.h"
#include "mangle.h"
#include <inttypes.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include "libcommon/log.h"
#include "libcommon/util.h"
#include <Python.h>
static bool inited = false;
PyObject *genfunc;
void mangle_mangleContent(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
{
if (!inited) {
Py_SetProgramName("honggdharma");
Py_Initialize();
PyObject *sysmodule = PyImport_ImportModule("sys");
PyObject *syspath = PyObject_GetAttrString(sysmodule, "path");
PyList_Append(syspath, PyString_FromString("."));
Py_DECREF(syspath);
Py_DECREF(sysmodule);
PyObject *mod = PyImport_ImportModule("honggdharma");
if (mod != NULL) {
genfunc = PyObject_GetAttrString(mod, "generate");
} else {
printf("\nUnable to load honggdharma.py!\n");
exit(1);
}
inited = true;
}
char *tc = PyString_AsString(PyObject_CallObject(genfunc, NULL));
size_t len = strlen(tc);
if (len > (hfuzz->maxFileSz)) {
return;
}
fuzzer->dynamicFileSz = len + 1;
memmove(&fuzzer->dynamicFile[0], tc, len + 1);
}