-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpython_wrapper.c
78 lines (65 loc) · 1.91 KB
/
python_wrapper.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
69
70
71
72
73
74
75
76
77
/*
* =====================================================================================
*
* Filename: python_wrapper.c
*
* Description: python module wrapper
*
* Version: 1.0
* Created: 05/10/2013 10:12:29 PM
* Revision: none
* Compiler: gcc
*
* Author: Reno
* Organization:
*
* =====================================================================================
*/
#include "python_wrapper.h"
PyObject *ATOSLError;
static PyObject *
symbolicate_wrapper(PyObject *self, PyObject *args)
{
const char *arch, *executable;
int result;
int numofaddresses;
PyObject* addresses_obj;
if (!PyArg_ParseTuple(args, "ssO", &arch, &executable, &addresses_obj)
|| !PyTuple_Check(addresses_obj))
return NULL;
numofaddresses = PyTuple_Size(addresses_obj);
char **addresses;
addresses = malloc(sizeof(char *)*numofaddresses);
int i = 0;
PyObject *address_item;
for (; i < numofaddresses; i++){
address_item = PyTuple_GetItem(addresses_obj, i);
if (PyString_Check(address_item)){
addresses[i] = PyString_AsString(address_item);
}else{
PyErr_SetString(ATOSLError, "tuple contains a non-string value.");
return NULL;
}
}
result = symbolicate(arch, executable, addresses, numofaddresses);
free(addresses);
if (result == -1){
return NULL;
}
return Py_BuildValue("i", result);
}
static PyMethodDef ATOSLMethods[] = {
{"symbolicate", symbolicate_wrapper, METH_VARARGS,
"binary address to symbol."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC initatosl(void)
{
PyObject *m;
m = Py_InitModule("atosl", ATOSLMethods);
if (m == NULL)
return;
ATOSLError = PyErr_NewException("atosl.error", NULL, NULL);
Py_INCREF(ATOSLError);
PyModule_AddObject(m, "error", ATOSLError);
}