-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path103-python.c
More file actions
59 lines (48 loc) · 1.22 KB
/
103-python.c
File metadata and controls
59 lines (48 loc) · 1.22 KB
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
#include "/usr/include/python3.4/Python.h"
#include <stdio.h>
void print_hexn(const char *str, int n)
{
int i = 0;
for (; i < n - 1; ++i)
printf("%02x ", (unsigned char) str[i]);
printf("%02x", str[i]);
}
void print_python_bytes(PyObject *p)
{
PyBytesObject *clone = (PyBytesObject *) p;
int calc_bytes, clone_size = 0;
printf("[.] bytes object info\n");
if (PyBytes_Check(clone))
{
clone_size = PyBytes_Size(p);
calc_bytes = clone_size + 1;
if (calc_bytes >= 10)
calc_bytes = 10;
printf(" size: %d\n", clone_size);
printf(" trying string: %s\n", clone->ob_sval);
printf(" first %d bytes: ", calc_bytes);
print_hexn(clone->ob_sval, calc_bytes);
printf("\n");
}
else
{
printf(" [ERROR] Invalid Bytes Object\n");
}
}
void print_python_list(PyObject *p)
{
int i = 0, list_len = 0;
PyObject *item;
PyListObject *clone = (PyListObject *) p;
printf("[*] Python list info\n");
list_len = PyList_GET_SIZE(p);
printf("[*] Size of the Python List = %d\n", list_len);
printf("[*] Allocated = %d\n", (int) clone->allocated);
for (; i < list_len; ++i)
{
item = PyList_GET_ITEM(p, i);
printf("Element %d: %s\n", i, item->ob_type->tp_name);
if (PyBytes_Check(item))
print_python_bytes(item);
}
}