diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2010-01-02 01:48:30 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2010-01-02 01:48:30 (GMT) | 
| commit | 2d95ce74200c8cb7c328535235a8c8e74686794e (patch) | |
| tree | 6e006e9b43b022a40ba53c58ed1f39be5327f880 /src/format/elf | |
| parent | 7468875c1022337efbff78069d715672ae083150 (diff) | |
Provided ways to load, save and edit some binary parts selection.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@141 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf')
| -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 | 
3 files changed, 76 insertions, 1 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 *);  | 
