-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path103-python.c
executable file
·49 lines (43 loc) · 1.18 KB
/
103-python.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
#include <Python.h>
#include <object.h>
#include <listobject.h>
#include <bytesobject.h>
void print_python_bytes(PyObject *p)
{
long int size;
int i;
char *trying_str = NULL;
printf("[.] bytes object info\n");
if (!PyBytes_Check(p))
{
printf(" [ERROR] Invalid Bytes Object\n");
return;
}
PyBytes_AsStringAndSize(p, &trying_str, &size);
printf(" size: %li\n", size);
printf(" trying string: %s\n", trying_str);
if (size < 10)
printf(" first %li bytes:", size + 1);
else
printf(" first 10 bytes:");
for (i = 0; i <= size && i < 10; i++)
printf(" %02hhx", trying_str[i]);
printf("\n");
}
void print_python_list(PyObject *p)
{
long int size = PyList_Size(p);
int i;
PyListObject *list = (PyListObject *)p;
const char *type;
printf("[*] Python list info\n");
printf("[*] Size of the Python List = %li\n", size);
printf("[*] Allocated = %li\n", list->allocated);
for (i = 0; i < size; i++)
{
type = (list->ob_item[i])->ob_type->tp_name;
printf("Element %i: %s\n", i, type);
if (!strcmp(type, "bytes"))
print_python_bytes(list->ob_item[i]);
}
}