summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch/instruction.c
blob: 9e676d27e890664638996a5bb51fb323cc4f0266 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * instruction.c - équivalent Python du fichier "arch/instruction.h"
 *
 * Copyright (C) 2012-2017 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 "instruction.h"


#include <assert.h>
#include <pygobject.h>


#include <arch/instruction.h>


#include "vmpa.h"
#include "../helpers.h"




/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */





/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */



/* Fournit la place mémoire d'une instruction. */
static PyObject *py_arch_instruction_get_range(PyObject *, void *);

/* Définit la localisation d'une instruction. */
static int py_arch_instruction_set_range(PyObject *, PyObject *, void *);



/* Fournit le nom humain de l'instruction manipulée. */
static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);












/* ---------------------------------------------------------------------------------- */
/*                     DEFINITION DES LIAISONS ENTRE INSTRUCTIONS                     */
/* ---------------------------------------------------------------------------------- */




/* Fournit les origines d'une instruction donnée. */
static PyObject *py_arch_instruction_get_sources(PyObject *, PyObject *);

/* Fournit les destinations d'une instruction donnée. */
static PyObject *py_arch_instruction_get_destinations(PyObject *, PyObject *);




/******************************************************************************
*                                                                             *
*  Paramètres  : self = instruction d'architecture à manipuler.               *
*                args = liste d'arguments non utilisée ici.                   *
*                                                                             *
*  Description : Fournit les origines d'une instruction donnée.               *
*                                                                             *
*  Retour      : Nombre de ces origines.                                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_sources(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Instance à retourner        */
    GArchInstruction *instr;                /* Version native              */
    instr_link_t *sources;                  /* Origine des liens           */
    size_t count;                           /* Nombre de liens présents    */
    size_t i;                               /* Boucle de parcours          */
    PyObject *dest;                         /* Destination de lien Python  */
    PyObject *type;                         /* Nature du lien en Python    */
    int ret;                                /* Bilan d'une écriture d'arg. */

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));

    count = g_arch_instruction_get_sources(instr, &sources);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        dest = pygobject_new(G_OBJECT(sources[i].linked));
        type = PyLong_FromLong(sources[i].type);

        ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", dest, type));
        assert(ret == 0);

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = instruction d'architecture à manipuler.               *
*                args = liste d'arguments non utilisée ici.                   *
*                                                                             *
*  Description : Fournit les destinations d'une instruction donnée.           *
*                                                                             *
*  Retour      : Nombre de ces destinations.                                  *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_destinations(PyObject *self, PyObject *args)
{
    PyObject *result;                       /* Instance à retourner        */
    GArchInstruction *instr;                /* Version native              */
    instr_link_t *dests;                    /* Destination des liens       */
    size_t count;                           /* Nombre de liens présents    */
    size_t i;                               /* Boucle de parcours          */
    PyObject *dest;                         /* Destination de lien Python  */
    PyObject *type;                         /* Nature du lien en Python    */
    int ret;                                /* Bilan d'une écriture d'arg. */

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));

    count = g_arch_instruction_get_destinations(instr, &dests);

    result = PyTuple_New(count);

    for (i = 0; i < count; i++)
    {
        dest = pygobject_new(G_OBJECT(dests[i].linked));
        type = PyLong_FromLong(dests[i].type);

        ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", dest, type));
        assert(ret == 0);

    }

    return result;

}












/******************************************************************************
*                                                                             *
*  Paramètres  : self    = classe représentant une instruction.               *
*                closure = adresse non utilisée ici.                          *
*                                                                             *
*  Description : Fournit la place mémoire d'une instruction.                  *
*                                                                             *
*  Retour      : Valeur associée à la propriété consultée.                    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure)
{
    PyObject *result;                       /* Conversion à retourner      */
    GArchInstruction *instr;                /* Version native              */
    const mrange_t *range;                  /* Espace mémoire à exporter   */

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));
    range = g_arch_instruction_get_range(instr);

    result = build_from_internal_mrange(range);

    return result;

}

