diff options
Diffstat (limited to 'src/format')
| -rw-r--r-- | src/format/Makefile.am | 2 | ||||
| -rw-r--r-- | src/format/elf/Makefile.am | 2 | ||||
| -rw-r--r-- | src/format/elf/elf.c | 33 | ||||
| -rw-r--r-- | src/format/elf/section.c | 40 | ||||
| -rw-r--r-- | src/format/elf/section.h | 3 | ||||
| -rw-r--r-- | src/format/executable-int.h | 5 | ||||
| -rw-r--r-- | src/format/executable.c | 21 | ||||
| -rw-r--r-- | src/format/executable.h | 3 | ||||
| -rwxr-xr-x | src/format/java/Makefile.am | 2 | ||||
| -rw-r--r-- | src/format/part.c | 99 | ||||
| -rw-r--r-- | src/format/part.h | 10 | ||||
| -rwxr-xr-x | src/format/pe/Makefile.am | 2 | 
12 files changed, 218 insertions, 4 deletions
| diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 9bfdd92..838cb99 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -35,7 +35,7 @@ libformat_la_LIBADD =					\  libformat_la_LDFLAGS =  -INCLUDES = $(LIBGTK_CFLAGS) +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)  AM_CPPFLAGS =  diff --git a/src/format/elf/Makefile.am b/src/format/elf/Makefile.am index 1e18356..f524bdf 100644 --- a/src/format/elf/Makefile.am +++ b/src/format/elf/Makefile.am @@ -15,7 +15,7 @@ libformatelf_la_SOURCES =				\  libformatelf_la_LDFLAGS =  -INCLUDES = $(LIBGTK_CFLAGS) +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)  AM_CPPFLAGS =  diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c index f32bce7..878bf51 100644 --- a/src/format/elf/elf.c +++ b/src/format/elf/elf.c @@ -62,6 +62,9 @@ static vmpa_t g_elf_format_get_entry_point(const GElfFormat *);  /* Fournit les références aux zones binaires à analyser. */  static GBinPart **g_elf_format_get_parts(const GElfFormat *, size_t *); +/* Fournit l'adresse virtuelle correspondant à une position. */ +static bool g_elf_format_translate_offset_into_address(const GElfFormat *, off_t, vmpa_t *); +  /****************************************************************************** @@ -136,6 +139,8 @@ static void g_elf_format_init(GElfFormat *format)      exe_format->get_entry_point = (get_entry_point_fc)g_elf_format_get_entry_point;      exe_format->get_parts = (get_parts_fc)g_elf_format_get_parts; +    exe_format->translate = (translate_off_fc)g_elf_format_translate_offset_into_address; +  } @@ -486,3 +491,31 @@ static GBinPart **g_elf_format_get_parts(const GElfFormat *format, size_t *count      return result;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           * +*                pos     = position dans le flux binaire à retrouver.         * +*                addr    = adresse virtuelle correspondante. [OUT]            * +*                                                                             * +*  Description : Fournit l'adresse virtuelle correspondant à une position.    * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_elf_format_translate_offset_into_address(const GElfFormat *format, off_t pos, vmpa_t *addr) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = translate_offset_into_address_using_elf_sections(format, pos, addr); + +    if (!result) +        /* TODO : prgm... */; + +    return result; + +} diff --git a/src/format/elf/section.c b/src/format/elf/section.c index f837dbf..b8d6a50 100644 --- a/src/format/elf/section.c +++ b/src/format/elf/section.c @@ -275,3 +275,43 @@ const char *extract_name_from_elf_string_section(const GElfFormat *format, const      return result;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           * +*                pos     = position dans le flux binaire à retrouver.         * +*                addr    = adresse virtuelle correspondante. [OUT]            * +*                                                                             * +*  Description : Fournit l'adresse virtuelle correspondant à une position.    * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool translate_offset_into_address_using_elf_sections(const GElfFormat *format, off_t pos, vmpa_t *addr) +{ +    bool result;                            /* Bilan à retourner           */ +    uint16_t i;                             /* Boucle de parcours          */ +    elf_shdr section;                       /* Section à analyser          */ + +    result = false; + +    for (i = 0; i < format->header.e_shnum && !result; i++) +    { +        find_elf_section_by_index(format, i, §ion); + +        if (ELF_SHDR(format, section, sh_offset) <= pos +            && pos < (ELF_SHDR(format, section, sh_offset) + ELF_SHDR(format, section, sh_size))) +        { +            *addr = ELF_SHDR(format, section, sh_addr) + pos - ELF_SHDR(format, section, sh_offset); +            result = true; +        } + +    } + +    return result; + +} diff --git a/src/format/elf/section.h b/src/format/elf/section.h index bc952a4..ca91097 100644 --- a/src/format/elf/section.h +++ b/src/format/elf/section.h @@ -51,6 +51,9 @@ bool find_elf_section_content_by_name(const GElfFormat *, const char *, off_t *,  /* Identifie une chaîne de caractères dans une section adéquate. */  const char *extract_name_from_elf_string_section(const GElfFormat *, const elf_shdr *, off_t); +/* Fournit l'adresse virtuelle correspondant à une position. */ +bool translate_offset_into_address_using_elf_sections(const GElfFormat *, off_t, vmpa_t *); +  #endif  /* _FORMAT_ELF_SECTION_H */ diff --git a/src/format/executable-int.h b/src/format/executable-int.h index ca8b7d5..e4b18a4 100644 --- a/src/format/executable-int.h +++ b/src/format/executable-int.h @@ -41,6 +41,9 @@ typedef vmpa_t (* get_entry_point_fc) (const GExeFormat *);  /* Fournit les références aux zones de code à analyser. */  typedef GBinPart ** (* get_parts_fc) (const GExeFormat *, size_t *); +/* Fournit l'adresse virtuelle correspondant à une position. */ +typedef bool (* translate_off_fc) (const GExeFormat *, off_t, vmpa_t *); + @@ -53,6 +56,8 @@ struct _GExeFormat      get_entry_point_fc get_entry_point;     /* Obtention du point d'entrée */      get_parts_fc get_parts;                 /* Liste des parties binaires  */ +    translate_off_fc translate;             /* Correspondance pos -> addr  */ +  };  /* Format d'exécutable générique (classe) */ diff --git a/src/format/executable.c b/src/format/executable.c index 4fb6b41..4af587f 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -142,3 +142,24 @@ GBinPart **g_exe_format_get_parts(const GExeFormat *format, size_t *count)      return format->get_parts(format, count);  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           * +*                pos     = position dans le flux binaire à retrouver.         * +*                addr    = adresse virtuelle correspondante. [OUT]            * +*                                                                             * +*  Description : Fournit l'adresse virtuelle correspondant à une position.    * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_exe_format_translate_offset_into_address(const GExeFormat *format, off_t pos, vmpa_t *addr) +{ +    return format->translate(format, pos, addr); + +} diff --git a/src/format/executable.h b/src/format/executable.h index bf3269d..4d3f759 100644 --- a/src/format/executable.h +++ b/src/format/executable.h @@ -75,6 +75,9 @@ vmpa_t g_exe_format_get_entry_point(const GExeFormat *);  /* Fournit les références aux zones binaires à analyser. */  GBinPart **g_exe_format_get_parts(const GExeFormat *, size_t *); +/* Fournit l'adresse virtuelle correspondant à une position. */ +bool g_exe_format_translate_offset_into_address(const GExeFormat *, off_t, vmpa_t *); +  #endif  /* _FORMAT_EXECUTABLE_H */ diff --git a/src/format/java/Makefile.am b/src/format/java/Makefile.am index 46bee9e..1ad2c67 100755 --- a/src/format/java/Makefile.am +++ b/src/format/java/Makefile.am @@ -12,7 +12,7 @@ libformatjava_la_SOURCES =				\  libformatjava_la_LDFLAGS =  -INCLUDES = $(LIBGTK_CFLAGS) +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)  AM_CPPFLAGS =  diff --git a/src/format/part.c b/src/format/part.c index d21cd87..63747d9 100644 --- a/src/format/part.c +++ b/src/format/part.c @@ -25,6 +25,7 @@  #include <malloc.h> +#include <stdlib.h>  #include <string.h> @@ -123,6 +124,84 @@ GBinPart *g_binary_part_new(void)  /******************************************************************************  *                                                                             * +*  Paramètres  : node = noeud XML contenant les données à charger.            * +*                                                                             * +*  Description : Crée une description de partie de code vierge à partir d'XML.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GBinPart *g_binary_part_load_from_xml(xmlNodePtr node) +{ +    GBinPart *result;                   /* Structure à retourner       */ +    char *value;                        /* Propriété lue depuis le XML */ + +    result = g_binary_part_new(); + +    result->name = qck_get_node_prop_value(node, "name"); +    if (result->name == NULL) goto gbplfx_error; + +    value = qck_get_node_prop_value(node, "offset"); +    if (value == NULL) goto gbplfx_error; + +    result->offset = atoi(value); +    free(value); + +    value = qck_get_node_prop_value(node, "size"); +    if (value == NULL) goto gbplfx_error; + +    result->size = atoi(value); +    free(value); + +    return result; + + gbplfx_error: + +    g_object_unref(G_OBJECT(result)); + +    return NULL; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : part   = description de partie à sauvegarder.                * +*                xdoc   = structure XML chargée.                              * +*                parent = noeud XML où rattacher le futur nouveau noeud.      * +*                                                                             * +*  Description : Enregistre les informations d'une partie de code dans du XML.* +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_binary_part_save_to_xml(const GBinPart *part, xmlDocPtr xdoc, xmlNodePtr parent) +{ +    bool result;                            /* Bilan à retourner           */ +    xmlNodePtr node;                        /* Nouveau noeud créé          */ + +    result = true; + +    node = add_node_to_node(xdoc, parent, "Part"); +    if (node == NULL) return false; + +    result = add_string_attribute_to_node(node, "name", part->name); +    result &= add_long_attribute_to_node(node, "offset", part->offset); +    result &= add_long_attribute_to_node(node, "size", part->size); + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : part = description de partie à mettre à jour.                *  *                name = nom à donner à la partie.                             *  *                                                                             * @@ -188,6 +267,26 @@ void g_binary_part_set_values(GBinPart *part, off_t offset, off_t size, vmpa_t a  /******************************************************************************  *                                                                             * +*  Paramètres  : part = description de partie à mettre à jour.                * +*                addr = adresse de la section à conserver.                    * +*                                                                             * +*  Description : Définit l'adresse virtuelle d'une partie de code.            * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_binary_part_set_address(GBinPart *part, vmpa_t addr) +{ +    part->addr = addr; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : part   = description de partie à consulter.                  *  *                offset = position de la section à donner ou NULL. [OUT]      *  *                size   = taille de la section à donner ou NULL. [OUT]        * diff --git a/src/format/part.h b/src/format/part.h index ff18fc9..5c1c904 100644 --- a/src/format/part.h +++ b/src/format/part.h @@ -29,6 +29,7 @@  #include <sys/types.h> +#include "../common/xml.h"  #include "../arch/archbase.h" @@ -54,6 +55,12 @@ GType g_binary_part_get_type(void);  /* Crée une description de partie de code vierge. */  GBinPart *g_binary_part_new(void); +/* Crée une description de partie de code vierge à partir d'XML. */ +GBinPart *g_binary_part_load_from_xml(xmlNodePtr); + +/* Enregistre les informations d'une partie de code dans du XML. */ +bool g_binary_part_save_to_xml(const GBinPart *, xmlDocPtr, xmlNodePtr); +  /* Attribue une description humaine à une partie de code. */  void g_binary_part_set_name(GBinPart *, const char *); @@ -63,6 +70,9 @@ const char *g_binary_part_get_name(const GBinPart *);  /* Définit les valeurs utiles d'une partie de code. */  void g_binary_part_set_values(GBinPart *, off_t, off_t, vmpa_t); +/* Définit l'adresse virtuelle d'une partie de code. */ +void g_binary_part_set_address(GBinPart *, vmpa_t); +  /* Fournit les valeurs utiles d'une partie de code. */  void g_binary_part_get_values(const GBinPart *, off_t *, off_t *, vmpa_t *); diff --git a/src/format/pe/Makefile.am b/src/format/pe/Makefile.am index a11d912..45f2f6b 100755 --- a/src/format/pe/Makefile.am +++ b/src/format/pe/Makefile.am @@ -8,7 +8,7 @@ libformatpe_la_SOURCES =				\  libformatpe_la_LDFLAGS =  -INCLUDES = $(LIBGTK_CFLAGS) +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)  AM_CPPFLAGS =  | 
