summaryrefslogtreecommitdiff
path: root/plugins/pyoida/pyoida.c
blob: 82f9980802f602d804240e6c1202b4d5d36e434e (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

/* OpenIDA - Outil d'analyse de fichiers binaires
 * pyoida.c - plugin permettant des extensions en Python
 *
 * Copyright (C) 2009 Cyrille Bagard
 *
 *  This file is part of OpenIDA.
 *
 *  OpenIDA 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.
 *
 *  OpenIDA 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "pyoida.h"


#include <Python.h>


#include "analysis/module.h"
#include "arch/module.h"
#include "format/module.h"

/*
#include "analysis/py_binary.h"
#include "analysis/py_line.h"
#include "analysis/py_line_code.h"
#include "analysis/roptions.h"
*/
#include "plugin.h"
#include "py_log.h"
#include "../../src/common/environment.h"


#include "plugin.h"



static GObject *_ref = NULL;



static PyObject *pyoida_get_current_binary(PyObject *self, PyObject *args)
{
    GOpenidaBinary *binary;                 /* Structure à copier          */

    binary = (GOpenidaBinary *)g_object_get_data(_ref, "current_binary");

    return pybinary_new_from_existing(binary);

}

static PyMethodDef SpamMethods[] = {
    {"current_binary",  pyoida_get_current_binary, METH_NOARGS,
     "Give the current analyzed binary."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};






/******************************************************************************
*                                                                             *
*  Paramètres  : ref = espace de référencement global.                        *
*                                                                             *
*  Description : Initialise le greffon permettant l'usage de Python.          *
*                                                                             *
*  Retour      : true.                                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool init_plugin(GObject *ref)
{
    GPluginModule *plugin;
    int ret;

    printf("Init pyoida\n");

    _ref = ref;

    add_to_env_var("PYTHONPATH", "/home/ocb/prog/openida/plugins/python", ";");


    Py_Initialize();

    initpyoida();




    plugin = g_python_plugin_new("lnxsyscalls/lnxsyscalls");
    add_plugin_to_main_list(plugin);



#if 0

#if 0
    //main2("/home/ocb/prog/openida/plugins/pyoida/lnxsyscalls/lnxsyscalls.py", "get_instance");
    main2("lnxsyscalls", "get_instance");
#else
    //main2("/home/ocb/prog/openida/plugins/pyoida/lnxsyscalls/lnxsyscalls.py", "get_instance");
    main2("lnxsyscalls/lnxsyscalls", "get_instance");
#endif

#endif

    //Py_Finalize();

    //exit(-1);

    return true;

}


#if PY_VERSION_HEX >= 0x03000000

/* Python 3.x code */

static struct PyModuleDef spammodule = {
   PyModuleDef_HEAD_INIT,
   "pyoida",   /* name of module */
   "pyoida_doc", /* module documentation, may be NULL */
   -1,       /* size of per-interpreter state of the module,
                or -1 if the module keeps state in global variables. */
   SpamMethods
};

PyMODINIT_FUNC
PyInit_pyoida(void)
{
    printf("Passage 3\n");
    (void) PyModule_Create(&spammodule);
}

#else

/* Python 2.x code */

typedef struct {
	PyObject_HEAD
	PyObject *md_dict;
} PyModuleObject;


PyMODINIT_FUNC
initpyoida(void)
{
    PyObject *module;

    printf("Passage 2\n");
    module = Py_InitModule("pyoida", SpamMethods);

    //add_analysis_roptions_to_python_module(module);
    add_analysis_module_to_python_module(module);
    add_arch_module_to_python_module(module);
    add_format_module_to_python_module(module);

    add_log_to_python_module(module);
    add_plugin_to_python_module(module);

}

#endif