From b9977e00ff9eb6e025e86a15c858183f3f314cf5 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 25 Apr 2009 16:51:41 +0000 Subject: Saved the current work on plugins. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@59 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 128 +++++ Makefile.am | 2 +- configure.ac | 31 +- src/Makefile.am | 37 +- src/analysis/Makefile.am | 11 +- src/analysis/binary.c | 593 ++++++++++++++++++++++ src/analysis/binary.h | 73 +++ src/analysis/line.c | 13 +- src/arch/Makefile.am | 9 +- src/arch/processor.c | 64 +-- src/arch/processor.h | 4 + src/arch/x86/processor.c | 3 +- src/binary.c | 596 ---------------------- src/binary.h | 73 --- src/common/Makefile.am | 6 +- src/common/extstr.c | 55 ++ src/common/extstr.h | 3 + src/debug/debuggers.h | 2 +- src/debug/ptrace/options.h | 2 +- src/dlg_sections.c | 2 +- src/easygtk.c | 538 -------------------- src/easygtk.h | 80 --- src/editor.c | 24 +- src/format/Makefile.am | 11 +- src/format/dwarf/Makefile.am | 6 +- src/format/elf/Makefile.am | 8 +- src/format/elf/e_elf.c | 6 +- src/format/java/Makefile.am | 6 +- src/format/mangling/Makefile.am | 6 +- src/format/pe/Makefile.am | 6 +- src/gtkext/Makefile.am | 11 +- src/gtkext/easygtk.c | 538 ++++++++++++++++++++ src/gtkext/easygtk.h | 80 +++ src/gtkext/gtkdockpanel.c | 6 +- src/gtkext/gtksnippet.c | 26 +- src/gtkext/support.c | 92 ++++ src/gtkext/support.h | 41 ++ src/panel/Makefile.am | 7 +- src/panel/log.c | 10 +- src/panel/registers.c | 2 +- src/plugins/Makefile.am | 17 + src/plugins/pglist.c | 73 +++ src/plugins/pglist.h | 39 ++ src/plugins/plugin.c | 144 ++++++ src/plugins/plugin.h | 56 +++ src/plugins/pyoida/Makefile.am | 20 + src/plugins/pyoida/linsyscalls/oidapgi.py | 28 ++ src/plugins/pyoida/py_binary.c | 358 +++++++++++++ src/plugins/pyoida/py_binary.h | 45 ++ src/plugins/pyoida/py_line.c | 802 ++++++++++++++++++++++++++++++ src/plugins/pyoida/py_line.h | 45 ++ src/plugins/pyoida/py_log.c | 341 +++++++++++++ src/plugins/pyoida/py_log.h | 39 ++ src/plugins/pyoida/pyoida.c | 131 +++++ src/plugins/pyoida/pyoida.h | 38 ++ src/project.c | 2 +- src/project.h | 2 +- src/shell.c | 330 ++++++++++++ src/shell.h | 38 ++ src/support.c | 92 ---- src/support.h | 41 -- 61 files changed, 4315 insertions(+), 1577 deletions(-) create mode 100644 src/analysis/binary.c create mode 100644 src/analysis/binary.h delete mode 100644 src/binary.c delete mode 100644 src/binary.h delete mode 100644 src/easygtk.c delete mode 100644 src/easygtk.h create mode 100644 src/gtkext/easygtk.c create mode 100644 src/gtkext/easygtk.h create mode 100644 src/gtkext/support.c create mode 100644 src/gtkext/support.h create mode 100644 src/plugins/Makefile.am create mode 100644 src/plugins/pglist.c create mode 100644 src/plugins/pglist.h create mode 100644 src/plugins/plugin.c create mode 100644 src/plugins/plugin.h create mode 100644 src/plugins/pyoida/Makefile.am create mode 100755 src/plugins/pyoida/linsyscalls/oidapgi.py create mode 100644 src/plugins/pyoida/py_binary.c create mode 100644 src/plugins/pyoida/py_binary.h create mode 100644 src/plugins/pyoida/py_line.c create mode 100644 src/plugins/pyoida/py_line.h create mode 100644 src/plugins/pyoida/py_log.c create mode 100644 src/plugins/pyoida/py_log.h create mode 100644 src/plugins/pyoida/pyoida.c create mode 100644 src/plugins/pyoida/pyoida.h create mode 100644 src/shell.c create mode 100644 src/shell.h delete mode 100644 src/support.c delete mode 100644 src/support.h diff --git a/ChangeLog b/ChangeLog index 53f81ef..ab90144 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,131 @@ +2009-04-25 Cyrille Bagard + + * configure.ac: + Add depedencies for Python and libvte. Add the new Makefiles from the + 'src/plugins' and 'src/plugins/pyoida' directories to AC_CONFIG_FILES. + + * Makefile.am: + Remove binary.[ch], easygtk.[ch] and support.[ch] from openida_SOURCES. + Fix INCLUDES and use the new shared libraries. + + * src/analysis/binary.c: + * src/analysis/binary.h: + New entries : move these files from .. ; update the call to get a processor. + + * src/analysis/line.c: + Remove the depedency the editor widget (need to be fixed). + + * src/analysis/Makefile.am: + Add binary.[ch] to libanalysis_la_SOURCES. Build a shared library. + + * src/arch/Makefile.am: + Build a shared library instead of an archive. + + * src/arch/processor.c: + * src/arch/processor.h: + Disable some debugging output. Provide a quick way to get a (X86) processor. + + * src/arch/x86/processor.c: + Replace escape_crlf_bin_string() by escape_crlf(). + + * src/binary.c: + * src/binary.h: + Moved entries. + + * src/common/extstr.c: + * src/common/extstr.h: + Add a function to escape carriage return/line feed characters. + + * src/common/Makefile.am: + Build a shared library instead of an archive. + + * src/debug/debuggers.h: + * src/debug/ptrace/options.h: + * src/dlg_sections.c: + Update includes. + + * src/easygtk.c: + * src/easygtk.h: + Moved entries. + + * src/editor.c: + Update code: calls, menus and tabs. + + * src/format/dwarf/Makefile.am: + Build a shared library instead of an archive. + + * src/format/elf/e_elf.c: + Update the call to escape_crlf_bin_string()/escape_crlf(). + + * src/format/elf/Makefile.am: + * src/format/java/Makefile.am: + Build a shared library instead of an archive. + + * src/format/Makefile.am: + * src/format/mangling/Makefile.am: + * src/format/pe/Makefile.am: + Build a shared library instead of an archive. + + * src/gtkext/easygtk.c: + Update GTK calls: replace the old gtk_widget_unref() calls by the new + g_object_unref() ones. + + * src/gtkext/gtkdockpanel.c: + Disable some debugging output. + + * src/gtkext/gtksnippet.c: + Use the G_DEFINE_TYPE macro. + + * src/gtkext/Makefile.am: + Add support.[ch] to libgtkext_la_SOURCES. Build a shared library. + + * src/gtkext/support.c: + * src/gtkext/support.h: + New entries : move these files from ... + + * src/Makefile.am: + * src/panel/log.c: + Typo. + + * src/panel/Makefile.am: + Build a shared library instead of an archive. + + * src/panel/registers.c: + Update includes. + + * src/plugins/Makefile.am: + * src/plugins/pglist.c: + * src/plugins/pglist.h: + * src/plugins/plugin.c: + * src/plugins/plugin.h: + New entries : code first steps to manage plugins using GModule. + + * src/plugins/pyoida/linsyscalls/oidapgi.py: + New entries : make a basic/dummy version of a Python plugin. + + * src/plugins/pyoida/Makefile.am: + * src/plugins/pyoida/py_binary.c: + * src/plugins/pyoida/py_binary.h: + * src/plugins/pyoida/py_line.c: + * src/plugins/pyoida/py_line.h: + * src/plugins/pyoida/py_log.c: + * src/plugins/pyoida/py_log.h: + * src/plugins/pyoida/pyoida.c: + * src/plugins/pyoida/pyoida.h: + New entries : allow some items of OpenIDA to be accessed from Python. + + * src/project.c: + * src/project.h: + Update includes. + + * src/shell.c: + * src/shell.h: + New entries: provide a terminal to play with Python. + + * src/support.c: + * src/support.h: + Moved entries. + 2009-04-12 Cyrille Bagard * configure.ac: diff --git a/Makefile.am b/Makefile.am index dedd688..ea7183a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -EXTRA_DIST = config.rpath config.rpath ChangeLog +EXTRA_DIST = config.rpath config.rpath config.rpath ChangeLog SUBDIRS = pixmaps src diff --git a/configure.ac b/configure.ac index 775e50d..4a4adf2 100644 --- a/configure.ac +++ b/configure.ac @@ -149,7 +149,8 @@ AC_SUBST(WARNING_FLAGS) # _XOPEN_SOURCE: strdup, snprintf # _ISOC99_SOURCE: INFINITY; NAN -COMPLIANCE_FLAGS="-D_GNU_SOURCE" +# GTK_DISABLE_DEPRECATED: on reste conforme au C99 +COMPLIANCE_FLAGS="-D_GNU_SOURCE -DGTK_DISABLE_DEPRECATED" AC_SUBST(COMPLIANCE_FLAGS) @@ -181,6 +182,30 @@ AC_SUBST(LIBXML_CFLAGS) AC_SUBST(LIBXML_LIBS) +#--- Checks for Python + +LIBPYTHON_CFLAGS=`python-config --cflags` +LIBPYTHON_LIBS=`python-config --libs` + +AC_SUBST(LIBPYTHON_CFLAGS) +AC_SUBST(LIBPYTHON_LIBS) + + +#--- Checks for libvte + +PKG_CHECK_MODULES(LIBVTE,vte >= 0.16.14,[libvte_found=yes],[libvte_found=no]) + +if test "$libvte_found" = "yes"; then + libvte_version=`pkg-config vte --modversion` +else + libvte_version='-' +fi + +AC_SUBST(LIBVTE_CFLAGS) +AC_SUBST(LIBVTE_LIBS) + + + ############################################################ # Outputting files ############################################################ @@ -205,7 +230,9 @@ AC_CONFIG_FILES([Makefile src/format/mangling/Makefile src/format/pe/Makefile src/gtkext/Makefile - src/panel/Makefile]) + src/panel/Makefile + src/plugins/Makefile + src/plugins/pyoida/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index da52127..fa63b43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,43 +2,46 @@ bin_PROGRAMS=openida openida_SOURCES = \ - binary.h binary.c \ dlg_sections.h dlg_sections.c \ - easygtk.h easygtk.c \ editor.c \ pan_strings.h pan_strings.c \ pan_symbols.h pan_symbols.c \ project.h project.c \ - support.h support.c \ + shell.h shell.c \ xdg.h xdg.c \ xml.h xml.c -INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/intl $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) `pkg-config --cflags gthread-2.0` +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/intl $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) `pkg-config --cflags gthread-2.0` $(LIBPYTHON_CFLAGS) $(LIBVTE_CFLAGS) AM_CPPFLAGS = AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl -lm $(LIBXML_LIBS) `pkg-config --libs gthread-2.0` +openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl -lm $(LIBXML_LIBS) `pkg-config --libs gthread-2.0` $(LIBPYTHON_LIBS) $(LIBVTE_LIBS) \ + -Larch/.libs -larch \ + -Lcommon/.libs -lcommon \ + -Lpanel/.libs -lpanel \ + -Lgtkext/.libs -lgtkext \ + -Lanalysis/.libs -lanalysis \ + -Lformat/.libs -lformat \ + -Lformat/dwarf/.libs -lformatdwarf \ + -Lformat/elf/.libs -lformatelf \ + -Lformat/java/.libs -lformatjava \ + -Lformat/mangling/.libs -lformatmangling \ + -Lformat/pe/.libs -lformatpe openida_LDADD = $(LIBINTL) \ - arch/libarch.a \ - arch/x86/libarchx86.a \ debug/libdebug.a \ debug/ptrace/libdebugptrace.a \ - format/libformat.a \ - format/dwarf/libformatdwarf.a \ - format/elf/libformatelf.a \ - format/java/libformatjava.a \ - format/mangling/libformatmangling.a \ - format/pe/libformatpe.a \ - gtkext/libgtkext.a \ - panel/libpanel.a \ - analysis/libanalysis.a \ + plugins/libplugins.a \ + plugins/pyoida/libpyoida.a \ common/libcommon.a -SUBDIRS = analysis arch common debug format gtkext panel +# gtkext doit être traité en premier, à cause des marshals GLib +# common doit être passé avant analysis + +SUBDIRS = arch format common analysis debug gtkext panel plugins diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am index e5f7689..8d986a1 100755 --- a/src/analysis/Makefile.am +++ b/src/analysis/Makefile.am @@ -1,7 +1,8 @@ -lib_LIBRARIES = libanalysis.a +lib_LTLIBRARIES = libanalysis.la -libanalysis_a_SOURCES = \ +libanalysis_la_SOURCES = \ + binary.h binary.c \ line.h line.c \ line-int.h \ line_code.h line_code.c \ @@ -10,10 +11,12 @@ libanalysis_a_SOURCES = \ prototype.h prototype.c \ variable.h variable.c -libanalysis_a_CFLAGS = $(AM_CFLAGS) +libanalysis_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) \ + -L../common/.libs -lcommon \ + -L../format/.libs -lformat -INCLUDES = $(LIBGTK_CFLAGS) +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) AM_CPPFLAGS = diff --git a/src/analysis/binary.c b/src/analysis/binary.c new file mode 100644 index 0000000..95b24b1 --- /dev/null +++ b/src/analysis/binary.c @@ -0,0 +1,593 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * binary.c - traitement des flots de code binaire + * + * Copyright (C) 2008 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 . + */ + + +#include "binary.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "line_code.h" +#include "line_comment.h" +#include "line_prologue.h" +#include "prototype.h" +#include "../arch/processor.h" + + +#include "../format/dbg_format.h" +#include "../format/exe_format.h" + + + + +#ifndef _ +# define _(str) str +#endif + + + +extern bool find_line_info(const uint8_t *content, off_t *size); + + + + +/* Description d'un fichier binaire */ +struct _openida_binary +{ + char *filename; /* Fichier chargé en mémoire */ + + off_t bin_length; /* Taille des données brutes */ + uint8_t *bin_data; /* Données binaires brutes */ + + exe_format *format; /* Format du binaire */ + asm_processor *proc; /* Architecture du binaire */ + + GRenderingLine *lines; /* Lignes de rendu en place */ + disass_options options; /* Options de désassemblage */ + +}; + + +/* Charge en mémoire le contenu d'un fichier à partir d'XML. */ +openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr); + +/* Charge en mémoire le contenu d'un fichier. */ +uint8_t *map_binary_file(const char *, off_t *); + +/* Construit la description d'introduction du désassemblage. */ +GRenderingLine *build_binary_prologue(const char *, const uint8_t *, off_t); + +/* Procède au désassemblage basique d'un contenu binaire. */ +void disassemble_openida_binary(openida_binary *); + + + +/****************************************************************************** +* * +* Paramètres : filename = nom du fichier à charger. * +* * +* Description : Charge en mémoire le contenu d'un fichier. * +* * +* Retour : Adresse de la représentation ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +openida_binary *load_binary_file(const char *filename) +{ + openida_binary *result; /* Adresse à retourner */ + + result = (openida_binary *)calloc(1, sizeof(openida_binary)); + + result->filename = strdup(filename); + + result->bin_data = map_binary_file(filename, &result->bin_length); + if (result->bin_data == NULL) goto lbf_error; + + result->format = load_new_exe_format(result->bin_data, result->bin_length); + if (result->format == NULL) goto lbf_error; + + + result->proc = create_processor(); + + + result->options.show_address = true; + result->options.show_code = true; + + result->options.format = result->format; + result->options.proc = result->proc; + + disassemble_openida_binary(result); + + return result; + + lbf_error: + + unload_binary_file(result); + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : xpathObj = point de lecture de tous les éléments. * +* * +* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. * +* * +* Retour : Adresse de la représentation ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr xpathObj) +{ + openida_binary *result; /* Adresse à retourner */ + + int i; + + result = (openida_binary *)calloc(1, sizeof(openida_binary)); + + for (i = 0; i < XPATH_OBJ_NODES_COUNT(xpathObj); i++) + if (xmlStrEqual(NODE_FROM_PATH_OBJ(xpathObj, i)->name, BAD_CAST "Filename")) + result->filename = qck_get_node_text_value(NODE_FROM_PATH_OBJ(xpathObj, i)); + + + + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à supprimer de la mémoire. * +* * +* Description : Décharge de la mémoire le contenu d'un fichier. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void unload_binary_file(openida_binary *binary) +{ + free(binary->filename); + + free(binary); + +} + + +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à consulter. * +* * +* Description : Fournit le fichier correspondant à l'élément binaire. * +* * +* Retour : Nom de fichier avec chemin absolu. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *openida_binary_get_filename(const openida_binary *binary) +{ + return binary->filename; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à consulter. * +* * +* Description : Fournit une description humaine d'un élément binaire. * +* * +* Retour : Chaîne de caractères humainenement lisible de représentation.* +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *openida_binary_to_string(const openida_binary *binary) +{ + return binary->filename; + +} + + + + +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à consulter. * +* * +* Description : Fournit les lignes de rendu issues du désassemblage. * +* * +* Retour : Lignes issues du désassemblage. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GRenderingLine *get_openida_binary_lines(const openida_binary *binary) +{ + return binary->lines; + +} + + + + + + +/****************************************************************************** +* * +* Paramètres : xpathCtx = contexte à utiliser pour mener les parcours. * +* base = première partie de l'expression XPath d'accès. * +* index = indice de la élément dans la liste des voisins. * +* * +* Description : Lit un élément binaire depuis un fichier XML. * +* * +* Retour : Représentation mise en place à libérer de la mémoire. * +* * +* Remarques : - * +* * +******************************************************************************/ + +openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr xpathCtx, const char *base, unsigned int index) +{ + openida_binary *result; /* Représentation à retourner */ + size_t expr_len; /* Taille d'une expression */ + char *expr; /* Chemin XPath reconstitué */ + xmlXPathObjectPtr xpathObj; /* Cible d'une recherche */ + char *value; /* Type d'élément rencontré */ + size_t sub_expr_len; /* Taille d'une expression #2 */ + char *sub_expr; /* Chemin XPath reconstitué #2 */ + int i; /* Boucle de parcours */ + + result = NULL; + + /* S'occupe en premier lieu du niveau courant */ + + expr_len = strlen(base) + strlen("/*[position()=") + strlen("4294967295") /* UINT_MAX */ + strlen("]") + 1; + + expr = (char *)calloc(expr_len, sizeof(char)); + snprintf(expr, expr_len, "%s/*[position()=%u]", base, index); + + xpathObj = get_node_xpath_object(xpathCtx, expr); + + value = qck_get_node_prop_value(NODE_FROM_PATH_OBJ(xpathObj, 0), "type"); + + xmlXPathFreeObject(xpathObj); + + if (value == NULL) goto robfx_err1; + + /* Raffinement au second passage */ + + sub_expr_len = expr_len + strlen("/*"); + sub_expr = (char *)calloc(sub_expr_len, sizeof(char)); + snprintf(sub_expr, sub_expr_len, "%s/*", expr); + + xpathObj = get_node_xpath_object(xpathCtx, sub_expr); + + if (strcmp(value, "file") == 0) result = load_binary_file_from_xml(xpathObj); + + xmlXPathFreeObject(xpathObj); + + free(sub_expr); + + robfx_err1: + + free(expr); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à traiter. * +* writer = rédacteur dédié à l'écriture. * +* * +* Description : Ecrit une sauvegarde du binaire dans un fichier XML. * +* * +* Retour : true si l'opération a bien tourné, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool write_openida_binary_to_xml(const openida_binary *binary, xmlTextWriterPtr writer) +{ + bool result; /* Bilan à faire remonter */ + + result = open_xml_element(writer, "Binary"); + + result &= write_xml_attribute(writer, "type", "file"); + + result &= write_xml_element_with_content(writer, "Filename", "%s", binary->filename); + + result &= close_xml_element(writer); + + return result; + +} + + + + + +/****************************************************************************** +* * +* Paramètres : filename = nom du fichier à charger. * +* length = taille des données mises en mémoire. [OUT] * +* * +* Description : Charge en mémoire le contenu d'un fichier. * +* * +* Retour : Adresse du contenu binaire ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +uint8_t *map_binary_file(const char *filename, off_t *length) +{ + uint8_t *result; /* Données à retourner */ + int fd; /* Fichier ouvert en lecture */ + struct stat info; /* Informations sur le fichier */ + int ret; /* Bilan d'un appel */ + + fd = open(filename, 0, O_RDONLY); + if (fd == -1) + { + perror("open()"); + return NULL; + } + + ret = fstat(fd, &info); + if (ret == -1) + { + perror("fstat()"); + close(fd); + return NULL; + } + + *length = info.st_size; + + result = (uint8_t *)mmap(NULL, *length, PROT_READ, MAP_PRIVATE, fd, 0); + if (result == MAP_FAILED) + { + perror("mmap()"); + result = NULL; + } + + ret = close(fd); + if (ret == -1) + perror("close()"); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : filename = nom du fichier chargé. * +* data = données en mémoire pour l'empreinte. * +* length = quantité de données à prendre en compte. * +* * +* Description : Construit la description d'introduction du désassemblage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +GRenderingLine *build_binary_prologue(const char *filename, const uint8_t *data, off_t length) +{ + GRenderingLine *result; /* Contenu à renvoyer */ + size_t len; /* Taille du texte */ + char *content; /* Contenu textuel d'une ligne */ + GRenderingLine *line; /* Représentation à ajouter */ + GChecksum *checksum; /* Calcul de l'empreinte */ + const gchar *hex; /* Valeur hexadécimale du SHA */ + + result = NULL;/* FIXME DL_LIST_HEAD_INIT( **/ + + line = g_prologue_line_new("Disassembly generated by OpenIDA"); + g_rendering_line_add_to_lines(&result, line); + + line = g_prologue_line_new("OpenIDA is free software - © 2008-2009 Cyrille Bagard"); + g_rendering_line_add_to_lines(&result, line); + + line = g_prologue_line_new(""); + g_rendering_line_add_to_lines(&result, line); + + /* Fichier */ + + len = strlen(_("File: ")) + strlen(filename); + content = (char *)calloc(len + 1, sizeof(char)); + + snprintf(content, len + 1, "%s%s", _("File: "), filename); + + line = g_prologue_line_new(content); + g_rendering_line_add_to_lines(&result, line); + + free(content); + + /* Checksum SHA256 */ + + checksum = g_checksum_new(G_CHECKSUM_SHA256); + + g_checksum_update(checksum, data, length); + hex = g_checksum_get_string(checksum); + + len = strlen(_("Sha256: ")) + strlen(hex); + content = (char *)calloc(len + 1, sizeof(char)); + + snprintf(content, len + 1, "%s%s", _("Sha256: "), hex); + + g_checksum_free(checksum); + + line = g_prologue_line_new(content); + g_rendering_line_add_to_lines(&result, line); + + free(content); + + line = g_prologue_line_new(""); + g_rendering_line_add_to_lines(&result, line); + + line = g_prologue_line_new(""); + g_rendering_line_add_to_lines(&result, line); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = binaire dont le contenu est à analyser. * +* * +* Description : Procède au désassemblage basique d'un contenu binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void disassemble_openida_binary(openida_binary *binary) +{ + asm_instr *instr; + + bin_routine **routines; /* Liste des routines trouvées */ + size_t routines_count; /* Nombre de ces routines */ + + bin_part **parts; + size_t parts_count; + + + + GRenderingLine *line; + + + off_t start; + off_t pos; + off_t len; + + uint64_t base = 0; + uint64_t offset = 0; + + size_t i; + + size_t k; + + uint64_t routine_offset; /* Point de départ de routine */ + char *routine_desc; /* Prototype d'une routine */ + + + + + binary->lines = build_binary_prologue(binary->filename, binary->bin_data, binary->bin_length); + + + routines = get_all_exe_routines(binary->format, &routines_count); + + + parts = get_elf_default_code_parts(binary->format, &parts_count); + qsort(parts, parts_count, sizeof(bin_part *), compare_bin_parts); + + + + + for (i = 0; i < parts_count; i++) + { + get_bin_part_values(parts[i], &pos, &len, &base); + + /* Décodage des instructions */ + + start = pos; + pos = 0; + + while (pos < len) + { + offset = base + pos; + + + instr = decode_instruction(binary->proc, &binary->bin_data[start], &pos, len, start, offset); + + + line = g_code_line_new(offset, instr, &binary->options); + g_rendering_line_add_to_lines(&binary->lines, line); + + } + + /* Ajout des prototypes de fonctions */ + + for (k = 0; k < routines_count; k++) + { + routine_offset = get_binary_routine_offset(routines[k]); + + if (!(base <= routine_offset && routine_offset < (base + len))) continue; + + routine_desc = routine_to_string(routines[k]); + + line = g_comment_line_new(routine_offset, routine_desc, &binary->options); + g_rendering_line_insert_into_lines(&binary->lines, line, true); + + free(routine_desc); + + } + + } + + + + + + + line = g_rendering_line_find_by_offset(binary->lines, get_exe_entry_point(binary->format)); + g_rendering_line_add_flag(line, RLF_ENTRY_POINT); + + + + +} diff --git a/src/analysis/binary.h b/src/analysis/binary.h new file mode 100644 index 0000000..69da2a7 --- /dev/null +++ b/src/analysis/binary.h @@ -0,0 +1,73 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * binary.h - prototypes pour le traitement des flots de code binaire + * + * Copyright (C) 2008 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 . + */ + + +#ifndef _BINARY_H +#define _BINARY_H + + +#include + + +#include "line.h" +#include "../xml.h" + + + +/* Description d'un fichier binaire */ +typedef struct _openida_binary openida_binary; + + +/* Charge en mémoire le contenu d'un fichier. */ +openida_binary *load_binary_file(const char *); + +/* Décharge de la mémoire le contenu d'un fichier. */ +void unload_binary_file(openida_binary *); + +/* Fournit une description humaine d'un élément binaire. */ +const char *openida_binary_to_string(const openida_binary *); + +/* Fournit le fichier correspondant à l'élément binaire. */ +const char *openida_binary_get_filename(const openida_binary *); + +/* Fournit les lignes de rendu issues du désassemblage. */ +GRenderingLine *get_openida_binary_lines(const openida_binary *); + + + +/* Lit un élément binaire depuis un fichier XML. */ +openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr, const char *, unsigned int); + +/* Ecrit une sauvegarde du binaire dans un fichier. */ +bool write_openida_binary_to_xml(const openida_binary *, xmlTextWriterPtr); + + + + + + + + + + + +#endif /* _BINARY_H */ diff --git a/src/analysis/line.c b/src/analysis/line.c index 4fc0ac5..bba601c 100644 --- a/src/analysis/line.c +++ b/src/analysis/line.c @@ -39,7 +39,7 @@ /* FIXME */ -extern GtkWidget *mywid; +//extern GtkWidget *mywid; @@ -96,9 +96,15 @@ static void g_rendering_line_class_init(GRenderingLineClass *klass) static void g_rendering_line_init(GRenderingLine *line) { + GdkScreen *screen; + PangoContext *context; + DL_LIST_ITEM_INIT(&line->link); - line->layout = gtk_widget_create_pango_layout(mywid, NULL); + screen = gdk_screen_get_default(); + context = gdk_pango_context_get_for_screen(screen); + + line->layout = pango_layout_new(context); line->get_bin_len = NULL; line->refresh_markup = NULL; @@ -230,6 +236,7 @@ RenderingLineFlag g_rendering_line_get_flags(const GRenderingLine *line) void g_rendering_line_draw(GRenderingLine *line, GdkDrawable *drawable, GdkGC *gc, gint x0, gint x1, gint y, gint h) { +#if 0 GdkPixbuf *pixbuf; /* Données utiles au dessin */ gdk_draw_layout(drawable, gc, x1, y, line->layout); @@ -268,7 +275,7 @@ void g_rendering_line_draw(GRenderingLine *line, GdkDrawable *drawable, GdkGC *g g_object_unref(pixbuf); } - +#endif } diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am index 2f7f072..ad5e3c6 100644 --- a/src/arch/Makefile.am +++ b/src/arch/Makefile.am @@ -1,7 +1,7 @@ -lib_LIBRARIES = libarch.a +lib_LTLIBRARIES = libarch.la -libarch_a_SOURCES = \ +libarch_la_SOURCES = \ instruction-int.h \ instruction.h instruction.c \ operand-int.h \ @@ -9,7 +9,10 @@ libarch_a_SOURCES = \ processor-int.h \ processor.h processor.c -libarch_a_CFLAGS = $(AM_CFLAGS) +libarch_la_LIBADD = \ + x86/libarchx86.a + +libarch_la_LDFLAGS = INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/arch/processor.c b/src/arch/processor.c index d367949..a67986d 100644 --- a/src/arch/processor.c +++ b/src/arch/processor.c @@ -24,16 +24,21 @@ #include "processor.h" -#include -#include #include "instruction-int.h" #include "processor-int.h" +#include "x86/processor.h" +asm_processor *create_processor(void) +{ + return create_x86_processor(); + +} + /****************************************************************************** @@ -72,7 +77,7 @@ asm_instr *decode_instruction(const asm_processor *proc, const uint8_t *data, of { *pos = old_pos; - printf("err while decoding opcode 0x%02hhx at 0x%08llx\n", data[*pos], offset); + //printf("err while decoding opcode 0x%02hhx at 0x%08llx\n", data[*pos], offset); result = create_db_instruction(data, pos, len); } @@ -88,59 +93,6 @@ asm_instr *decode_instruction(const asm_processor *proc, const uint8_t *data, of } -/****************************************************************************** -* * -* Paramètres : input = chaîne de caractères à traiter. * -* * -* Description : S'assure qu'une chaîne de caractère tient sur une ligne. * -* * -* Retour : Adresse de la chaîne de caractères modifiée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -char *escape_crlf_bin_string(char *input) -{ - size_t inlen; - regex_t preg; - int ret; - size_t curpos; - regmatch_t pmatch[2]; - - inlen = strlen(input); - - ret = regcomp(&preg, "(\t|\n|\r)", REG_EXTENDED | REG_ICASE); - /* TODO: ret */ - - for (curpos = 0; regexec(&preg, &input[curpos], 2, pmatch, 0) != REG_NOMATCH; ) - { - inlen += 1 + 1; - input = (char *)realloc(input, inlen * sizeof(char *)); - - memmove(&input[curpos + pmatch[1].rm_eo + 1], &input[curpos + pmatch[1].rm_eo], inlen - 1 - curpos - pmatch[1].rm_eo); - - switch (input[curpos + pmatch[1].rm_so]) - { - case '\t': - memcpy(&input[curpos + pmatch[1].rm_so], "\\t", 2); - break; - case '\n': - memcpy(&input[curpos + pmatch[1].rm_so], "\\n", 2); - break; - case '\r': - memcpy(&input[curpos + pmatch[1].rm_so], "\\r", 2); - break; - } - - curpos += pmatch[1].rm_eo + 1; - - } - - return input; - -} - /****************************************************************************** * * diff --git a/src/arch/processor.h b/src/arch/processor.h index 343a98c..6c65e95 100644 --- a/src/arch/processor.h +++ b/src/arch/processor.h @@ -53,6 +53,10 @@ typedef struct _asm_processor asm_processor; +asm_processor *create_processor(void); + + + /* Décode une instruction dans un flux de données. */ asm_instr *decode_instruction(const asm_processor *, const uint8_t *, off_t *, off_t, off_t, uint64_t); diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index 15d26a4..b6f5c30 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -32,6 +32,7 @@ #include "instruction.h" #include "opcodes.h" #include "operand.h" +#include "../../common/extstr.h" @@ -517,7 +518,7 @@ void x86_print_instruction(const asm_x86_processor *proc, const exe_format *form break; case STP_STRING: - label = escape_crlf_bin_string(label); + label = escape_crlf(label); snprintf(&opbuffer[i][oplen], 256 - oplen, " \"%s\"", label); break; diff --git a/src/binary.c b/src/binary.c deleted file mode 100644 index 85196d9..0000000 --- a/src/binary.c +++ /dev/null @@ -1,596 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.c - traitement des flots de code binaire - * - * Copyright (C) 2008 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 . - */ - - -#include "binary.h" - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "analysis/line_code.h" -#include "analysis/line_comment.h" -#include "analysis/line_prologue.h" -#include "analysis/prototype.h" -#include "arch/processor.h" - - -#include "format/dbg_format.h" -#include "format/exe_format.h" - - - - -#ifndef _ -# define _(str) str -#endif - - - -extern bool find_line_info(const uint8_t *content, off_t *size); - - - - -/* Description d'un fichier binaire */ -struct _openida_binary -{ - char *filename; /* Fichier chargé en mémoire */ - - off_t bin_length; /* Taille des données brutes */ - uint8_t *bin_data; /* Données binaires brutes */ - - exe_format *format; /* Format du binaire */ - asm_processor *proc; /* Architecture du binaire */ - - GRenderingLine *lines; /* Lignes de rendu en place */ - disass_options options; /* Options de désassemblage */ - -}; - - -/* Charge en mémoire le contenu d'un fichier à partir d'XML. */ -openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr); - -/* Charge en mémoire le contenu d'un fichier. */ -uint8_t *map_binary_file(const char *, off_t *); - -/* Construit la description d'introduction du désassemblage. */ -GRenderingLine *build_binary_prologue(const char *, const uint8_t *, off_t); - -/* Procède au désassemblage basique d'un contenu binaire. */ -void disassemble_openida_binary(openida_binary *); - - - -/****************************************************************************** -* * -* Paramètres : filename = nom du fichier à charger. * -* * -* Description : Charge en mémoire le contenu d'un fichier. * -* * -* Retour : Adresse de la représentation ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -openida_binary *load_binary_file(const char *filename) -{ - openida_binary *result; /* Adresse à retourner */ - - result = (openida_binary *)calloc(1, sizeof(openida_binary)); - - result->filename = strdup(filename); - - result->bin_data = map_binary_file(filename, &result->bin_length); - if (result->bin_data == NULL) goto lbf_error; - - result->format = load_new_exe_format(result->bin_data, result->bin_length); - if (result->format == NULL) goto lbf_error; - - - result->proc = create_x86_processor(); - - - result->options.show_address = true; - result->options.show_code = true; - - result->options.format = result->format; - result->options.proc = result->proc; - - disassemble_openida_binary(result); - - return result; - - lbf_error: - - unload_binary_file(result); - - return NULL; - -} - - -/****************************************************************************** -* * -* Paramètres : xpathObj = point de lecture de tous les éléments. * -* * -* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. * -* * -* Retour : Adresse de la représentation ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr xpathObj) -{ - openida_binary *result; /* Adresse à retourner */ - - int i; - - result = (openida_binary *)calloc(1, sizeof(openida_binary)); - - for (i = 0; i < XPATH_OBJ_NODES_COUNT(xpathObj); i++) - if (xmlStrEqual(NODE_FROM_PATH_OBJ(xpathObj, i)->name, BAD_CAST "Filename")) - result->filename = qck_get_node_text_value(NODE_FROM_PATH_OBJ(xpathObj, i)); - - - - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à supprimer de la mémoire. * -* * -* Description : Décharge de la mémoire le contenu d'un fichier. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void unload_binary_file(openida_binary *binary) -{ - free(binary->filename); - - free(binary); - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à consulter. * -* * -* Description : Fournit le fichier correspondant à l'élément binaire. * -* * -* Retour : Nom de fichier avec chemin absolu. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const char *openida_binary_get_filename(const openida_binary *binary) -{ - return binary->filename; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à consulter. * -* * -* Description : Fournit une description humaine d'un élément binaire. * -* * -* Retour : Chaîne de caractères humainenement lisible de représentation.* -* * -* Remarques : - * -* * -******************************************************************************/ - -const char *openida_binary_to_string(const openida_binary *binary) -{ - return binary->filename; - -} - - - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à consulter. * -* * -* Description : Fournit les lignes de rendu issues du désassemblage. * -* * -* Retour : Lignes issues du désassemblage. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GRenderingLine *get_openida_binary_lines(const openida_binary *binary) -{ - return binary->lines; - -} - - - - - - -/****************************************************************************** -* * -* Paramètres : xpathCtx = contexte à utiliser pour mener les parcours. * -* base = première partie de l'expression XPath d'accès. * -* index = indice de la élément dans la liste des voisins. * -* * -* Description : Lit un élément binaire depuis un fichier XML. * -* * -* Retour : Représentation mise en place à libérer de la mémoire. * -* * -* Remarques : - * -* * -******************************************************************************/ - -openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr xpathCtx, const char *base, unsigned int index) -{ - openida_binary *result; /* Représentation à retourner */ - size_t expr_len; /* Taille d'une expression */ - char *expr; /* Chemin XPath reconstitué */ - xmlXPathObjectPtr xpathObj; /* Cible d'une recherche */ - char *value; /* Type d'élément rencontré */ - size_t sub_expr_len; /* Taille d'une expression #2 */ - char *sub_expr; /* Chemin XPath reconstitué #2 */ - int i; /* Boucle de parcours */ - - result = NULL; - - /* S'occupe en premier lieu du niveau courant */ - - expr_len = strlen(base) + strlen("/*[position()=") + strlen("4294967295") /* UINT_MAX */ + strlen("]") + 1; - - expr = (char *)calloc(expr_len, sizeof(char)); - snprintf(expr, expr_len, "%s/*[position()=%u]", base, index); - - xpathObj = get_node_xpath_object(xpathCtx, expr); - - value = qck_get_node_prop_value(NODE_FROM_PATH_OBJ(xpathObj, 0), "type"); - - xmlXPathFreeObject(xpathObj); - - if (value == NULL) goto robfx_err1; - - /* Raffinement au second passage */ - - sub_expr_len = expr_len + strlen("/*"); - sub_expr = (char *)calloc(sub_expr_len, sizeof(char)); - snprintf(sub_expr, sub_expr_len, "%s/*", expr); - - xpathObj = get_node_xpath_object(xpathCtx, sub_expr); - - if (strcmp(value, "file") == 0) result = load_binary_file_from_xml(xpathObj); - - xmlXPathFreeObject(xpathObj); - - free(sub_expr); - - robfx_err1: - - free(expr); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à traiter. * -* writer = rédacteur dédié à l'écriture. * -* * -* Description : Ecrit une sauvegarde du binaire dans un fichier XML. * -* * -* Retour : true si l'opération a bien tourné, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool write_openida_binary_to_xml(const openida_binary *binary, xmlTextWriterPtr writer) -{ - bool result; /* Bilan à faire remonter */ - - result = open_xml_element(writer, "Binary"); - - result &= write_xml_attribute(writer, "type", "file"); - - result &= write_xml_element_with_content(writer, "Filename", "%s", binary->filename); - - result &= close_xml_element(writer); - - return result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : filename = nom du fichier à charger. * -* length = taille des données mises en mémoire. [OUT] * -* * -* Description : Charge en mémoire le contenu d'un fichier. * -* * -* Retour : Adresse du contenu binaire ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -uint8_t *map_binary_file(const char *filename, off_t *length) -{ - uint8_t *result; /* Données à retourner */ - int fd; /* Fichier ouvert en lecture */ - struct stat info; /* Informations sur le fichier */ - int ret; /* Bilan d'un appel */ - - fd = open(filename, 0, O_RDONLY); - if (fd == -1) - { - perror("open()"); - return NULL; - } - - ret = fstat(fd, &info); - if (ret == -1) - { - perror("fstat()"); - close(fd); - return NULL; - } - - *length = info.st_size; - - result = (uint8_t *)mmap(NULL, *length, PROT_READ, MAP_PRIVATE, fd, 0); - if (result == MAP_FAILED) - { - perror("mmap()"); - result = NULL; - } - - ret = close(fd); - if (ret == -1) - perror("close()"); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : filename = nom du fichier chargé. * -* data = données en mémoire pour l'empreinte. * -* length = quantité de données à prendre en compte. * -* * -* Description : Construit la description d'introduction du désassemblage. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -GRenderingLine *build_binary_prologue(const char *filename, const uint8_t *data, off_t length) -{ - GRenderingLine *result; /* Contenu à renvoyer */ - size_t len; /* Taille du texte */ - char *content; /* Contenu textuel d'une ligne */ - GRenderingLine *line; /* Représentation à ajouter */ - GChecksum *checksum; /* Calcul de l'empreinte */ - const gchar *hex; /* Valeur hexadécimale du SHA */ - - result = NULL;/* FIXME DL_LIST_HEAD_INIT( **/ - - line = g_prologue_line_new("Disassembly generated by OpenIDA"); - g_rendering_line_add_to_lines(&result, line); - - line = g_prologue_line_new("OpenIDA is free software - © 2008-2009 Cyrille Bagard"); - g_rendering_line_add_to_lines(&result, line); - - line = g_prologue_line_new(""); - g_rendering_line_add_to_lines(&result, line); - - /* Fichier */ - - len = strlen(_("File: ")) + strlen(filename); - content = (char *)calloc(len + 1, sizeof(char)); - - snprintf(content, len + 1, "%s%s", _("File: "), filename); - - line = g_prologue_line_new(content); - g_rendering_line_add_to_lines(&result, line); - - free(content); - - /* Checksum SHA256 */ - - checksum = g_checksum_new(G_CHECKSUM_SHA256); - - g_checksum_update(checksum, data, length); - hex = g_checksum_get_string(checksum); - - len = strlen(_("Sha256: ")) + strlen(hex); - content = (char *)calloc(len + 1, sizeof(char)); - - snprintf(content, len + 1, "%s%s", _("Sha256: "), hex); - - g_checksum_free(checksum); - - line = g_prologue_line_new(content); - g_rendering_line_add_to_lines(&result, line); - - free(content); - - line = g_prologue_line_new(""); - g_rendering_line_add_to_lines(&result, line); - - line = g_prologue_line_new(""); - g_rendering_line_add_to_lines(&result, line); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = binaire dont le contenu est à analyser. * -* * -* Description : Procède au désassemblage basique d'un contenu binaire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void disassemble_openida_binary(openida_binary *binary) -{ - asm_instr *instr; - - bin_routine **routines; /* Liste des routines trouvées */ - size_t routines_count; /* Nombre de ces routines */ - - bin_part **parts; - size_t parts_count; - - - - GRenderingLine *line; - - - off_t start; - off_t pos; - off_t len; - - uint64_t base = 0; - uint64_t offset = 0; - - size_t i; - - size_t k; - - uint64_t routine_offset; /* Point de départ de routine */ - char *routine_desc; /* Prototype d'une routine */ - - - - - binary->lines = build_binary_prologue(binary->filename, binary->bin_data, binary->bin_length); - - - - - - routines = get_all_exe_routines(binary->format, &routines_count); - - - parts = get_elf_default_code_parts(binary->format, &parts_count); - qsort(parts, parts_count, sizeof(bin_part *), compare_bin_parts); - - - - - for (i = 0; i < parts_count; i++) - { - get_bin_part_values(parts[i], &pos, &len, &base); - - /* Décodage des instructions */ - - start = pos; - pos = 0; - - while (pos < len) - { - offset = base + pos; - - - instr = decode_instruction(binary->proc, &binary->bin_data[start], &pos, len, start, offset); - - - line = g_code_line_new(offset, instr, &binary->options); - g_rendering_line_add_to_lines(&binary->lines, line); - - } - - /* Ajout des prototypes de fonctions */ - - for (k = 0; k < routines_count; k++) - { - routine_offset = get_binary_routine_offset(routines[k]); - - if (!(base <= routine_offset && routine_offset < (base + len))) continue; - - routine_desc = routine_to_string(routines[k]); - - line = g_comment_line_new(routine_offset, routine_desc, &binary->options); - g_rendering_line_insert_into_lines(&binary->lines, line, true); - - free(routine_desc); - - } - - } - - - - - - - line = g_rendering_line_find_by_offset(binary->lines, get_exe_entry_point(binary->format)); - g_rendering_line_add_flag(line, RLF_ENTRY_POINT); - - - - -} diff --git a/src/binary.h b/src/binary.h deleted file mode 100644 index ed3522d..0000000 --- a/src/binary.h +++ /dev/null @@ -1,73 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.h - prototypes pour le traitement des flots de code binaire - * - * Copyright (C) 2008 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 . - */ - - -#ifndef _BINARY_H -#define _BINARY_H - - -#include -#include "xml.h" - - -#include "analysis/line.h" - - - -/* Description d'un fichier binaire */ -typedef struct _openida_binary openida_binary; - - -/* Charge en mémoire le contenu d'un fichier. */ -openida_binary *load_binary_file(const char *); - -/* Décharge de la mémoire le contenu d'un fichier. */ -void unload_binary_file(openida_binary *); - -/* Fournit une description humaine d'un élément binaire. */ -const char *openida_binary_to_string(const openida_binary *); - -/* Fournit le fichier correspondant à l'élément binaire. */ -const char *openida_binary_get_filename(const openida_binary *); - -/* Fournit les lignes de rendu issues du désassemblage. */ -GRenderingLine *get_openida_binary_lines(const openida_binary *); - - - -/* Lit un élément binaire depuis un fichier XML. */ -openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr, const char *, unsigned int); - -/* Ecrit une sauvegarde du binaire dans un fichier. */ -bool write_openida_binary_to_xml(const openida_binary *, xmlTextWriterPtr); - - - - - - - - - - - -#endif /* _BINARY_H */ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index f23941b..1bb66d9 100755 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,13 +1,13 @@ -lib_LIBRARIES = libcommon.a +lib_LTLIBRARIES = libcommon.la -libcommon_a_SOURCES = \ +libcommon_la_SOURCES = \ dllist.h dllist.c \ endianness.h endianness.c \ extstr.h extstr.c \ macros.h -libcommon_a_CFLAGS = $(AM_CFLAGS) +libcommon_la_LDFLAGS = INCLUDES = diff --git a/src/common/extstr.c b/src/common/extstr.c index aba9830..deffbd4 100644 --- a/src/common/extstr.c +++ b/src/common/extstr.c @@ -25,6 +25,7 @@ #include +#include #include @@ -83,3 +84,57 @@ char *strprep(char *str1, const char *str2) return result; } + + +/****************************************************************************** +* * +* Paramètres : input = chaîne de caractères à traiter. * +* * +* Description : S'assure qu'une chaîne de caractère tient sur une ligne. * +* * +* Retour : Adresse de la chaîne de caractères modifiée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *escape_crlf(char *input) +{ + size_t inlen; + regex_t preg; + int ret; + size_t curpos; + regmatch_t pmatch[2]; + + inlen = strlen(input); + + ret = regcomp(&preg, "(\t|\n|\r)", REG_EXTENDED | REG_ICASE); + /* TODO: ret */ + + for (curpos = 0; regexec(&preg, &input[curpos], 2, pmatch, 0) != REG_NOMATCH; ) + { + inlen += 1 + 1; + input = (char *)realloc(input, inlen * sizeof(char *)); + + memmove(&input[curpos + pmatch[1].rm_eo + 1], &input[curpos + pmatch[1].rm_eo], inlen - 1 - curpos - pmatch[1].rm_eo); + + switch (input[curpos + pmatch[1].rm_so]) + { + case '\t': + memcpy(&input[curpos + pmatch[1].rm_so], "\\t", 2); + break; + case '\n': + memcpy(&input[curpos + pmatch[1].rm_so], "\\n", 2); + break; + case '\r': + memcpy(&input[curpos + pmatch[1].rm_so], "\\r", 2); + break; + } + + curpos += pmatch[1].rm_eo + 1; + + } + + return input; + +} diff --git a/src/common/extstr.h b/src/common/extstr.h index 8975000..8baa2e2 100644 --- a/src/common/extstr.h +++ b/src/common/extstr.h @@ -32,6 +32,9 @@ char *stradd(char *str1, const char *str2); /* Fait précéder une chaîne de caractères par une autre. */ char *strprep(char *, const char *); +/* S'assure qu'une chaîne de caractère tient sur une ligne. */ +char *escape_crlf(char *); + #endif /* _COMMON_EXTSTR_H */ diff --git a/src/debug/debuggers.h b/src/debug/debuggers.h index 96e0c47..03c3164 100644 --- a/src/debug/debuggers.h +++ b/src/debug/debuggers.h @@ -30,7 +30,7 @@ #include -#include "../binary.h" +#include "../analysis/binary.h" diff --git a/src/debug/ptrace/options.h b/src/debug/ptrace/options.h index e49f87c..bc25abf 100644 --- a/src/debug/ptrace/options.h +++ b/src/debug/ptrace/options.h @@ -28,7 +28,7 @@ #include -#include "../../binary.h" +#include "../../analysis/binary.h" diff --git a/src/dlg_sections.c b/src/dlg_sections.c index 2aae552..44a00a7 100644 --- a/src/dlg_sections.c +++ b/src/dlg_sections.c @@ -24,7 +24,7 @@ #include "dlg_sections.h" -#include "easygtk.h" +#include "gtkext/easygtk.h" diff --git a/src/easygtk.c b/src/easygtk.c deleted file mode 100644 index d6f8dc4..0000000 --- a/src/easygtk.c +++ /dev/null @@ -1,538 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * easygtk.c - mise en place rapide de composants GTK - * - * Copyright (C) 2008 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 . - */ - - -#include "easygtk.h" - - - - -/****************************************************************************** -* * -* Paramètres : pt = espace imposé à la zone supérieure. * -* pb = espace imposé à la zone inférieure. * -* pl = espace imposé à la zone gauche. * -* pr = espace imposé à la zone droite. * -* * -* Description : Met en place un aligement dont les bordures sont à ajuster. * -* * -* Retour : Composant 'GtkWidget' ici créé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_padded_alignment(guint pt, guint pb, guint pl, guint pr) -{ - GtkWidget *result; /* Instance à renvoyer */ - - result = gtk_alignment_new(0.5, 0.5, 1, 1); - gtk_widget_show(result); - gtk_alignment_set_padding(GTK_ALIGNMENT(result), pt, pb, pl, pr); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : caption = contenu de l'étiqutte à placer. * -* alignment = conteneur réel à utiliser pour la suite. [OUT] * -* pt = espace imposé à la zone supérieure. * -* pb = espace imposé à la zone inférieure. * -* pl = espace imposé à la zone gauche. * -* pr = espace imposé à la zone droite. * -* * -* Description : Met en place une frame. * -* * -* Retour : Composant 'GtkWidget' ici créé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_frame(const char *caption, GtkWidget **alignment, guint pt, guint pb, guint pl, guint pr) -{ - GtkWidget *result; /* Instance à renvoyer */ - GtkWidget *label; /* Etiquette à utiliser */ - - result = gtk_frame_new(NULL); - gtk_widget_show(result); - - gtk_frame_set_shadow_type(GTK_FRAME(result), GTK_SHADOW_NONE); - - label = qck_create_label(NULL, NULL, caption); - gtk_frame_set_label_widget(GTK_FRAME(result), label); - gtk_label_set_use_markup(GTK_LABEL(label), TRUE); - - *alignment = qck_create_padded_alignment(pt, pb, pl, pr); - gtk_container_add(GTK_CONTAINER(result), *alignment); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* * -* Description : Met en place un support à onglets. * -* * -* Retour : Composant 'GtkWidget' ici créé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_notebook(GObject *object, const char *name) -{ - GtkWidget *result; /* Instance à renvoyer */ - - result = gtk_notebook_new(); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* filename = chemin d'accès complet au fichier à afficher. * -* * -* Description : Crée un composant 'GtkImage'. * -* * -* Retour : Image mise en place. * -* * -* Remarques : Si le chemin est libérable, il est libéré de la mémoire. * -* * -******************************************************************************/ - -GtkWidget *qck_create_image(GObject *object, const char *name, gchar *filename) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - if (filename == NULL) - result = gtk_image_new(); - - else - { - result = gtk_image_new_from_file(filename); - g_free(filename); - } - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* caption = intitulé apparaissant sur le composant. * -* * -* Description : Crée un composant 'GtkLabel'. * -* * -* Retour : Champ d'indication mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_label(GObject *object, const char *name, const char *caption) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_label_new(caption); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - gtk_misc_set_alignment(GTK_MISC(result), 0, 0.5); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* text = éventuel contenu initial du champ de saisie. * -* * -* Description : Crée et enregistre un composant 'GtkEntry'. * -* * -* Retour : Champ de saisie mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_entry(GObject *object, const char *name, const char *text) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_entry_new(); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (text != NULL) - gtk_entry_set_text(GTK_ENTRY(result), text); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* caption = intitulé du bouton à créer. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkButton'. * -* * -* Retour : Simple bouton mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_button(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_button_new_with_label(caption); - GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "clicked", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* stock = désignation du type de bouton GTK. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkButton'. * -* * -* Retour : Simple bouton mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_button_from_stock(GObject *object, const char *name, const char *stock, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_button_new_from_stock(stock); - GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "clicked", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* image = nom de l'image stockée dans GTK. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkButton'. * -* * -* Retour : Simple bouton mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_button_with_img(GObject *object, const char *name, const char *image, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - GtkWidget *render; /* Image à ajouter au bouton */ - - result = gtk_button_new(); - GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); - - render = gtk_image_new_from_stock(image, GTK_ICON_SIZE_BUTTON); - gtk_widget_show(render); - gtk_container_add(GTK_CONTAINER(result), render); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "clicked", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkComboBox'. * -* * -* Retour : Composant mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_combobox(GObject *object, const char *name, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_combo_box_new_text(); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "changed", handler, data); - - return result; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* caption = intitulé du menu à créer. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkMenuItem'. * -* * -* Retour : Simple élément de menu mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_menu_item(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_menu_item_new_with_mnemonic(caption); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "activate", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* caption = intitulé du menu à créer. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkCheckMenuItem'. * -* * -* Retour : Simple élément de menu mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_check_menu_item(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_check_menu_item_new_with_mnemonic(caption); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "toggled", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : object = espace dédié à l'inscription de références. * -* name = nom à donner au nouveau composant. * -* rgroup = groupe d'apparatenance pour les radios. * -* caption = intitulé du menu à créer. * -* handler = éventuelle fonction de sélection associée. * -* data = données à transmettre avec l'événement si besoin. * -* * -* Description : Crée et enregistre un composant 'GtkRadioMenuItem'. * -* * -* Retour : Simple élément de menu mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_radio_menu_item(GObject *object, const char *name, GSList *rgroup, const char *caption, GCallback handler, gpointer data) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_radio_menu_item_new_with_mnemonic(rgroup, caption); - - if (G_IS_OBJECT(object) && name != NULL) - { - gtk_widget_ref(result); - g_object_set_data_full(object, name, result, (GtkDestroyNotify)gtk_widget_unref); - } - - gtk_widget_show(result); - - if (handler != NULL) - g_signal_connect(result, "toggled", handler, data); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Crée et enregistre un composant 'GtkSeparatorMenuItem'. * -* * -* Retour : Simple élément de menu mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *qck_create_menu_separator(void) -{ - GtkWidget *result; /* Résultat à renvoyer */ - - result = gtk_separator_menu_item_new(); - gtk_widget_show(result); - - return result; - -} diff --git a/src/easygtk.h b/src/easygtk.h deleted file mode 100644 index 41b24e0..0000000 --- a/src/easygtk.h +++ /dev/null @@ -1,80 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * easygtk.h - prototypes pour la mise en place rapide de composants GTK - * - * Copyright (C) 2008 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 . - */ - - -#ifndef _EASYGTK_H -#define _EASYGTK_H - - -#include - - - -/* Met en place un aligement dont les bordures sont à ajuster. */ -GtkWidget *qck_create_padded_alignment(guint, guint, guint, guint); - -/* Met en place une frame. */ -GtkWidget *qck_create_frame(const char *, GtkWidget **, guint, guint, guint, guint); - -/* Met en place un support à onglets. */ -GtkWidget *qck_create_notebook(GObject *, const char *); - -/* Crée un composant 'GtkImage'. */ -GtkWidget *qck_create_image(GObject *, const char *, gchar *); - -/* Crée un composant 'GtkLabel'. */ -GtkWidget *qck_create_label(GObject *, const char *, const char *); - -/* Crée et enregistre un composant 'GtkEntry'. */ -GtkWidget *qck_create_entry(GObject *, const char *, const char *); - -/* Crée et enregistre un composant 'GtkButton'. */ -GtkWidget *qck_create_button(GObject *, const char *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkButton'. */ -GtkWidget *qck_create_button_from_stock(GObject *, const char *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkButton'. */ -GtkWidget *qck_create_button_with_img(GObject *, const char *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkComboBox'. */ -GtkWidget *qck_create_combobox(GObject *, const char *, GCallback, gpointer); - - - - -/* Crée et enregistre un composant 'GtkMenuItem'. */ -GtkWidget *qck_create_menu_item(GObject *, const char *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkCheckMenuItem'. */ -GtkWidget *qck_create_check_menu_item(GObject *, const char *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkRadioMenuItem'. */ -GtkWidget *qck_create_radio_menu_item(GObject *, const char *, GSList *, const char *, GCallback, gpointer); - -/* Crée et enregistre un composant 'GtkSeparatorMenuItem'. */ -GtkWidget *qck_create_menu_separator(void); - - - - -#endif /* _EASYGTK_H */ diff --git a/src/editor.c b/src/editor.c index 888f1af..4e0b8c2 100644 --- a/src/editor.c +++ b/src/editor.c @@ -41,21 +41,27 @@ -#include "binary.h" #include "dlg_sections.h" -#include "easygtk.h" #include "pan_strings.h" #include "pan_symbols.h" +#include "analysis/binary.h" +#include "gtkext/easygtk.h" #include "gtkext/gtkbinview.h" #include "gtkext/gtkdockpanel.h" #include "gtkext/gtksnippet.h" #include "format/exe_format.h" #include "format/mangling/demangler.h" +#include "plugins/pglist.h" #include "debug/debuggers.h" #include "panel/panels.h" + +#include "shell.h" /* TODO : à virer -> plugin */ + + + #define _(str) str @@ -180,6 +186,7 @@ int main(int argc, char **argv) editor = create_editor(); gtk_widget_show(editor); + init_all_plugins(G_OBJECT(editor)); gdk_threads_enter(); gtk_main(); @@ -396,10 +403,16 @@ GtkWidget *create_editor(void) submenuitem = qck_create_menu_separator(); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); + + update_debug_menu_items(ref, FALSE); + menuitem = gtk_menu_item_new_with_mnemonic(_("_Plugins")); + gtk_widget_show(menuitem); + gtk_container_add(GTK_CONTAINER(menuboard), menuitem); + @@ -523,6 +536,13 @@ GtkWidget *create_editor(void) + panel = build_shell_panel(G_OBJECT(result)); + + ditem = gtk_dock_item_new(_("Shell"), panel); + gtk_dock_panel_add_item(dpanel, ditem); + + + /* notebook = qck_create_notebook(NULL, NULL); diff --git a/src/format/Makefile.am b/src/format/Makefile.am index baf11de..41d7120 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -1,13 +1,18 @@ -lib_LIBRARIES = libformat.a +lib_LTLIBRARIES = libformat.la -libformat_a_SOURCES = \ +libformat_la_SOURCES = \ exe_format.h exe_format.c \ exe_format-int.h \ dbg_format.h dbg_format.c \ dbg_format-int.h -libformat_a_CFLAGS = $(AM_CFLAGS) +libformat_la_LDFLAGS = $(LIBGTK_LIBS) \ + -Ldwarf/.libs -lformatdwarf \ + -Lelf/.libs -lformatelf \ + -Ljava/.libs -lformatjava \ + -Lmangling/.libs -lformatmangling \ + -Lpe/.libs -lformatpe INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/format/dwarf/Makefile.am b/src/format/dwarf/Makefile.am index 0c36205..d5853c3 100644 --- a/src/format/dwarf/Makefile.am +++ b/src/format/dwarf/Makefile.am @@ -1,14 +1,14 @@ -lib_LIBRARIES = libformatdwarf.a +lib_LTLIBRARIES = libformatdwarf.la -libformatdwarf_a_SOURCES = \ +libformatdwarf_la_SOURCES = \ abbrev.h abbrev.c \ d_dwarf.h d_dwarf.c \ dwarf_def.h \ info.h info.c \ utils.h utils.c -libformatdwarf_a_CFLAGS = $(AM_CFLAGS) +libformatdwarf_la_LDFLAGS = $(LIBGTK_LIBS) INCLUDES = diff --git a/src/format/elf/Makefile.am b/src/format/elf/Makefile.am index 663194e..c64fc5c 100644 --- a/src/format/elf/Makefile.am +++ b/src/format/elf/Makefile.am @@ -1,14 +1,16 @@ -lib_LIBRARIES = libformatelf.a +lib_LTLIBRARIES = libformatelf.la -libformatelf_a_SOURCES = \ +libformatelf_la_SOURCES = \ e_elf.h e_elf.c \ elf-int.h \ section.h section.c \ strings.h strings.c \ symbol.h symbol.c -libformatelf_a_CFLAGS = $(AM_CFLAGS) +libformatelf_la_LDFLAGS = $(LIBGTK_LIBS) \ + -L../../common/.libs -common \ + -L../../arch/.libs -larch INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/format/elf/e_elf.c b/src/format/elf/e_elf.c index 1a1fe8d..c52a304 100644 --- a/src/format/elf/e_elf.c +++ b/src/format/elf/e_elf.c @@ -33,6 +33,7 @@ #include "strings.h" #include "symbol.h" #include "../../panel/log.h" +#include "../../common/extstr.h" @@ -47,9 +48,6 @@ uint64_t get_elf_entry_point(const elf_format *); -/* S'assure qu'une chaîne de caractère tient sur une ligne. */ -extern char *escape_crlf_bin_string(char *); - /* Récupère tous les éléments identifiées dans le binaire. */ size_t get_elf_resolved_items(const elf_format *, char ***, ResolvedType **, uint64_t **); @@ -462,7 +460,7 @@ size_t get_elf_resolved_items(const elf_format *format, char ***labels, Resolved (*types)[start + i] = RTP_STRING; (*offsets)[start + i] = format->strings[i].vaddress; - (*labels)[start + i] = escape_crlf_bin_string((*labels)[start + i]); + (*labels)[start + i] = escape_crlf((*labels)[start + i]); } diff --git a/src/format/java/Makefile.am b/src/format/java/Makefile.am index f94466d..9f59f61 100755 --- a/src/format/java/Makefile.am +++ b/src/format/java/Makefile.am @@ -1,7 +1,7 @@ -lib_LIBRARIES = libformatjava.a +lib_LTLIBRARIES = libformatjava.la -libformatjava_a_SOURCES = \ +libformatjava_la_SOURCES = \ attribute.h attribute.c \ e_java.h e_java.c \ field.h field.c \ @@ -9,7 +9,7 @@ libformatjava_a_SOURCES = \ method.h method.c \ pool.h pool.c -libformatjava_a_CFLAGS = $(AM_CFLAGS) +libformatjava_la_LDFLAGS = $(LIBGTK_LIBS) INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/format/mangling/Makefile.am b/src/format/mangling/Makefile.am index 3f7acc5..0823ffc 100644 --- a/src/format/mangling/Makefile.am +++ b/src/format/mangling/Makefile.am @@ -3,15 +3,15 @@ BUILT_SOURCES = itanium_gram.h AM_YFLAGS = -d -lib_LIBRARIES = libformatmangling.a +lib_LTLIBRARIES = libformatmangling.la -libformatmangling_a_SOURCES = \ +libformatmangling_la_SOURCES = \ demangler.h demangler.c \ itanium.h \ itanium_gram.y \ itanium_tok.l -libformatmangling_a_CFLAGS = $(AM_CFLAGS) +libformatmangling_la_LDFLAGS = $(LIBGTK_LIBS) INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/format/pe/Makefile.am b/src/format/pe/Makefile.am index cf47c4e..9167577 100755 --- a/src/format/pe/Makefile.am +++ b/src/format/pe/Makefile.am @@ -1,11 +1,11 @@ -lib_LIBRARIES = libformatpe.a +lib_LTLIBRARIES = libformatpe.la -libformatpe_a_SOURCES = \ +libformatpe_la_SOURCES = \ e_pe.h e_pe.c \ pe-int.h -libformatpe_a_CFLAGS = $(AM_CFLAGS) +libformatpe_la_LDFLAGS = $(LIBGTK_LIBS) INCLUDES = diff --git a/src/gtkext/Makefile.am b/src/gtkext/Makefile.am index aa14cf5..dbf1fbc 100644 --- a/src/gtkext/Makefile.am +++ b/src/gtkext/Makefile.am @@ -1,17 +1,20 @@ BUILT_SOURCES = iodamarshal.h iodamarshal.c -lib_LIBRARIES = libgtkext.a +lib_LTLIBRARIES = libgtkext.la -libgtkext_a_SOURCES = \ +libgtkext_la_SOURCES = \ + easygtk.h easygtk.c \ gtkbinview.h gtkbinview.c \ gtkdockitem.h gtkdockitem.c \ gtkdockpanel.h gtkdockpanel.c \ gtkdropwindow.h gtkdropwindow.c \ gtksnippet.h gtksnippet.c \ - iodamarshal.h iodamarshal.c + iodamarshal.h iodamarshal.c \ + support.h support.c -libgtkext_a_CFLAGS = $(AM_CFLAGS) +libgtkext_la_LDFLAGS = $(LIBGTK_LIBS) \ + -L../analysis/.libs -lanalysis INCLUDES = $(LIBGTK_CFLAGS) diff --git a/src/gtkext/easygtk.c b/src/gtkext/easygtk.c new file mode 100644 index 0000000..f596404 --- /dev/null +++ b/src/gtkext/easygtk.c @@ -0,0 +1,538 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * easygtk.c - mise en place rapide de composants GTK + * + * Copyright (C) 2008 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 . + */ + + +#include "easygtk.h" + + + + +/****************************************************************************** +* * +* Paramètres : pt = espace imposé à la zone supérieure. * +* pb = espace imposé à la zone inférieure. * +* pl = espace imposé à la zone gauche. * +* pr = espace imposé à la zone droite. * +* * +* Description : Met en place un aligement dont les bordures sont à ajuster. * +* * +* Retour : Composant 'GtkWidget' ici créé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_padded_alignment(guint pt, guint pb, guint pl, guint pr) +{ + GtkWidget *result; /* Instance à renvoyer */ + + result = gtk_alignment_new(0.5, 0.5, 1, 1); + gtk_widget_show(result); + gtk_alignment_set_padding(GTK_ALIGNMENT(result), pt, pb, pl, pr); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : caption = contenu de l'étiqutte à placer. * +* alignment = conteneur réel à utiliser pour la suite. [OUT] * +* pt = espace imposé à la zone supérieure. * +* pb = espace imposé à la zone inférieure. * +* pl = espace imposé à la zone gauche. * +* pr = espace imposé à la zone droite. * +* * +* Description : Met en place une frame. * +* * +* Retour : Composant 'GtkWidget' ici créé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_frame(const char *caption, GtkWidget **alignment, guint pt, guint pb, guint pl, guint pr) +{ + GtkWidget *result; /* Instance à renvoyer */ + GtkWidget *label; /* Etiquette à utiliser */ + + result = gtk_frame_new(NULL); + gtk_widget_show(result); + + gtk_frame_set_shadow_type(GTK_FRAME(result), GTK_SHADOW_NONE); + + label = qck_create_label(NULL, NULL, caption); + gtk_frame_set_label_widget(GTK_FRAME(result), label); + gtk_label_set_use_markup(GTK_LABEL(label), TRUE); + + *alignment = qck_create_padded_alignment(pt, pb, pl, pr); + gtk_container_add(GTK_CONTAINER(result), *alignment); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* * +* Description : Met en place un support à onglets. * +* * +* Retour : Composant 'GtkWidget' ici créé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_notebook(GObject *object, const char *name) +{ + GtkWidget *result; /* Instance à renvoyer */ + + result = gtk_notebook_new(); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* filename = chemin d'accès complet au fichier à afficher. * +* * +* Description : Crée un composant 'GtkImage'. * +* * +* Retour : Image mise en place. * +* * +* Remarques : Si le chemin est libérable, il est libéré de la mémoire. * +* * +******************************************************************************/ + +GtkWidget *qck_create_image(GObject *object, const char *name, gchar *filename) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + if (filename == NULL) + result = gtk_image_new(); + + else + { + result = gtk_image_new_from_file(filename); + g_free(filename); + } + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* caption = intitulé apparaissant sur le composant. * +* * +* Description : Crée un composant 'GtkLabel'. * +* * +* Retour : Champ d'indication mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_label(GObject *object, const char *name, const char *caption) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_label_new(caption); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + gtk_misc_set_alignment(GTK_MISC(result), 0, 0.5); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* text = éventuel contenu initial du champ de saisie. * +* * +* Description : Crée et enregistre un composant 'GtkEntry'. * +* * +* Retour : Champ de saisie mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_entry(GObject *object, const char *name, const char *text) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_entry_new(); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (text != NULL) + gtk_entry_set_text(GTK_ENTRY(result), text); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* caption = intitulé du bouton à créer. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkButton'. * +* * +* Retour : Simple bouton mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_button(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_button_new_with_label(caption); + GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "clicked", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* stock = désignation du type de bouton GTK. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkButton'. * +* * +* Retour : Simple bouton mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_button_from_stock(GObject *object, const char *name, const char *stock, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_button_new_from_stock(stock); + GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "clicked", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* image = nom de l'image stockée dans GTK. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkButton'. * +* * +* Retour : Simple bouton mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_button_with_img(GObject *object, const char *name, const char *image, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + GtkWidget *render; /* Image à ajouter au bouton */ + + result = gtk_button_new(); + GTK_WIDGET_SET_FLAGS(result, GTK_CAN_DEFAULT); + + render = gtk_image_new_from_stock(image, GTK_ICON_SIZE_BUTTON); + gtk_widget_show(render); + gtk_container_add(GTK_CONTAINER(result), render); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "clicked", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkComboBox'. * +* * +* Retour : Composant mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_combobox(GObject *object, const char *name, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_combo_box_new_text(); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "changed", handler, data); + + return result; + +} + + + + + + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* caption = intitulé du menu à créer. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkMenuItem'. * +* * +* Retour : Simple élément de menu mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_menu_item(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_menu_item_new_with_mnemonic(caption); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "activate", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* caption = intitulé du menu à créer. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkCheckMenuItem'. * +* * +* Retour : Simple élément de menu mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_check_menu_item(GObject *object, const char *name, const char *caption, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_check_menu_item_new_with_mnemonic(caption); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "toggled", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : object = espace dédié à l'inscription de références. * +* name = nom à donner au nouveau composant. * +* rgroup = groupe d'apparatenance pour les radios. * +* caption = intitulé du menu à créer. * +* handler = éventuelle fonction de sélection associée. * +* data = données à transmettre avec l'événement si besoin. * +* * +* Description : Crée et enregistre un composant 'GtkRadioMenuItem'. * +* * +* Retour : Simple élément de menu mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_radio_menu_item(GObject *object, const char *name, GSList *rgroup, const char *caption, GCallback handler, gpointer data) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_radio_menu_item_new_with_mnemonic(rgroup, caption); + + if (G_IS_OBJECT(object) && name != NULL) + { + gtk_widget_ref(result); + g_object_set_data_full(object, name, result, (GtkDestroyNotify)g_object_unref); + } + + gtk_widget_show(result); + + if (handler != NULL) + g_signal_connect(result, "toggled", handler, data); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée et enregistre un composant 'GtkSeparatorMenuItem'. * +* * +* Retour : Simple élément de menu mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *qck_create_menu_separator(void) +{ + GtkWidget *result; /* Résultat à renvoyer */ + + result = gtk_separator_menu_item_new(); + gtk_widget_show(result); + + return result; + +} diff --git a/src/gtkext/easygtk.h b/src/gtkext/easygtk.h new file mode 100644 index 0000000..41b24e0 --- /dev/null +++ b/src/gtkext/easygtk.h @@ -0,0 +1,80 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * easygtk.h - prototypes pour la mise en place rapide de composants GTK + * + * Copyright (C) 2008 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 . + */ + + +#ifndef _EASYGTK_H +#define _EASYGTK_H + + +#include + + + +/* Met en place un aligement dont les bordures sont à ajuster. */ +GtkWidget *qck_create_padded_alignment(guint, guint, guint, guint); + +/* Met en place une frame. */ +GtkWidget *qck_create_frame(const char *, GtkWidget **, guint, guint, guint, guint); + +/* Met en place un support à onglets. */ +GtkWidget *qck_create_notebook(GObject *, const char *); + +/* Crée un composant 'GtkImage'. */ +GtkWidget *qck_create_image(GObject *, const char *, gchar *); + +/* Crée un composant 'GtkLabel'. */ +GtkWidget *qck_create_label(GObject *, const char *, const char *); + +/* Crée et enregistre un composant 'GtkEntry'. */ +GtkWidget *qck_create_entry(GObject *, const char *, const char *); + +/* Crée et enregistre un composant 'GtkButton'. */ +GtkWidget *qck_create_button(GObject *, const char *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkButton'. */ +GtkWidget *qck_create_button_from_stock(GObject *, const char *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkButton'. */ +GtkWidget *qck_create_button_with_img(GObject *, const char *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkComboBox'. */ +GtkWidget *qck_create_combobox(GObject *, const char *, GCallback, gpointer); + + + + +/* Crée et enregistre un composant 'GtkMenuItem'. */ +GtkWidget *qck_create_menu_item(GObject *, const char *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkCheckMenuItem'. */ +GtkWidget *qck_create_check_menu_item(GObject *, const char *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkRadioMenuItem'. */ +GtkWidget *qck_create_radio_menu_item(GObject *, const char *, GSList *, const char *, GCallback, gpointer); + +/* Crée et enregistre un composant 'GtkSeparatorMenuItem'. */ +GtkWidget *qck_create_menu_separator(void); + + + + +#endif /* _EASYGTK_H */ diff --git a/src/gtkext/gtkdockpanel.c b/src/gtkext/gtkdockpanel.c index f48f31a..e7bd14b 100644 --- a/src/gtkext/gtkdockpanel.c +++ b/src/gtkext/gtkdockpanel.c @@ -624,13 +624,13 @@ static gboolean gtk_dock_panel_update_title(GtkNotebook *notebook, GtkNotebookPa char *str; /* Valeur finale reconstituée */ - printf("[%p] list len :: %u / %u\n", data, index, g_list_length(GTK_DOCK_PANEL(data)->ditems)); + //printf("[%p] list len :: %u / %u\n", data, index, g_list_length(GTK_DOCK_PANEL(data)->ditems)); if (index >= g_list_length(GTK_DOCK_PANEL(data)->ditems)) return FALSE; - printf(" >> ditem = %p\n", g_list_nth_data(GTK_DOCK_PANEL(data)->ditems, index)); + //printf(" >> ditem = %p\n", g_list_nth_data(GTK_DOCK_PANEL(data)->ditems, index)); - printf(" >> index :: %u vs %d\n", index, gtk_notebook_get_current_page(GTK_DOCK_PANEL(data)->notebook)); + //printf(" >> index :: %u vs %d\n", index, gtk_notebook_get_current_page(GTK_DOCK_PANEL(data)->notebook)); ditem = GTK_DOCK_ITEM(g_list_nth_data(GTK_DOCK_PANEL(data)->ditems, index)); diff --git a/src/gtkext/gtksnippet.c b/src/gtkext/gtksnippet.c index a48baf2..39d2949 100644 --- a/src/gtkext/gtksnippet.c +++ b/src/gtkext/gtksnippet.c @@ -156,29 +156,10 @@ static void gtk_snippet_paint(GtkSnippet *snippet); static void gtk_snippet_destroy(GtkObject *object); -GtkType -gtk_snippet_get_type(void) -{ - static GtkType gtk_snippet_type = 0; - - - if (!gtk_snippet_type) { - static const GtkTypeInfo gtk_snippet_info = { - "GtkSnippet", - sizeof(GtkSnippet), - sizeof(GtkSnippetClass), - (GtkClassInitFunc) gtk_snippet_class_init, - (GtkObjectInitFunc) gtk_snippet_init, - NULL, - NULL, - (GtkClassInitFunc) NULL - }; - gtk_snippet_type = gtk_type_unique(GTK_TYPE_WIDGET, >k_snippet_info); - } + +G_DEFINE_TYPE(GtkSnippet, gtk_snippet, GTK_TYPE_WIDGET) - return gtk_snippet_type; -} GtkWidget * gtk_snippet_new(void) @@ -688,6 +669,7 @@ void gtk_snippet_add_line(GtkSnippet *snippet, const code_line_info *line) void gtk_snippet_build_content(GtkSnippet *snippet) { +#if 0 const uint8_t *exe_content; /* Contenu binaire global */ off_t max_bin_len; /* Taille max du code brut */ unsigned int i; /* Boucle de traitement */ @@ -854,7 +836,7 @@ void gtk_snippet_build_content(GtkSnippet *snippet) pango_layout_iter_free(iter); //gtk_widget_set_size_request(GTK_WIDGET(snippet), width + 2 * MARGIN_SPACE + snippet->line_height, height); - +#endif } diff --git a/src/gtkext/support.c b/src/gtkext/support.c new file mode 100644 index 0000000..67e7605 --- /dev/null +++ b/src/gtkext/support.c @@ -0,0 +1,92 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * support.c - recherche des chemins d'accès aux fichiers + * + * Copyright (C) 2008-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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "support.h" + + +#include +#include + + + +/* Liste des répertoires contenant des images */ +static GList *pixmaps_directories = NULL; + + + +/****************************************************************************** +* * +* Paramètres : directory = nouveau répertoire à parcourir. * +* * +* Description : Ajoute un répertoire à la liste des répertoires d'images. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void add_pixmap_directory(const char *directory) +{ + pixmaps_directories = g_list_prepend(pixmaps_directories, + strdup(directory)); + +} + + +/****************************************************************************** +* * +* Paramètres : filename = nom de fichier seul comme indice. * +* * +* Description : Trouve le chemin d'accès complet à un fichier donné. * +* * +* Retour : Chemin trouvé à libérer de la mémoire ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +gchar *find_pixmap_file(const char *filename) +{ + gchar *result; /* Trouvaille à renvoyer */ + GList *iter; /* Boucle de parcours */ + + result = NULL; + + for (iter = pixmaps_directories; iter != NULL && result == NULL; iter = iter->next) + { + result = g_strdup_printf("%s%s%s", (gchar *)iter->data, + G_DIR_SEPARATOR_S, filename); + + if (!g_file_test(result, G_FILE_TEST_EXISTS)) + { + g_free(result); + result = NULL; + } + + } + + return result; + +} diff --git a/src/gtkext/support.h b/src/gtkext/support.h new file mode 100644 index 0000000..9d3373b --- /dev/null +++ b/src/gtkext/support.h @@ -0,0 +1,41 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * support.h - prototypes pour la recherche des chemins d'accès aux fichiers + * + * Copyright (C) 2008-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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _SUPPORT_H +#define _SUPPORT_H + + +#include + + + +/* Ajoute un répertoire à la liste des répertoires d'images. */ +void add_pixmap_directory(const char *); + +/* Trouve le chemin d'accès complet à un fichier donné. */ +gchar *find_pixmap_file(const char *); + + + +#endif /* _SUPPORT_H */ diff --git a/src/panel/Makefile.am b/src/panel/Makefile.am index a74cfa0..c69e2ca 100755 --- a/src/panel/Makefile.am +++ b/src/panel/Makefile.am @@ -1,12 +1,13 @@ -lib_LIBRARIES = libpanel.a +lib_LTLIBRARIES = libpanel.la -libpanel_a_SOURCES = \ +libpanel_la_SOURCES = \ log.h log.c \ panels.h panels.c \ registers.h registers.c -libpanel_a_CFLAGS = $(AM_CFLAGS) +libpanel_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBPYTHON_LIBS) \ + -L../gtkext/.libs -lgtkext INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) diff --git a/src/panel/log.c b/src/panel/log.c index 94bb8a4..812d470 100644 --- a/src/panel/log.c +++ b/src/panel/log.c @@ -109,8 +109,8 @@ GtkWidget *build_log_panel(void) /****************************************************************************** * * -* Paramètres : panel = panneau à mettre à jour. * -* msg = message à faire apparaître à l'écran. * +* Paramètres : type = espèce du message à ajouter. * +* msg = message à faire apparaître à l'écran. * * * * Description : Affiche un message dans le journal des messages système. * * * @@ -161,9 +161,9 @@ void log_simple_message(LogMessageType type, const char *msg) /****************************************************************************** * * -* Paramètres : panel = panneau à mettre à jour. * -* fmt = format du message à faire apparaître à l'écran. * -* ... = éventuels arguments venant compléter le message. * +* Paramètres : type = espèce du message à ajouter. * +* fmt = format du message à faire apparaître à l'écran. * +* ... = éventuels arguments venant compléter le message. * * * * Description : Affiche un message dans le journal des messages système. * * * diff --git a/src/panel/registers.c b/src/panel/registers.c index ce27a71..1f9c8e5 100644 --- a/src/panel/registers.c +++ b/src/panel/registers.c @@ -25,7 +25,7 @@ #include "registers.h" -#include "../easygtk.h" +#include "../gtkext/easygtk.h" diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am new file mode 100644 index 0000000..2d480bb --- /dev/null +++ b/src/plugins/Makefile.am @@ -0,0 +1,17 @@ + +lib_LIBRARIES = libplugins.a + +libplugins_a_SOURCES = \ + pglist.h pglist.c \ + plugin.h plugin.c + +libplugins_a_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = pyoida diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c new file mode 100644 index 0000000..8301eb3 --- /dev/null +++ b/src/plugins/pglist.c @@ -0,0 +1,73 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pglist.c - gestion de l'ensemble des greffons + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "pglist.h" + + +#include "plugin.h" + + + +/* Propriétés de l'ensemble des greffons */ +typedef struct _plugins_list +{ + GObject *ref; /* Référencement global */ + + + + +} plugins_list; + + +/* Liste de l'ensemble des greffons */ +static plugins_list list; + + + +/****************************************************************************** +* * +* Paramètres : ref = espace de référencement global. * +* * +* Description : Procède au chargement des différents greffons trouvés. * +* * +* Retour : Toujours true (même s'il y a des erreurs de chargemet). * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_all_plugins(GObject *ref) +{ + GPluginModule *pg; + + list.ref = ref; + + + pg = g_plugin_module_new("/home/ocb/prog/openida.pg/src/plugins/pyoida/pyoidamodule.so", list.ref); + + printf("plug ? %p\n", pg); + + return true; + +} diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h new file mode 100644 index 0000000..89abd51 --- /dev/null +++ b/src/plugins/pglist.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pglist.h - prototypes pour la gestion de l'ensemble des greffons + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PGLIST_H +#define _PLUGINS_PGLIST_H + + +#include +#include + + + +/* Procède au chargement des différents greffons trouvés. */ +bool init_all_plugins(GObject *); + + + +#endif /* _PLUGINS_PGLIST_H */ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c new file mode 100644 index 0000000..f21ac02 --- /dev/null +++ b/src/plugins/plugin.c @@ -0,0 +1,144 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * plugin.h - interactions avec un greffon donné + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "plugin.h" + + +#include +#include + + + +/* Procède à l'initialisation du greffon */ +typedef bool (* init_plugin_fc) (GObject *); + + + +/* Greffon pour OpenIDA (instance) */ +struct _GPluginModule +{ + GObject parent; /* A laisser en premier */ + + GModule *module; /* Abstration de manipulation */ + + init_plugin_fc init; /* Procédure d'initialisation */ + +}; + + +/* Greffon pour OpenIDA (classe) */ +struct _GPluginModuleClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des greffons. */ +static void g_plugin_module_class_init(GPluginModuleClass *); + +/* Initialise une instance de greffon. */ +static void g_plugin_module_init(GPluginModule *); + + + +/* Indique le type définit pour un greffon. */ +G_DEFINE_TYPE(GPluginModule, g_plugin_module, G_TYPE_OBJECT); + + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des greffons. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_plugin_module_class_init(GPluginModuleClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : line = instance à initialiser. * +* * +* Description : Initialise une instance de greffon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_plugin_module_init(GPluginModule *line) +{ + +} + + + +/****************************************************************************** +* * +* Paramètres : filename = nom du fichier à charger. * +* ref = espace de référencement global. * +* * +* Description : Crée un module pour un greffon donné. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref) +{ + GPluginModule *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); + + + result->module = g_module_open(filename, G_MODULE_BIND_LAZY); + + + if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) + { + printf("Err plugin init sym\n"); + /* TODO */ + } + + + + if (!result->init(ref)) + printf("Err loading pg\n"); + + return result; + +} diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h new file mode 100644 index 0000000..6013e21 --- /dev/null +++ b/src/plugins/plugin.h @@ -0,0 +1,56 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * plugin.h - prototypes pour les interactions avec un greffon donné + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PLUGIN_H +#define _PLUGINS_PLUGIN_H + + +#include + + + +/* Greffon pour OpenIDA (instance) */ +typedef struct _GPluginModule GPluginModule; + +/* Greffon pour OpenIDA (classe) */ +typedef struct _GPluginModuleClass GPluginModuleClass; + + +#define G_TYPE_PLUGIN_MODULE (g_plugin_module_get_type()) +#define G_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PLUGIN_MODULE, GPluginModule)) +#define G_IS_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PLUGIN_MODULE)) +#define G_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PLUGIN_MODULE, GPluginModuleClass)) +#define G_IS_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PLUGIN_MODULE)) +#define G_PLUGIN_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PLUGIN_MODULE, GPluginModuleClass)) + + +/* Indique le type définit pour un greffon. */ +GType g_plugin_module_get_type(void); + +/* Crée un module pour un greffon donné. */ +GPluginModule *g_plugin_module_new(const gchar *, GObject *); + + + +#endif /* _PLUGINS_PLUGIN_H */ diff --git a/src/plugins/pyoida/Makefile.am b/src/plugins/pyoida/Makefile.am new file mode 100644 index 0000000..4df2820 --- /dev/null +++ b/src/plugins/pyoida/Makefile.am @@ -0,0 +1,20 @@ + +lib_LTLIBRARIES = libpyoida.la + +libpyoida_la_SOURCES = \ + py_binary.h py_binary.c \ + py_line.h py_line.c \ + py_log.h py_log.c \ + pyoida.h pyoida.c + +libpyoida_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \ + -L../../panel/.libs -lpanel + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/src/plugins/pyoida/linsyscalls/oidapgi.py b/src/plugins/pyoida/linsyscalls/oidapgi.py new file mode 100755 index 0000000..dd4e010 --- /dev/null +++ b/src/plugins/pyoida/linsyscalls/oidapgi.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import pyoida +#import oidaline +from pyoida import Noddy + + +class OpenIDAPlugin: + """A simple example class""" + + + + + +if __name__ == "__main__": + print "OpenIDA PlugIn" + + + print "Hello World\n", + + pyoida.system("ls -lh") + + test = Noddy("first", "last") + + print test.name() + + #oidaline.echo() + diff --git a/src/plugins/pyoida/py_binary.c b/src/plugins/pyoida/py_binary.c new file mode 100644 index 0000000..eb2a73d --- /dev/null +++ b/src/plugins/pyoida/py_binary.c @@ -0,0 +1,358 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_binary.c - intermédiaire des binaires pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_binary.h" + +#include + + + +#include "py_line.h" + + + +typedef struct { + PyObject_HEAD + + openida_binary *binary; /* Instance réelle rattachée */ + +} pybinary; + + +#define _(str) str + + + + + +/* Fournit la description du type 'binary' pour Python. */ +PyTypeObject *pybinary_get_type(void); + + + + +/* Fournit les lignes de rendu associé pour Python. */ +static PyObject *pybinary_get_lines(pybinary *); + + + + + + + +static void +pybinary_dealloc(pybinary* self) +{ +#if 0 + Py_XDECREF(self->first); + Py_XDECREF(self->last); +#endif + + //printf("dealloc\n"); + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //printf("dealloc::end\n"); + +} + +static PyObject * +pybinary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pybinary *self; + + + printf("creating a new binary\n"); + + self = (pybinary *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + +/****************************************************************************** +* * +* Paramètres : binary = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pybinary_new_from_existing(openida_binary *binary) +{ + pybinary *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + type = pybinary_get_type(); + + result = (pybinary *)type->tp_alloc(type, 0); + + if (result != NULL) + result->binary = binary; + + return (PyObject *)result; + +} + + + + +static int +pybinary_init(pybinary *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pybinary_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + + + + + +static PyMemberDef pybinary_members[] = { +#if 0 + {"number", T_INT, offsetof(pybinary, number), 0, + "noddy number"}, +#endif + {NULL} /* Sentinel */ +}; + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Fournit les lignes de rendu associé pour Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pybinary_get_lines(pybinary *self) +{ + PyObject *result; /* Liste à retourner */ + GRenderingLine *lines; /* Liste récupérée à convertir */ + + lines = get_openida_binary_lines(self->binary); + + result = pyline_new_from_existing(lines, lines); + + return result; + +} + + + + +#if 0 +static PyObject * +pybinary_name(pybinary* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} +#endif + +static PyMethodDef pybinary_methods[] = { +#if 0 + {"name", (PyCFunction)pybinary_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + { "lines", (PyCFunction)pybinary_get_lines, METH_NOARGS, + "Provide a list of associated rendering lines." + }, + {NULL} /* Sentinel */ +}; + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'binary' pour Python. * +* * +* Retour : Adresse de la description du type 'binary'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pybinary_get_type(void) +{ + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pybinary", /* tp_name */ + sizeof(pybinary), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pybinary_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pybinary objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pybinary_methods, /* tp_methods */ + pybinary_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pybinary_init, /* tp_init */ + 0, /* tp_alloc */ + pybinary_new, /* tp_new */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'binary' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_binary_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(pybinary_get_type()) < 0) + return false; + + printf("Adding binary type\n"); + + + + Py_INCREF(pybinary_get_type()); + PyModule_AddObject(module, "binary", (PyObject *)pybinary_get_type()); + + + return true; /* FIXME */ + + +} diff --git a/src/plugins/pyoida/py_binary.h b/src/plugins/pyoida/py_binary.h new file mode 100644 index 0000000..1b9fda4 --- /dev/null +++ b/src/plugins/pyoida/py_binary.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_binary.h - prototypes pour l'intermédiaire des binaires pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_BINARY_H +#define _PLUGINS_PYOIDA_PY_BINARY_H + + +#include +#include + + +#include "../../analysis/binary.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pybinary_new_from_existing(openida_binary *); + +/* Ajoute l'objet 'binary' au module Python. */ +bool add_binary_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_BINARY_H */ diff --git a/src/plugins/pyoida/py_line.c b/src/plugins/pyoida/py_line.c new file mode 100644 index 0000000..303d155 --- /dev/null +++ b/src/plugins/pyoida/py_line.c @@ -0,0 +1,802 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.c - intermédiaire des lignes de représentation pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_line.h" + +#include + + + +#include "../../analysis/line_code.h" + + + + +typedef struct { + PyObject_HEAD + + GRenderingLine *head; + + GRenderingLine *line; /* Instance réelle rattachée */ + +} pyline; + + +#define _(str) str + + + + + +/* Fournit la description du type 'line' pour Python. */ +PyTypeObject *pyline_get_type(void); + + + + +/* Prépare un parcours de lignes. */ +static PyObject *pyline_get_iter(pyline *); + + + + +/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ + + +/* Itérateur pour lignes de rendu */ +typedef struct _PyLineIter +{ + PyObject_HEAD /* A laisser en premier */ + + GRenderingLine *head; /* Liste à parcourir */ + GRenderingLine *cur; /* Point de parcours courant */ + +} PyLineIter; + + +/* Fournit la description de l'itérateur 'PyLine' pour Python. */ +static PyTypeObject *pylineiter_get_type(void); + +/* Prépare l'itérateur pour un parcours de lignes de rendu. */ +static PyObject *pylineiter_new(GRenderingLine *); + +/* Libère la mémoire occupée par un itérateur de 'PyLine'. */ +static void pylineiter_dealloc(PyLineIter *); + +/* Fournit l'élément suivant dans un parcours de lignes. */ +static PyObject *pylineiter_get_next(PyLineIter *); + + + + +/* ---------------------- EQUIVALENT PYTHON DES LIGNES DE CODE ---------------------- */ + + +/* Représentation Python d'une ligne de code */ +typedef struct _PyCodeLine +{ + pyline base; /* A laisser en premier */ + +} PyCodeLine; + + +/* Fournit la description du type 'PyCodeLine' pour Python. */ +PyTypeObject *pycodeline_get_type(void); + + + +static int +pycodeline_init(pyline *self, PyObject *args, PyObject *kwds); + +static PyObject * +pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds); + + + +PyObject *pycodeline_new_from_existing(GRenderingLine *head, GRenderingLine *line); + + + + + + + + +static void +pyline_dealloc(pyline* self) +{ +#if 0 + Py_XDECREF(self->first); + Py_XDECREF(self->last); +#endif + + //printf("dealloc\n"); + + + g_object_set_data(G_OBJECT(self->line), "pyline", NULL); + + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //printf("dealloc::end\n"); + +} + +static PyObject * +pyline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pyline *self; + + + printf("creating a new line\n"); + + self = (pyline *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + +/****************************************************************************** +* * +* Paramètres : head = ???? * +* line = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pyline_new_from_existing(GRenderingLine *head, GRenderingLine *line) +{ + pyline *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + result = (pyline *)g_object_get_data(G_OBJECT(line), "pyline"); + + if (result == NULL) + { + if (G_IS_CODE_LINE(line)) + result = pycodeline_new_from_existing(head, line); + + else + { + type = pyline_get_type(); + + result = (pyline *)type->tp_alloc(type, 0); + + if (result != NULL) + { + result->head = head; + result->line = line; + + g_object_set_data(G_OBJECT(line), "pyline", result); + + } + + } + + } + + return (PyObject *)result; + +} + + + + +static int +pyline_init(pyline *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pyline_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + + + + + +static PyMemberDef pyline_members[] = { +#if 0 + {"number", T_INT, offsetof(pyline, number), 0, + "noddy number"}, +#endif + {NULL} /* Sentinel */ +}; + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Prépare un parcours de lignes. * +* * +* Retour : Point de départ d'un parcours. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pyline_get_iter(pyline *self) +{ + printf(" get iter -- %p\n", self->line); + + return (PyObject *)pylineiter_new(self->head); + +} + + + + + + +#if 0 +static PyObject * +pyline_name(pyline* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} +#endif + +static PyMethodDef pyline_methods[] = { +#if 0 + {"name", (PyCFunction)pyline_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + {NULL} /* Sentinel */ +}; + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'line' pour Python. * +* * +* Retour : Adresse de la description du type 'line'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pyline_get_type(void) +{ + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pyline", /* tp_name */ + sizeof(pyline), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pyline_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pyline objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)pyline_get_iter, /* tp_iter */ + 0, /* tp_iternext */ + pyline_methods, /* tp_methods */ + pyline_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pyline_init, /* tp_init */ + 0, /* tp_alloc */ + pyline_new, /* tp_new */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'line' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_line_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(pyline_get_type()) < 0) + return false; + + if (PyType_Ready(pylineiter_get_type()) < 0) + return false; + + pycodeline_get_type()->tp_base = pyline_get_type(); + if (PyType_Ready(pycodeline_get_type()) < 0) + return false; + + + + + printf("Adding line type\n"); + + + + Py_INCREF(pyline_get_type()); + PyModule_AddObject(module, "line", (PyObject *)pyline_get_type()); + + Py_INCREF(pylineiter_get_type()); + PyModule_AddObject(module, "lineiter", (PyObject *)pylineiter_get_type()); + + Py_INCREF(pycodeline_get_type()); + PyModule_AddObject(module, "codeline", (PyObject *)pycodeline_get_type()); + + + return true; /* FIXME */ + + +} + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* ITERATEUR POUR LE PARCOURS DE LIGNES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description de l'itérateur 'PyLine' pour Python. * +* * +* Retour : Adresse de la description du type 'PyLineIter'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyTypeObject *pylineiter_get_type(void) +{ + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /* ob_size */ +#endif + + "PyOIDA.PyLineIter", /* tp_name */ + sizeof(PyLineIter), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pylineiter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Pylineiter objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)pylineiter_get_next, /* tp_iternext */ + 0, /* tp_methods */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : head = liste à parcourir. * +* * +* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * +* * +* Retour : Instance d'itérateur prête à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pylineiter_new(GRenderingLine *head) +{ + PyLineIter *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + type = pylineiter_get_type(); + + result = (PyLineIter *)type->tp_alloc(type, 0); + + if (result != NULL) + { + result->head = head; + result->cur = NULL; + } + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance d'objet à supprimer. * +* * +* Description : Libère la mémoire occupée par un itérateur de 'PyLine'. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void pylineiter_dealloc(PyLineIter *self) +{ + self->ob_type->tp_free((PyObject *)self); + //Py_TYPE(self)->tp_free((PyObject *)self); + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Fournit l'élément suivant dans un parcours de lignes. * +* * +* Retour : Point suivant du parcours ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pylineiter_get_next(PyLineIter *self) +{ + PyObject *result; /* Elément à retourner */ + GRenderingLine *next; /* Elément réel suivant */ + + if (self->cur == NULL) next = self->head; + else next = g_rendering_line_get_next_iter(self->head, self->cur); + + printf(" next for %p is :: %p\n", self->cur, next); + + if (next != NULL) + { + self->cur = next; + result = pyline_new_from_existing(self->head, next); + } + + else result = NULL; + + return (PyObject *)result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* EQUIVALENT PYTHON DES LIGNES DE CODE */ +/* ---------------------------------------------------------------------------------- */ + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'PyCodeLine' pour Python. * +* * +* Retour : Adresse de la description du type 'PyCodeLine'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pycodeline_get_type(void) +{ + static PyMethodDef pycodeline_methods[] = { +#if 0 + {"name", (PyCFunction)pyline_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + {NULL} /* Sentinel */ +}; + + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "PyOIDA.PyCodeLine", /* tp_name */ + sizeof(PyCodeLine), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pycodeline objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pycodeline_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pycodeline_init, /* tp_init */ + 0, /* tp_alloc */ + pycodeline_new, /* tp_new */ + }; + + return &result; + +} + + + + + +static int +pycodeline_init(pyline *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pyline_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + + + +static PyObject * +pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pyline *self; + + + printf("creating a new line\n"); + + self = (pyline *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + +/****************************************************************************** +* * +* Paramètres : head = ???? * +* line = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pycodeline_new_from_existing(GRenderingLine *head, GRenderingLine *line) +{ + pyline *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + result = (pyline *)g_object_get_data(G_OBJECT(line), "pyline"); + + if (result == NULL) + { + type = pycodeline_get_type(); + + result = (pyline *)type->tp_alloc(type, 0); + + if (result != NULL) + { + result->head = head; + result->line = line; + + g_object_set_data(G_OBJECT(line), "pyline", result); + + } + + } + + return (PyObject *)result; + +} diff --git a/src/plugins/pyoida/py_line.h b/src/plugins/pyoida/py_line.h new file mode 100644 index 0000000..2270de6 --- /dev/null +++ b/src/plugins/pyoida/py_line.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.h - prototypes pour l'intermédiaire des lignes de représentation pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LINE_H +#define _PLUGINS_PYOIDA_PY_LINE_H + + +#include +#include + + +#include "../../analysis/line.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pyline_new_from_existing(GRenderingLine *, GRenderingLine *); + +/* Ajoute l'objet 'line' au module Python. */ +bool add_line_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LINE_H */ diff --git a/src/plugins/pyoida/py_log.c b/src/plugins/pyoida/py_log.c new file mode 100644 index 0000000..94be1f0 --- /dev/null +++ b/src/plugins/pyoida/py_log.c @@ -0,0 +1,341 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_log.c - intermédiaire du panneau de messages pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_log.h" + +#include + + +#include "../../panel/log.h" + + +typedef struct { + PyObject_HEAD + PyObject *first; + PyObject *last; + int number; +} pylog; + + +#define _(str) str + + + + +/* Définit les constantes pour les types de message. */ +bool pylog_define_constants(PyObject *); + +/* Affiche un message dans le journal des messages système. */ +PyObject *pylog_simple_message(PyObject *, PyObject *); + + + + +/****************************************************************************** +* * +* Paramètres : dict = dictionnaire à compléter. * +* * +* Description : Définit les constantes pour les types de message. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool pylog_define_constants(PyObject *dict) +{ + int ret; /* Bilan d'un ajout */ + + ret = PyDict_SetItemString(dict, "LMT_INFO", PyInt_FromLong(LMT_INFO)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "LMT_BAD_BINARY", PyInt_FromLong(LMT_BAD_BINARY)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "LMT_PROCESS", PyInt_FromLong(LMT_PROCESS)); + if (ret == -1) return false; + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pylog_simple_message(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + LogMessageType type; /* Espèce du message */ + const char *msg; /* Contenu du message */ + + if (!PyArg_ParseTuple(args, "is", &type, &msg)) + return NULL; + + switch (type) + { + case LMT_INFO: + case LMT_BAD_BINARY: + case LMT_PROCESS: + log_simple_message(type, msg); + result = Py_None; + break; + + default: + PyErr_SetString(PyExc_ValueError, + _("Invalid type of message")); + result = NULL; + break; + + } + + return result; + +} + + + + + + + + + + +static void +pylog_dealloc(pylog* self) +{ + Py_XDECREF(self->first); + Py_XDECREF(self->last); + + + //printf("dealloc\n"); + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //printf("dealloc::end\n"); + +} + +static PyObject * +pylog_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pylog *self; + + self = (pylog *)type->tp_alloc(type, 0); + if (self != NULL) { + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; + } + + return (PyObject *)self; +} + +static int +pylog_init(pylog *self, PyObject *args, PyObject *kwds) +{ + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pylog_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } + + return 0; +} + +static PyMemberDef pylog_members[] = { + {"number", T_INT, offsetof(pylog, number), 0, + "noddy number"}, + {NULL} /* Sentinel */ +}; + + + + + + + + + + +static PyObject * +pylog_name(pylog* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} + +static PyMethodDef pylog_methods[] = { + {"name", (PyCFunction)pylog_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, + { "log_simple_message", (PyCFunction)pylog_simple_message, METH_VARARGS | METH_STATIC, + "Return the name, combining the first and last name" + }, + {NULL} /* Sentinel */ +}; + + +static PyTypeObject pylog_type = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pylog", /* tp_name */ + sizeof(pylog), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pylog_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pylog objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pylog_methods, /* tp_methods */ + pylog_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pylog_init, /* tp_init */ + 0, /* tp_alloc */ + pylog_new, /* tp_new */ +}; + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'log' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_log_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(&pylog_type) < 0) + return; + + printf("Adding log type\n"); + + + pylog_define_constants(pylog_type.tp_dict); + + + + + Py_INCREF(&pylog_type); + PyModule_AddObject(module, "logger", (PyObject *)&pylog_type); + + + return true; /* FIXME */ + + +} diff --git a/src/plugins/pyoida/py_log.h b/src/plugins/pyoida/py_log.h new file mode 100644 index 0000000..5274428 --- /dev/null +++ b/src/plugins/pyoida/py_log.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_log.h - prototypes pour l'intermédiaire du panneau de messages pour 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LOG_H +#define _PLUGINS_PYOIDA_PY_LOG_H + + +#include +#include + + + +/* Ajoute l'objet 'log' au module Python. */ +bool add_log_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LOG_H */ diff --git a/src/plugins/pyoida/pyoida.c b/src/plugins/pyoida/pyoida.c new file mode 100644 index 0000000..26624b2 --- /dev/null +++ b/src/plugins/pyoida/pyoida.c @@ -0,0 +1,131 @@ + +/* 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 . + */ + + +#include "pyoida.h" + + + +#include + + +#include "py_binary.h" +#include "py_log.h" + + +static GObject *_ref = NULL; + + + +static PyObject *pyoida_get_current_binary(PyObject *self, PyObject *args) +{ + openida_binary *binary; /* Structure à copier */ + + binary = (openida_binary *)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) +{ + + printf("Init pyoida\n"); + + _ref = ref; + + 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 */ + + +PyMODINIT_FUNC +initpyoida(void) +{ + PyObject *module; + + + printf("Passage 2\n"); + module = Py_InitModule("pyoida", SpamMethods); + + add_binary_to_python_module(module); + add_line_to_python_module(module); + add_log_to_python_module(module); + +} + +#endif diff --git a/src/plugins/pyoida/pyoida.h b/src/plugins/pyoida/pyoida.h new file mode 100644 index 0000000..736db8e --- /dev/null +++ b/src/plugins/pyoida/pyoida.h @@ -0,0 +1,38 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pyoida.h - prototypes pour le 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 . + */ + + +#ifndef _PLUGINS_PYOIDA_H +#define _PLUGINS_PYOIDA_H + + +#include +#include + + + +/* Initialise le greffon permettant l'usage de Python. */ +bool init_plugin(GObject *); + + + +#endif /* _PLUGINS_PYOIDA_H */ diff --git a/src/project.c b/src/project.c index 2ec9e09..20ec7c3 100644 --- a/src/project.c +++ b/src/project.c @@ -30,9 +30,9 @@ #include -#include "easygtk.h" #include "xdg.h" #include "xml.h" +#include "gtkext/easygtk.h" diff --git a/src/project.h b/src/project.h index a08039d..64c32bd 100644 --- a/src/project.h +++ b/src/project.h @@ -25,7 +25,7 @@ #define _PROJECT_H -#include "binary.h" +#include "analysis/binary.h" diff --git a/src/shell.c b/src/shell.c new file mode 100644 index 0000000..1f8d28d --- /dev/null +++ b/src/shell.c @@ -0,0 +1,330 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * shell.c - panneau d'affichage du shell Python + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "shell.h" + + +#include +#include +#include +#include +#include +#include +#include + + +#include + + +#include + + +static pid_t child = 0; + + +#define _(str) str + + + +/* Réagit à la terminaison d'un shell Python lancé. */ +static void terminal_child_exited_cb(VteReaper *, GPid, gint, VteTerminal *); + +/* Lance un nouveau shell Python dans un terminal donné. */ +static void run_new_shell_in_terminal(VteTerminal *); + +/* Réagit aux premières lignes de l'interpréteur Python. */ +void python_started_cb(VteTerminal *, gpointer); + + + +/* Exécute un shell interprétant du Python. */ +static gpointer python_shell_thread(gpointer); + + + int amaster; + int aslave; + char name[64]; + + +/****************************************************************************** +* * +* Paramètres : ref = adresse de l'espace de référencements. * +* * +* Description : Construit le panneau d'affichage des symboles. * +* * +* Retour : Adresse du panneau mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *build_shell_panel(GObject *ref) +{ + GtkWidget *result; /* Panneau à retourner */ + GtkWidget *term; /* Terminal proprement dit */ + + + + GError *error; /* Bilan de création de thread */ + + + + term = vte_terminal_new(); + + result = gtk_scrolled_window_new(NULL, GTK_ADJUSTMENT(VTE_TERMINAL(term)->adjustment)); + gtk_widget_show(result); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN); + + gtk_widget_show(term); + gtk_container_add(GTK_CONTAINER(result), term); + + + vte_terminal_set_cursor_blinks(VTE_TERMINAL(term), TRUE); + + + //return result; + + openpty(&amaster, &aslave, name, NULL, NULL); + + + fprintf(stderr, "m = %d, s = %d, n = \"%s\"\n", amaster, + aslave, name); + + + vte_terminal_set_pty(VTE_TERMINAL(term), amaster); + + + if (!g_thread_create((GThreadFunc)python_shell_thread, term, FALSE, &error)) + { + printf ("Failed to create the thread: %s\n", error->message); + } + + + + + /* + g_signal_connect(vte_reaper_get(), "child-exited", + G_CALLBACK(terminal_child_exited_cb), term); + + + run_new_shell_in_terminal(VTE_TERMINAL(term)); + */ + + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : reaper = surveillant des processus exécuté dans le terminal. * +* pid = identifiant du processus terminé. * +* status = informations sur la sortie de l'interpréteur. * +* term = terminal affiché à l'écran. * +* * +* Description : Réagit à la terminaison d'un shell Python lancé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void terminal_child_exited_cb(VteReaper *reaper, GPid pid, gint status, VteTerminal *term) +{ + + vte_terminal_feed(term, _("Exit detected ; lauching an new Python shell...\n\r"), -1); + + + run_new_shell_in_terminal(term); + +} + + +/****************************************************************************** +* * +* Paramètres : term = terminal affiché à l'écran. * +* * +* Description : Lance un nouveau shell Python dans un terminal donné. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void run_new_shell_in_terminal(VteTerminal *term) +{ + gdouble refval; /* Attente active (bouh !) */ + size_t len; /* Longueur de chaîne */ + + char *args[] = { "python", NULL }; + +#ifdef DEBUG + char *env[] = { NULL, NULL }; +#else + char **env = NULL; +#endif + + refval = gtk_adjustment_get_value(GTK_ADJUSTMENT(term->adjustment)); + +#ifdef DEBUG + len = strlen("PYTHONPATH=") + strlen(PACKAGE_SOURCE_DIR) + strlen("/src/plugins/pyoida"); + + env[0] = (char *)calloc(len + 1, sizeof(char)); + + strcpy(env[0], "PYTHONPATH="); + strcat(env[0], PACKAGE_SOURCE_DIR); + strcat(env[0], "/src/plugins/pyoida"); +#endif + + child = vte_terminal_fork_command(VTE_TERMINAL(term), args[0], args, + env, NULL, 0, 0, 0); + + vte_reaper_add_child(child); + + printf("ref :: %g\n", refval); + + //while (refval == gtk_adjustment_get_value(GTK_ADJUSTMENT(term->adjustment))); + + + g_signal_connect(term, "contents-changed", + G_CALLBACK(python_started_cb), NULL); + +} + + +/****************************************************************************** +* * +* Paramètres : term = terminal affiché à l'écran. * +* data = adresse non utilisée ici. * +* * +* Description : Réagit aux premières lignes de l'interpréteur Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void python_started_cb(VteTerminal *term, gpointer data) +{ + static int counter = 0; /* Saut du prologue */ + + if (counter++ == 0) return; + else counter = 0; + + vte_terminal_feed_child(term, "import pyoida\n", -1); + + vte_terminal_feed_child(term, "from pyoida import *\n", -1); + + g_signal_handlers_disconnect_by_func(term, G_CALLBACK(python_started_cb), NULL); + +} + + + +/****************************************************************************** +* * +* Paramètres : ????????????????????????????????????????????????? * +* * +* Description : Exécute un shell interprétant du Python. * +* * +* Retour : ??? * +* * +* Remarques : - * +* * +******************************************************************************/ + +static gpointer python_shell_thread(gpointer data) +{ + FILE *stream; + + printf("==== FE :: '%s'\n", ptsname(aslave)); + + + + + //stream = fopen("/dev/pts/21", "w+"); + stream = fdopen(aslave, "w+"); + if (stream == NULL) + { + perror("fdopen"); + return NULL; + } + + + /* Mise à jour des entrées/sorties */ + /* + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + dup(aslave); + dup(aslave); + dup(aslave); + */ + + + + + Py_Initialize(); + + + amaster = STDIN_FILENO; + + + write(amaster, "import pyoida\n", strlen("import pyoida\n")); + write(amaster, "from pyoida import *\n", strlen("from pyoida import *\n")); + + + + + + write(amaster, "logger.log_simple_message(2, 'uhih')\n", strlen("logger.log_simple_message(2, 'uhih')\n")); + + + + write(amaster, "for i in pyoida.current_binary().lines():\n", strlen("for i in pyoida.current_binary().lines():\n")); + write(amaster, "\tprint i\n", strlen("\tprint i\n")); + + + + + printf("+++++++++++++++++++++++++++looping\n"); + + PyRun_AnyFile(stream, NULL); + + printf("===========================looping\n"); + + + Py_Finalize(); + + + + return NULL; + +} diff --git a/src/shell.h b/src/shell.h new file mode 100644 index 0000000..c07a368 --- /dev/null +++ b/src/shell.h @@ -0,0 +1,38 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * shell.h - prototypes pour le panneau d'affichage du shell Python + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PAN_SHELL_H +#define _PAN_SHELL_H + + +#include + + + +/* Construit le panneau d'affichage des symboles. */ +GtkWidget *build_shell_panel(GObject *); + + + +#endif /* _PAN_SHELL_H */ diff --git a/src/support.c b/src/support.c deleted file mode 100644 index 67e7605..0000000 --- a/src/support.c +++ /dev/null @@ -1,92 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * support.c - recherche des chemins d'accès aux fichiers - * - * Copyright (C) 2008-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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "support.h" - - -#include -#include - - - -/* Liste des répertoires contenant des images */ -static GList *pixmaps_directories = NULL; - - - -/****************************************************************************** -* * -* Paramètres : directory = nouveau répertoire à parcourir. * -* * -* Description : Ajoute un répertoire à la liste des répertoires d'images. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void add_pixmap_directory(const char *directory) -{ - pixmaps_directories = g_list_prepend(pixmaps_directories, - strdup(directory)); - -} - - -/****************************************************************************** -* * -* Paramètres : filename = nom de fichier seul comme indice. * -* * -* Description : Trouve le chemin d'accès complet à un fichier donné. * -* * -* Retour : Chemin trouvé à libérer de la mémoire ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -gchar *find_pixmap_file(const char *filename) -{ - gchar *result; /* Trouvaille à renvoyer */ - GList *iter; /* Boucle de parcours */ - - result = NULL; - - for (iter = pixmaps_directories; iter != NULL && result == NULL; iter = iter->next) - { - result = g_strdup_printf("%s%s%s", (gchar *)iter->data, - G_DIR_SEPARATOR_S, filename); - - if (!g_file_test(result, G_FILE_TEST_EXISTS)) - { - g_free(result); - result = NULL; - } - - } - - return result; - -} diff --git a/src/support.h b/src/support.h deleted file mode 100644 index 9d3373b..0000000 --- a/src/support.h +++ /dev/null @@ -1,41 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * support.h - prototypes pour la recherche des chemins d'accès aux fichiers - * - * Copyright (C) 2008-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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _SUPPORT_H -#define _SUPPORT_H - - -#include - - - -/* Ajoute un répertoire à la liste des répertoires d'images. */ -void add_pixmap_directory(const char *); - -/* Trouve le chemin d'accès complet à un fichier donné. */ -gchar *find_pixmap_file(const char *); - - - -#endif /* _SUPPORT_H */ -- cgit v0.11.2-87-g4458