diff options
Diffstat (limited to 'src/format')
| -rw-r--r-- | src/format/elf/elf.c | 34 | ||||
| -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 | 6 | ||||
| -rw-r--r-- | src/format/executable.c | 23 | ||||
| -rw-r--r-- | src/format/executable.h | 3 | ||||
| -rw-r--r-- | src/format/part.c | 29 | ||||
| -rw-r--r-- | src/format/part.h | 3 | 
8 files changed, 138 insertions, 3 deletions
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c index 878bf51..b703dcf 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 la position correspondant à une adresse virtuelle. */ +static bool g_elf_format_translate_address_into_offset(const GElfFormat *, vmpa_t, off_t *); +  /* Fournit l'adresse virtuelle correspondant à une position. */  static bool g_elf_format_translate_offset_into_address(const GElfFormat *, off_t, vmpa_t *); @@ -139,7 +142,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; +    exe_format->translate_addr = (translate_addr_fc)g_elf_format_translate_address_into_offset; +    exe_format->translate_off = (translate_off_fc)g_elf_format_translate_offset_into_address;  } @@ -496,6 +500,34 @@ static GBinPart **g_elf_format_get_parts(const GElfFormat *format, size_t *count  /******************************************************************************  *                                                                             *  *  Paramètres  : format  = description de l'exécutable à consulter.           * +*                addr    = adresse virtuelle à retrouver.                     * +*                pos     = position correspondante. [OUT]                     * +*                                                                             * +*  Description : Fournit la position correspondant à une adresse virtuelle.   * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_elf_format_translate_address_into_offset(const GElfFormat *format, vmpa_t addr, off_t *pos) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = translate_address_into_offset_using_elf_sections(format, addr, pos); + +    if (!result) +        /* TODO : prgm... */; + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           *  *                pos     = position dans le flux binaire à retrouver.         *  *                addr    = adresse virtuelle correspondante. [OUT]            *  *                                                                             * diff --git a/src/format/elf/section.c b/src/format/elf/section.c index b8d6a50..cb6a04a 100644 --- a/src/format/elf/section.c +++ b/src/format/elf/section.c @@ -280,6 +280,46 @@ const char *extract_name_from_elf_string_section(const GElfFormat *format, const  /******************************************************************************  *                                                                             *  *  Paramètres  : format  = description de l'exécutable à consulter.           * +*                addr    = adresse virtuelle à retrouver.                     * +*                pos     = position correspondante. [OUT]                     * +*                                                                             * +*  Description : Fournit la position correspondant à une adresse virtuelle.   * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool translate_address_into_offset_using_elf_sections(const GElfFormat *format, vmpa_t addr, off_t *pos) +{ +    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_addr) <= addr +            && addr < (ELF_SHDR(format, section, sh_addr) + ELF_SHDR(format, section, sh_size))) +        { +            *pos = ELF_SHDR(format, section, sh_offset) + addr - ELF_SHDR(format, section, sh_addr); +            result = true; +        } + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           *  *                pos     = position dans le flux binaire à retrouver.         *  *                addr    = adresse virtuelle correspondante. [OUT]            *  *                                                                             * diff --git a/src/format/elf/section.h b/src/format/elf/section.h index ca91097..811e32b 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 la position correspondant à une adresse virtuelle. */ +bool translate_address_into_offset_using_elf_sections(const GElfFormat *, vmpa_t, off_t *); +  /* Fournit l'adresse virtuelle correspondant à une position. */  bool translate_offset_into_address_using_elf_sections(const GElfFormat *, off_t, vmpa_t *); diff --git a/src/format/executable-int.h b/src/format/executable-int.h index e4b18a4..224e193 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 la position correspondant à une adresse virtuelle. */ +typedef bool (* translate_addr_fc) (const GExeFormat *, vmpa_t, off_t *); +  /* Fournit l'adresse virtuelle correspondant à une position. */  typedef bool (* translate_off_fc) (const GExeFormat *, off_t, vmpa_t *); @@ -56,7 +59,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  */ +    translate_addr_fc translate_addr;       /* Correspondance addr -> pos  */ +    translate_off_fc translate_off;         /* Correspondance pos -> addr  */  }; diff --git a/src/format/executable.c b/src/format/executable.c index 4af587f..76efaa1 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -147,6 +147,27 @@ GBinPart **g_exe_format_get_parts(const GExeFormat *format, size_t *count)  /******************************************************************************  *                                                                             *  *  Paramètres  : format  = description de l'exécutable à consulter.           * +*                addr    = adresse virtuelle à retrouver.                     * +*                pos     = position correspondante. [OUT]                     * +*                                                                             * +*  Description : Fournit la position correspondant à une adresse virtuelle.   * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_exe_format_translate_address_into_offset(const GExeFormat *format, vmpa_t addr, off_t *pos) +{ +    return format->translate_addr(format, addr, pos); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format  = description de l'exécutable à consulter.           *  *                pos     = position dans le flux binaire à retrouver.         *  *                addr    = adresse virtuelle correspondante. [OUT]            *  *                                                                             * @@ -160,6 +181,6 @@ GBinPart **g_exe_format_get_parts(const GExeFormat *format, size_t *count)  bool g_exe_format_translate_offset_into_address(const GExeFormat *format, off_t pos, vmpa_t *addr)  { -    return format->translate(format, pos, addr); +    return format->translate_off(format, pos, addr);  } diff --git a/src/format/executable.h b/src/format/executable.h index 4d3f759..2042df4 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 la position correspondant à une adresse virtuelle. */ +bool g_exe_format_translate_address_into_offset(const GExeFormat *, vmpa_t, off_t *); +  /* Fournit l'adresse virtuelle correspondant à une position. */  bool g_exe_format_translate_offset_into_address(const GExeFormat *, off_t, vmpa_t *); diff --git a/src/format/part.c b/src/format/part.c index 63747d9..006cb75 100644 --- a/src/format/part.c +++ b/src/format/part.c @@ -124,6 +124,35 @@ GBinPart *g_binary_part_new(void)  /******************************************************************************  *                                                                             * +*  Paramètres  : src = partie de code à copier.                               * +*                                                                             * +*  Description : Crée une description de partie de code à partir d'une autre. * +*                                                                             * +*  Retour      : Partie de code copiée.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GBinPart *g_binary_part_dump(const GBinPart *src) +{ +    GBinPart *result;                   /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_BIN_PART, NULL); + +    result->name = (src->name != NULL ? strdup(src->name) : NULL); + +    result->offset = result->offset; +    result->size = result->size; +    result->addr = result->addr; + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : node = noeud XML contenant les données à charger.            *  *                                                                             *  *  Description : Crée une description de partie de code vierge à partir d'XML.* diff --git a/src/format/part.h b/src/format/part.h index 5c1c904..32d1903 100644 --- a/src/format/part.h +++ b/src/format/part.h @@ -55,6 +55,9 @@ 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 à partir d'une autre. */ +GBinPart *g_binary_part_dump(const GBinPart *); +  /* Crée une description de partie de code vierge à partir d'XML. */  GBinPart *g_binary_part_load_from_xml(xmlNodePtr);  | 