/******************************************************************************
*                                                                             *
*  Paramètres  : self    = objet Python concerné par l'appel.                 *
*                value   = valeur fournie à intégrer ou prendre en compte.    *
*                closure = adresse non utilisée ici.                          *
*                                                                             *
*  Description : Définit la localisation d'une instruction.                   *
*                                                                             *
*  Retour      : Bilan de l'opération pour Python.                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static int py_arch_instruction_set_range(PyObject *self, PyObject *value, void *closure)
{
    int ret;                                /* Bilan d'analyse             */
    mrange_t *range;                        /* Espace mémoire à manipuler  */
    GArchInstruction *instr;                /* Version native              */

    ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type());
    if (!ret) return -1;

    range = get_internal_mrange(value);

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));
    g_arch_instruction_set_range(instr, range);

    return 0;

}







/******************************************************************************
*                                                                             *
*  Paramètres  : self   = classe représentant une instruction.                *
*                unused = adresse non utilisée ici.                           *
*                                                                             *
*  Description : Fournit le nom humain de l'instruction manipulée.            *
*                                                                             *
*  Retour      : Valeur associée à la propriété consultée.                    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused)
{
    PyObject *result;                       /* Trouvailles à retourner     */
    GArchInstruction *instr;                /* Version native              */
    const char *kw;                         /* Valeur récupérée            */

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));
    kw = g_arch_instruction_get_keyword(instr, 0/* FIXME*/);

    result = PyUnicode_FromString(kw);

    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_arch_instruction_type(void)
{
    static PyMethodDef py_arch_instruction_methods[] = {
        { "get_sources", py_arch_instruction_get_sources,
          METH_NOARGS,
          "get_sources(, /)\n--\n\nProvide the instructions list driving to the current instruction."
        },
        { "get_destinations", py_arch_instruction_get_destinations,
          METH_NOARGS,
          "get_destinations(, /)\n--\n\nProvide the instructions list following the current instruction."
        },
        { NULL }
    };

    static PyGetSetDef py_arch_instruction_getseters[] = {
        {
            "range", py_arch_instruction_get_range, py_arch_instruction_set_range,
            "Give access to the memory range covered by the current instruction.", NULL
        },
        {
            "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL,
            "Give le name of the assembly instruction.", NULL
        },
        { NULL }
    };

    static PyTypeObject py_arch_instruction_type = {

        PyVarObject_HEAD_INIT(NULL, 0)

        .tp_name        = "pychrysalide.arch.ArchInstruction",
        .tp_basicsize   = sizeof(PyGObject),

        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE,

        .tp_doc         = "PyChrysalide instruction for a given architecture.",

        .tp_methods     = py_arch_instruction_methods,
        .tp_getset      = py_arch_instruction_getseters,

    };

    return &py_arch_instruction_type;

}


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

bool register_python_arch_instruction(PyObject *module)
{
    PyTypeObject *py_arch_instruction_type; /* Type Python 'BinContent'    */
    PyObject *dict;                         /* Dictionnaire du module      */

    py_arch_instruction_type = get_python_arch_instruction_type();

    APPLY_ABSTRACT_FLAG(py_arch_instruction_type);

    dict = PyModule_GetDict(module);

    if (!register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type, &PyGObject_Type))
        return false;

    return true;

}







#if 0


#include <pygobject.h>
#include <stdbool.h>
#include <string.h>


#include <arch/instruction.h>


#include "../quirks.h"



/* --------------------- ITERATEUR POUR BOUCLE SUR INSTRUCTIONS --------------------- */


/* Itérateur pour les instructions */
typedef struct _PyArchInstructionIter
{
    PyObject_HEAD                           /* A laisser en premier        */

    GArchInstruction *head;                 /* Ancrage supposé             */
    PyObject *current;                      /* Départ, puis parcours...    */
    bool started;                           /* Démarrage effectué ?        */

} PyArchInstructionIter;


/* Prépare l'itérateur pour un parcours d'instructions. */
static PyObject *py_arch_instruction_iterator_create(PyObject *);

/* Libère la mémoire d'un itérateur de 'ArchInstruction'. */
static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *);

/* Fournit l'élément suivant dans un parcours d'instructions. */
static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *);



