-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path103-python.c
70 lines (58 loc) · 1.31 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <Python.h>
/**
* print_python_bytes - Prints bytes information
*
* @p: Python Object
* Return: no return
*/
void print_python_bytes(PyObject *p)
{
char *string;
long int size, i, limit;
printf("[.] bytes object info\n");
if (!PyBytes_Check(p))
{
printf(" [ERROR] Invalid Bytes Object\n");
return;
}
size = ((PyVarObject *)(p))->ob_size;
string = ((PyBytesObject *)p)->ob_sval;
printf(" size: %ld\n", size);
printf(" trying string: %s\n", string);
if (size >= 10)
limit = 10;
else
limit = size + 1;
printf(" first %ld bytes:", limit);
for (i = 0; i < limit; i++)
if (string[i] >= 0)
printf(" %02x", string[i]);
else
printf(" %02x", 256 + string[i]);
printf("\n");
}
/**
* print_python_list - Prints list information
*
* @p: Python Object
* Return: no return
*/
void print_python_list(PyObject *p)
{
long int size, i;
PyListObject *list;
PyObject *obj;
size = ((PyVarObject *)(p))->ob_size;
list = (PyListObject *)p;
printf("[*] Python list info\n");
printf("[*] Size of the Python List = %ld\n", size);
printf("[*] Allocated = %ld\n", list->allocated);
for (i = 0; i < size; i++)
{
obj = ((PyListObject *)p)->ob_item[i];
printf("Element %ld: %s\n", i, ((obj)->ob_type)->tp_name);
if (PyBytes_Check(obj))
print_python_bytes(obj);
}
}