summaryrefslogtreecommitdiff
path: root/plugins/dex/python/pool.c
blob: 0c088653a466d22e3b429e42490f18610df26eff (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875

/* Chrysalide - Outil d'analyse de fichiers binaires
 * pool.c - équivalent Python du fichier "plugins/dex/pool.c"
 *
 * Copyright (C) 2019 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "pool.h"


#include <pygobject.h>


#include <plugins/pychrysalide/helpers.h>


#include "translate.h"
#include "../pool.h"



/* Reconstitue les éléments bruts d'un type Dex. */
static PyObject *py_dex_pool_get_raw_type(PyObject *, PyObject *);

/* Reconstitue les éléments bruts d'un champ Dex. */
static PyObject *py_dex_pool_get_raw_field(PyObject *, PyObject *);

/* Reconstitue les éléments bruts d'une routine Dex. */
static PyObject *py_dex_pool_get_raw_prototype(PyObject *, PyObject *);

/* Reconstitue les éléments bruts d'une méthode Dex. */
static PyObject *py_dex_pool_get_raw_method(PyObject *, PyObject *);

/* Reconstitue les éléments bruts d'une classe Dex. */
static PyObject *py_dex_pool_get_raw_class(PyObject *, PyObject *);

/* Fournit la liste de toutes les chaînes de la table globale. */
static PyObject *py_dex_pool_get_strings(PyObject *, void *);

/* Fournit la liste de tous les types de la table globale. */
static PyObject *py_dex_pool_get_types(PyObject *, void *);

/* Fournit la liste de tous les champs de la table globale. */
static PyObject *py_dex_pool_get_fields(PyObject *, void *);

/* Fournit la liste de tous les prototypes de la table globale. */
static PyObject *py_dex_pool_get_prototypes(PyObject *, void *);

/* Fournit la liste de toutes les méthodes de la table globale. */
static PyObject *py_dex_pool_get_methods(PyObject *, void *);

/* Fournit la liste de toutes les classes de la table globale. */
static PyObject *py_dex_pool_get_classes(PyObject *, void *);



#define DEX_POOL_DOC                                                    \
    "DexPool is the class collecting all resources of a Dex format."    \
    "\n"                                                                \
    "The pool is populated when the format gets analyzed."



/******************************************************************************
*                                                                             *
*  Paramètres  : self = objet représentant une table de ressources Dex.       *
*                args = arguments fournis pour l'opération.                   *
*                                                                             *
*  Description : Reconstitue les éléments bruts d'un type Dex.                *
*                                                                             *
*  Retour      : Instance mise en place.                                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_raw_type(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Bilan à retourner           */
    unsigned int index;                     /* Indice de l'élément visé    */
    int ret;                                /* Bilan de lecture des args.  */
    GDexPool *pool;                         /* Table de ressources Dex     */
    type_id_item type_id;                 /* Elément à transmettre       */
    bool status;                            /* Bilan de l'opération        */

#define DEX_POOL_GET_RAW_TYPE_METHOD PYTHON_METHOD_DEF                                      \
(                                                                                           \
    get_raw_type, "$self, index, /",                                                        \
    METH_VARARGS, py_dex_pool,                                                              \
    "Provide the raw data of a given type in the Dex pool as a pychrysalide.StructObject"   \
    " instance."                                                                            \
    "\n"                                                                                    \
    "Indexes start at 0.\n"                                                                 \
    "\n"                                                                                    \
    "All the fields are extracted from the Dex *type_id_item* structure:\n"                 \
    "* descriptor_idx: index into the string_ids list for the descriptor string.\n"         \
    "\n"                                                                                    \
    "In case of error, the function returns None."                                          \
)

    ret = PyArg_ParseTuple(args, "I", &index);
    if (!ret) return NULL;

    pool = G_DEX_POOL(pygobject_get(self));

    status = g_dex_pool_get_raw_type(pool, index, &type_id);

    if (status)
        result = translate_dex_type_id_to_python(&type_id);

    else
    {
        result = Py_None;
        Py_INCREF(result);
    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = objet représentant une table de ressources Dex.       *
*                args = arguments fournis pour l'opération.                   *
*                                                                             *
*  Description : Reconstitue les éléments bruts d'un champ Dex.               *
*                                                                             *
*  Retour      : Instance mise en place.                                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_raw_field(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Bilan à retourner           */
    unsigned int index;                     /* Indice de l'élément visé    */
    int ret;                                /* Bilan de lecture des args.  */
    GDexPool *pool;                         /* Table de ressources Dex     */
    field_id_item field_id;                 /* Elément à transmettre       */
    bool status;                            /* Bilan de l'opération        */

#define DEX_POOL_GET_RAW_FIELD_METHOD PYTHON_METHOD_DEF                                     \
(                                                                                           \
    get_raw_field, "$self, index, /",                                                       \
    METH_VARARGS, py_dex_pool,                                                              \
    "Provide the raw data of a given field in the Dex pool as a pychrysalide.StructObject"  \
    " instance."                                                                            \
    "\n"                                                                                    \
    "Indexes start at 0.\n"                                                                 \
    "\n"                                                                                    \
    "All the fields are extracted from the Dex *field_id_item* structure:\n"                \
    "* class_idx: index into the type_ids list for the definer of the field ;\n"            \
    "* type_idx: index into the type_ids list for the type of the field ;\n"                \
    "* name_idx: index into the string_ids list for the name of the field.\n"               \
    "\n"                                                                                    \
    "In case of error, the function returns None."                                          \
)

    ret = PyArg_ParseTuple(args, "I", &index);
    if (!ret) return NULL;

    pool = G_DEX_POOL(pygobject_get(self));

    status = g_dex_pool_get_raw_field(pool, index, &field_id);

    if (status)
        result = translate_dex_field_id_to_python(&field_id);

    else
    {
        result = Py_None;
        Py_INCREF(result);
    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = objet représentant une table de ressources Dex.       *
*                args = arguments fournis pour l'opération.                   *
*                                                                             *
*  Description : Reconstitue les éléments bruts d'une routine Dex.            *
*                                                                             *
*  Retour      : Instance mise en place.                                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_raw_prototype(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Bilan à retourner           */
    unsigned int index;                     /* Indice de l'élément visé    */
    int ret;                                /* Bilan de lecture des args.  */
    GDexPool *pool;                         /* Table de ressources Dex     */
    proto_id_item proto_id;                 /* Elément à transmettre       */
    bool status;                            /* Bilan de l'opération        */

#define DEX_POOL_GET_RAW_PROTOTYPE_METHOD PYTHON_METHOD_DEF                                     \
(                                                                                               \
    get_raw_prototype, "$self, index, /",                                                       \
    METH_VARARGS, py_dex_pool,                                                                  \
    "Provide the raw data of a given prototype in the Dex pool as a pychrysalide.StructObject"  \
    " instance."                                                                                \
    "\n"                                                                                        \
    "Indexes start at 0.\n"                                                                     \
    "\n"                                                                                        \
    "All the fields are extracted from the Dex *proto_id_item* structure:\n"                    \
    "* shorty_idx: index into the *string_ids* list for the short-form descriptor string ;\n"   \
    "* return_type_idx: index into the *type_ids* list for the return type ;\n"                 \
    "* parameters_off: offset from the start of the Dex file to the list of parameter types."   \
    "\n"                                                                                        \
    "In case of error, the function returns None."                                              \
)

    ret = PyArg_ParseTuple(args, "I", &index);
    if (!ret) return NULL;

    pool = G_DEX_POOL(pygobject_get(self));

    status = g_dex_pool_get_raw_prototype(pool, index, &proto_id);

    if (status)
        result = translate_dex_proto_id_to_python(&proto_id);

    else
    {
        result = Py_None;
        Py_INCREF(result);
    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = objet représentant une table de ressources Dex.       *
*                args = arguments fournis pour l'opération.                   *
*                                                                             *
*  Description : Reconstitue les éléments bruts d'une méthode Dex.            *
*                                                                             *
*  Retour      : Instance mise en place.                                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_raw_method(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Bilan à retourner           */
    unsigned int index;                     /* Indice de l'élément visé    */
    int ret;                                /* Bilan de lecture des args.  */
    GDexPool *pool;                         /* Table de ressources Dex     */
    method_id_item method_id;               /* Elément à transmettre       */
    bool status;                            /* Bilan de l'opération        */

#define DEX_POOL_GET_RAW_METHOD_METHOD PYTHON_METHOD_DEF                                    \
(                                                                                           \
    get_raw_method, "$self, index, /",                                                      \
    METH_VARARGS, py_dex_pool,                                                              \
    "Provide the raw data of a given method in the Dex pool as a pychrysalide.StructObject" \
    " instance."                                                                            \
    "\n"                                                                                    \
    "Indexes start at 0.\n"                                                                 \
    "\n"                                                                                    \
    "All the fields are extracted from the Dex *method_id_item* structure:\n"               \
    "* class_idx: index into the type_ids list for the definer of the method ;\n"           \
    "* proto_idx: index into the proto_ids list for the prototype of the method ;\n"        \
    "* name_idx: index into the string_ids list for the name of the method.\n"              \
    "\n"                                                                                    \
    "In case of error, the function returns None."                                          \
)

    ret = PyArg_ParseTuple(args, "I", &index);
    if (!ret) return NULL;

    pool = G_DEX_POOL(pygobject_get(self));

    status = g_dex_pool_get_raw_method(pool, index, &method_id);

    if (status)
        result = translate_dex_method_id_to_python(&method_id);

    else
    {
        result = Py_None;
        Py_INCREF(result);
    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = objet représentant une table de ressources Dex.       *
*                args = arguments fournis pour l'opération.                   *
*                                                                             *
*  Description : Reconstitue les éléments bruts d'une classe Dex.             *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_raw_class(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Bilan à retourner           */
    unsigned int index;                     /* Indice de l'élément visé    */
    int ret;                                /* Bilan de lecture des args.  */
    GDexPool *pool;                         /* Table de ressources Dex     */
    class_def_item class_def;               /* Elément à transmettre       */
    bool status;                            /* Bilan de l'opération        */

#define DEX_POOL_GET_RAW_CLASS_METHOD PYTHON_METHOD_DEF                                         \
(                                                                                               \
    get_raw_class, "$self, index, /",                                                           \
    METH_VARARGS, py_dex_pool,                                                                  \
    "Provide the raw data of a given class in the Dex pool as a pychrysalide.StructObject"      \
    " instance."                                                                                \
    "\n"                                                                                        \
    "Indexes start at 0.\n"                                                                     \
    "\n"                                                                                        \
    "All the fields are extracted from the Dex *class_def_item* structure:\n"                   \
    "* class_idx: index into the type_ids list for this class ;\n"                              \
    "* access_flags: access flags for the class (public, final, etc.) ;\n"                      \
    "* superclass_idx: index into the type_ids list for the superclass, or the constant value"  \
    " NO_INDEX if the class has no superclass ;\n"                                              \
    "* interfaces_off: offset from the start of the file to the list of interfaces, or 0"       \
    " if there are none ;\n"                                                                    \
    "* source_file_idx: index into the string_ids list for the name of the file containing"     \
    " the original source for (at least most of) this class, or the special value NO_INDEX to"  \
    " represent a lack of this information ;\n"                                                 \
    "* annotations_off: offset from the start of the file to the annotations structure, or 0"   \
    " if there are no annotation ;\n"                                                           \
    "* class_data_off: offset from the start of the file to the associated class data, or 0"    \
    " if there is no class data ;\n"                                                            \
    "* static_values_off: offset from the start of the file to the list of initial values"      \
    " for static fields, or 0 if there are none.\n"                                             \
    "\n"                                                                                        \
    "In case of error, the function returns None."                                              \
)

    ret = PyArg_ParseTuple(args, "I", &index);
    if (!ret) return NULL;

    pool = G_DEX_POOL(pygobject_get(self));

    status = g_dex_pool_get_raw_class(pool, index, &class_def);

    if (status)
        result = translate_dex_class_definition_to_python(&class_def);

    else
    {
        result = Py_None;
        Py_INCREF(result);
    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de toutes les chaînes de la table globale.  *
*                                                                             *
*  Retour      : Liste vide ou remplie de chaînes.                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_strings(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    uint32_t count;                         /* Nombre d'éléments à traiter */
    uint32_t i;                             /* Boucle de parcours          */
    const char *string;                     /* Chaîne à intégrer           */
    PyObject *str;                          /* Chaîne au format Python     */

#define DEX_POOL_STRINGS_ATTRIB PYTHON_GET_DEF_FULL                         \
(                                                                           \
    strings, py_dex_pool,                                                   \
    "Strings inside the Dex pool."                                          \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *string_id_item*"      \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_strings(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        string = g_dex_pool_get_string(pool, i, NULL, NULL);

        if (string == NULL)
        {
            str = Py_None;
            Py_INCREF(str);
        }

        else
            str = PyUnicode_FromString(string);

        PyTuple_SetItem(result, i, str);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de tous les types de la table globale.      *
*                                                                             *
*  Retour      : Liste vide ou remplie de types.                              *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_types(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    uint32_t count;                         /* Nombre d'éléments à traiter */
    uint32_t i;                             /* Boucle de parcours          */
    GDataType *type;                        /* Type à intégrer             */
    PyObject *tp;                           /* Type au format Python       */

#define DEX_POOL_TYPES_ATTRIB PYTHON_GET_DEF_FULL                           \
(                                                                           \
    types, py_dex_pool,                                                     \
    "Types inside the Dex pool."                                            \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *type_id_item*"        \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_types(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        type = g_dex_pool_get_type_(pool, i);

        if (type == NULL)
        {
            tp = Py_None;
            Py_INCREF(tp);
        }

        else
        {
            tp = pygobject_new(G_OBJECT(type));
            g_object_unref(type);
        }

        PyTuple_SetItem(result, i, tp);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de tous les champs de la table globale.     *
*                                                                             *
*  Retour      : Liste vide ou remplie de méthodes.                           *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_fields(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    uint32_t count;                         /* Nombre d'éléments à traiter */
    uint32_t i;                             /* Boucle de parcours          */
    GBinVariable *variable;                 /* Champ à intégrer            */
    PyObject *var;                          /* Champ au format Python      */

#define DEX_POOL_FIELDS_ATTRIB PYTHON_GET_DEF_FULL                          \
(                                                                           \
    fields, py_dex_pool,                                                    \
    "Fields inside the Dex pool."                                           \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *field_id_item*"       \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_fields(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        variable = g_dex_pool_get_field(pool, i);

        if (variable == NULL)
        {
            var = Py_None;
            Py_INCREF(var);
        }

        else
        {
            var = pygobject_new(G_OBJECT(variable));
            g_object_unref(variable);
        }

        PyTuple_SetItem(result, i, var);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de tous les prototypes de la table globale. *
*                                                                             *
*  Retour      : Liste vide ou remplie de méthodes.                           *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_prototypes(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    uint32_t count;                         /* Nombre d'éléments à traiter */
    uint32_t i;                             /* Boucle de parcours          */
    GBinRoutine *routine;                   /* Routine à intégrer          */
    PyObject *rtn;                          /* Routine au format Python    */

#define DEX_POOL_PROTOTYPES_ATTRIB PYTHON_GET_DEF_FULL                      \
(                                                                           \
    prototypes, py_dex_pool,                                                \
    "Prototypes inside the Dex pool."                                       \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *proto_id_item*"       \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_prototypes(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        routine = g_dex_pool_get_prototype(pool, i);

        if (routine == NULL)
        {
            rtn = Py_None;
            Py_INCREF(rtn);
        }

        else
        {
            rtn = pygobject_new(G_OBJECT(routine));
            g_object_unref(routine);
        }

        PyTuple_SetItem(result, i, rtn);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de toutes les méthodes de la table globale. *
*                                                                             *
*  Retour      : Liste vide ou remplie de méthodes.                           *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_methods(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    uint32_t count;                         /* Nombre d'éléments à traiter */
    uint32_t i;                             /* Boucle de parcours          */
    GDexMethod *method;                     /* Méthode à intégrer          */
    PyObject *meth;                         /* Méthode au format Python    */

#define DEX_POOL_METHODS_ATTRIB PYTHON_GET_DEF_FULL                         \
(                                                                           \
    methods, py_dex_pool,                                                   \
    "Methods inside the Dex pool."                                          \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *method_id_item*"      \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_methods(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        method = g_dex_pool_get_method(pool, i);

        if (method == NULL)
        {
            meth = Py_None;
            Py_INCREF(meth);
        }

        else
        {
            meth = pygobject_new(G_OBJECT(method));
            g_object_unref(method);
        }

        PyTuple_SetItem(result, i, meth);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                closure = non utilisé ici.                                   *
*                                                                             *
*  Description : Fournit la liste de toutes les classes de la table globale.  *
*                                                                             *
*  Retour      : Liste vide ou remplie de classes.                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_dex_pool_get_classes(PyObject *self, void *closure)
{
    PyObject *result;                       /* Valeur à retourner          */
    GDexPool *pool;                         /* Version native              */
    size_t count;                           /* Nombre d'éléments à traiter */
    size_t i;                               /* Boucle de parcours          */
    GDexClass *class;                       /* Classe du format à intégrer */

#define DEX_POOL_CLASSES_ATTRIB PYTHON_GET_DEF_FULL                         \
(                                                                           \
    classes, py_dex_pool,                                                   \
    "Classes inside the Dex pool."                                          \
    "\n"                                                                    \
    "These objects are the Chrysalide version of all *class_def_item*"      \
    " structures stored in the Dex format header."                          \
)

    pool = G_DEX_POOL(pygobject_get(self));

    count = g_dex_pool_count_classes(pool);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        class = g_dex_pool_get_class(pool, i);
        assert(class != NULL);

        PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(class)));

        g_object_unref(G_OBJECT(class));

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Fournit un accès à une définition de type à diffuser.        *
*                                                                             *
*  Retour      : Définition d'objet pour Python.                              *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

PyTypeObject *get_python_dex_pool_type(void)
{
    static PyMethodDef py_dex_pool_methods[] = {
        DEX_POOL_GET_RAW_TYPE_METHOD,
        DEX_POOL_GET_RAW_FIELD_METHOD,
        DEX_POOL_GET_RAW_PROTOTYPE_METHOD,
        DEX_POOL_GET_RAW_METHOD_METHOD,
        DEX_POOL_GET_RAW_CLASS_METHOD,
        { NULL }
    };

    static PyGetSetDef py_dex_pool_getseters[] = {
        DEX_POOL_STRINGS_ATTRIB,
        DEX_POOL_TYPES_ATTRIB,
        DEX_POOL_FIELDS_ATTRIB,
        DEX_POOL_METHODS_ATTRIB,
        DEX_POOL_PROTOTYPES_ATTRIB,
        DEX_POOL_CLASSES_ATTRIB,
        { NULL }
    };

    static PyTypeObject py_dex_pool_type = {

        PyVarObject_HEAD_INIT(NULL, 0)

        .tp_name        = "pychrysalide.format.dex.DexPool",
        .tp_basicsize   = sizeof(PyGObject),

        .tp_flags       = Py_TPFLAGS_DEFAULT,

        .tp_doc         = DEX_POOL_DOC,

        .tp_methods     = py_dex_pool_methods,
        .tp_getset      = py_dex_pool_getseters

    };

    return &py_dex_pool_type;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : module = module dont la définition est à compléter.          *
*                                                                             *
*  Description : Prend en charge l'objet 'pychrysalide.format.dex.DexPool'.   *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool register_python_dex_pool(PyObject *module)
{
    PyTypeObject *type;                     /* Type Python 'DexPool'       */
    PyObject *dict;                         /* Dictionnaire du module      */

    type = get_python_dex_pool_type();

    dict = PyModule_GetDict(module);

    if (!register_class_for_pygobject(dict, G_TYPE_DEX_POOL, type))
        return false;

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : arg = argument quelconque à tenter de convertir.             *
*                dst = destination des valeurs récupérées en cas de succès.   *
*                                                                             *
*  Description : Tente de convertir en table de ressources pour format Dex.   *
*                                                                             *
*  Retour      : Bilan de l'opération, voire indications supplémentaires.     *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

int convert_to_dex_pool(PyObject *arg, void *dst)
{
    int result;                             /* Bilan à retourner           */

    result = PyObject_IsInstance(arg, (PyObject *)get_python_dex_pool_type());

    switch (result)
    {
        case -1:
            /* L'exception est déjà fixée par Python */
            result = 0;
            break;

        case 0:
            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to loaded binary");
            break;

        case 1:
            *((GDexPool **)dst) = G_DEX_POOL(pygobject_get(arg));
            break;

        default:
            assert(false);
            break;

    }

    return result;

}