/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */


/* Crée un nouvel objet Python de type 'ArchInstruction'. */
static PyObject *py_arch_instruction_new(PyTypeObject *, PyObject *, PyObject *);

/* Prépare un parcours d'instructions. */
static PyObject *py_arch_instruction_get_iter(PyObject *);

/* Fournit la valeur associée à une propriété donnée. */
static PyObject *py_arch_instruction_get_location(PyObject *, char *);

/* Fournit le nom humain de l'instruction manipulée. */
static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);



/* ---------------------------------------------------------------------------------- */
/*                       ITERATEUR POUR BOUCLE SUR INSTRUCTIONS                       */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : origin = élément à l'origine du parcours.                    *
*                                                                             *
*  Description : Prépare l'itérateur pour un parcours d'instructions.         *
*                                                                             *
*  Retour      : Instance d'itérateur prête à emploi.                         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
{
    PyArchInstructionIter *result;          /* Nouvelle instance à renvoyer*/
    PyObject *module;                       /* Module d'appartenance       */
    PyTypeObject *type;                     /* Type d'objet à créer        */

    module = PyImport_ImportModule("pychrysalide.arch");
    type = (PyTypeObject *)PyObject_GetAttrString(module, "ArchInstructionIterator");
    Py_DECREF(module);

    result = (PyArchInstructionIter *)type->tp_alloc(type, 0);
    Py_DECREF(type);

    if (result != NULL)
    {
        Py_INCREF(origin);
        result->head = G_ARCH_INSTRUCTION(pygobject_get(origin));
        g_object_ref(G_OBJECT(result->head));

        result->current = origin;
    }

    return (PyObject *)result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = instance d'objet à supprimer.                         *
*                                                                             *
*  Description : Libère la mémoire d'un itérateur de 'ArchInstruction'.       *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *self)
{
    PyObject *first;                        /* Récupération de la première */

    first = pygobject_new(G_OBJECT(self->head));

    Py_DECREF(first);
    g_object_unref(G_OBJECT(self->head));

#if PY_VERSION_HEX < 0x03000000
    self->ob_type->tp_free((PyObject *)self);
#else
    Py_TYPE(self)->tp_free((PyObject *)self);
#endif

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = instance manipulée à traiter.                         *
*                                                                             *
*  Description : Fournit l'élément suivant dans un parcours d'instructions.   *
*                                                                             *
*  Retour      : Point suivant du parcours ou NULL.                           *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
{
    PyObject *result;                       /* Elément à retourner         */
    GArchInstruction *next;                 /* Elément réel suivant        */

    if (!self->started)
    {
        self->started = true;
        result = self->current;
        Py_INCREF(result);

    }
    else
    {
        next = G_ARCH_INSTRUCTION(pygobject_get(self->current));
        next = g_arch_instruction_get_next_iter(self->head, next, VMPA_MAX);

        if (next != NULL)
        {
            result = pygobject_new(G_OBJECT(next));
            self->current = result;
        }
        else result = NULL;

    }

    Py_XINCREF(result);
    return (PyObject *)result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : module = module dont la définition est à compléter.          *
*                                                                             *
*  Description : Permet une itération de 'pychrysalide.arch.ArchInstruction'. *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool register_python_arch_instruction_iterator(PyObject *module)
{
    int ret;                                /* Bilan d'un appel            */

    static PyTypeObject py_arch_instruction_iterator_type = {

        PyObject_HEAD_INIT(NULL)

        .tp_name        = "pychrysalide.arch.ArchInstructionIterator",
        .tp_basicsize   = sizeof(PyArchInstructionIter),

        .tp_dealloc     = (destructor)py_arch_instruction_iterator_dealloc,

        //.tp_flags       = Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS,

        .tp_doc         = "PyChrysalide architecture instruction iterator",

        .tp_iter        = PyObject_SelfIter,
        .tp_iternext    = (iternextfunc)py_arch_instruction_iterator_next

    };

    if (PyType_Ready(&py_arch_instruction_iterator_type) < 0)
        return false;

    Py_INCREF(&py_arch_instruction_iterator_type);
    ret = PyModule_AddObject(module, "ArchInstructionIterator", (PyObject *)&py_arch_instruction_iterator_type);

    return (ret == 0);

}



/* ---------------------------------------------------------------------------------- */
/*                       INSTRUCTIONS D'ARCHITECTURES EN PYTHON                       */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : type = type de l'objet à instancier.                         *
*                args = arguments fournis à l'appel.                          *
*                kwds = arguments de type key=val fournis.                    *
*                                                                             *
*  Description : Crée un nouvel objet Python de type 'ArchInstruction'.       *
*                                                                             *
*  Retour      : Instance Python mise en place.                               *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    Py_RETURN_NONE;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = instance manipulée à traiter.                         *
*                                                                             *
*  Description : Prépare un parcours d'instructions.                          *
*                                                                             *
*  Retour      : Point de départ d'un parcours.                               *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_iter(PyObject *self)
{
    return py_arch_instruction_iterator_create(self);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : self = classe représentant une instruction.                  *
*                name = nom de la propriété à lire.                           *
*                                                                             *
*  Description : Fournit la valeur associée à une propriété donnée.           *
*                                                                             *
*  Retour      : Valeur associée à la propriété consultée.                    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
{
    PyObject *result;                       /* Trouvailles à retourner     */
    GArchInstruction *instr;                /* Version native              */
    off_t offset;                           /* Position dans le fichier    */
    off_t length;                           /* Taille de l'instruction     */
    vmpa_t address;                         /* Position en mémoire         */

    instr = G_ARCH_INSTRUCTION(pygobject_get(self));
    g_arch_instruction_get_location(instr, &offset, &length, &address);

    if (strcmp(name, "offset") == 0)
        result = PyLong_FromLong(offset);

    else if (strcmp(name, "length") == 0)
        result = PyLong_FromLong(length);

    else if (strcmp(name, "address") == 0)
        result = PyLong_FromLongLong(address);

    else
        result = NULL;

    return result;

}



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

bool register_python_arch_instruction(PyObject *module)
{
    PyObject *pygobj_mod;                   /* Module Python-GObject       */
    int ret;                                /* Bilan d'un appel            */

    static PyMethodDef py_arch_instruction_methods[] = {
        { NULL }
    };

    static PyGetSetDef py_arch_instruction_getseters[] = {
        {
            "offset", (getter)py_arch_instruction_get_location, (setter)NULL,
            "Provide the location of the instruction in the binary file.", "offset"
        },
        {
            "length", (getter)py_arch_instruction_get_location, (setter)NULL,
            "Provide the length of the instruction.", "length"
        },
        {
            "address", (getter)py_arch_instruction_get_location, (setter)NULL,
            "Provide the location of the instruction in memory.", "address"
        },
        {
            "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL,
            "Give le name of the assembly instruction.", NULL
        },
        { NULL }
    };

    static PyTypeObject py_arch_instruction_type = {

        PyObject_HEAD_INIT(NULL)

        .tp_name        = "pychrysalide.arch.ArchInstruction",
        .tp_basicsize   = sizeof(PyGObject),

        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,

        .tp_doc         = "PyChrysalide architecture instruction",

        .tp_methods     = py_arch_instruction_methods,
        .tp_getset      = py_arch_instruction_getseters,
        .tp_new         = (newfunc)py_arch_instruction_new,

        .tp_iter        = (getiterfunc)py_arch_instruction_get_iter

    };

    pygobj_mod = PyImport_ImportModule("gobject");
    if (pygobj_mod == NULL) return false;

    py_arch_instruction_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
    Py_DECREF(pygobj_mod);

    if (PyType_Ready(&py_arch_instruction_type) < 0)
        return false;

    Py_INCREF(&py_arch_instruction_type);
    ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)&py_arch_instruction_type);

    register_class_for_pygobject(module, "GArchInstruction", G_TYPE_ARCH_INSTRUCTION,
                             &py_arch_instruction_type,
                             Py_BuildValue("(O)", py_arch_instruction_type.tp_base));

    return (ret == 0);

}


#endif