diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2018-05-24 07:43:32 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2018-05-24 07:43:32 (GMT) | 
| commit | 08c45a8c7970403c3d658b1b0af9ac09f66b4a7e (patch) | |
| tree | 25a8108e36b7328c266ba6e71647243dfd6b7cac /src/format | |
| parent | 7135e7944c91d2e8b787c8782375423b9a90ed5b (diff) | |
Translated offsets and addresses with more accuracy.
Diffstat (limited to 'src/format')
| -rw-r--r-- | src/format/executable-int.c | 74 | ||||
| -rw-r--r-- | src/format/executable-int.h | 13 | ||||
| -rw-r--r-- | src/format/executable.c | 52 | ||||
| -rw-r--r-- | src/format/executable.h | 4 | 
4 files changed, 122 insertions, 21 deletions
| diff --git a/src/format/executable-int.c b/src/format/executable-int.c index e13a7c9..d20a776 100644 --- a/src/format/executable-int.c +++ b/src/format/executable-int.c @@ -79,3 +79,77 @@ bool g_exe_format_without_virt_translate_address_into_vmpa(const GExeFormat *for      return true;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format = description de l'exécutable à consulter.            * +*                off    = position physique à retrouver.                      * +*                pos    = position correspondante. [OUT]                      * +*                                                                             * +*  Description : Fournit l'emplacement correspondant à une position physique. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_exe_format_translate_offset_into_vmpa_using_portions(GExeFormat *format, phys_t off, vmpa2t *pos) +{ +    bool result;                            /* Bilan à retourner           */ +    GBinPortion *portions;                  /* Liste de découpages         */ + +    portions = g_exe_format_get_portions(format); + +    if (portions == NULL) +        result = false; + +    else +    { +        result = g_binary_portion_translate_offset_into_vmpa(portions, off, pos); + +        g_object_unref(G_OBJECT(portions)); + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : format = description de l'exécutable à consulter.            * +*                addr   = adresse virtuelle à retrouver.                      * +*                pos    = position correspondante. [OUT]                      * +*                                                                             * +*  Description : Fournit l'emplacement correspondant à une adresse virtuelle. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_exe_format_translate_address_into_vmpa_using_portions(GExeFormat *format, virt_t addr, vmpa2t *pos) +{ +    bool result;                            /* Bilan à retourner           */ +    GBinPortion *portions;                  /* Liste de découpages         */ + +    portions = g_exe_format_get_portions(format); + +    if (portions == NULL) +        result = false; + +    else +    { +        result = g_binary_portion_translate_address_into_vmpa(portions, addr, pos); + +        g_object_unref(G_OBJECT(portions)); + +    } + +    return result; + +} diff --git a/src/format/executable-int.h b/src/format/executable-int.h index ed2c7c1..58eba25 100644 --- a/src/format/executable-int.h +++ b/src/format/executable-int.h @@ -42,10 +42,10 @@ typedef bool (* get_main_addr_fc) (GExeFormat *, vmpa2t *);  typedef void (* refine_portions_fc) (GExeFormat *);  /* Fournit l'emplacement correspondant à une position physique. */ -typedef bool (* translate_phys_fc) (const GExeFormat *, phys_t, vmpa2t *); +typedef bool (* translate_phys_fc) (GExeFormat *, phys_t, vmpa2t *);  /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -typedef bool (* translate_virt_fc) (const GExeFormat *, virt_t, vmpa2t *); +typedef bool (* translate_virt_fc) (GExeFormat *, virt_t, vmpa2t *);  /* Fournit l'emplacement d'une section donnée. */  typedef bool (* get_range_by_name_fc) (const GExeFormat *, const char *, mrange_t *); @@ -82,6 +82,9 @@ struct _GExeFormatClass  }; +/* Crée les portions potentiellement utiles aux traductions. */ +void g_executable_format_setup_portions(GExeFormat *, GtkStatusStack *); +  /* Effectue les ultimes opérations de chargement d'un binaire. */  bool g_executable_format_complete_loading(GExeFormat *, GtkStatusStack *); @@ -91,6 +94,12 @@ bool g_exe_format_without_virt_translate_offset_into_vmpa(const GExeFormat *, ph  /* Fournit l'emplacement correspondant à une adresse virtuelle. */  bool g_exe_format_without_virt_translate_address_into_vmpa(const GExeFormat *, virt_t, vmpa2t *); +/* Fournit l'emplacement correspondant à une position physique. */ +bool g_exe_format_translate_offset_into_vmpa_using_portions(GExeFormat *, phys_t, vmpa2t *); + +/* Fournit l'emplacement correspondant à une adresse virtuelle. */ +bool g_exe_format_translate_address_into_vmpa_using_portions(GExeFormat *, virt_t, vmpa2t *); +  #endif  /* _FORMAT_EXECUTABLE_INT_H */ diff --git a/src/format/executable.c b/src/format/executable.c index 0107074..a2ee569 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -289,39 +289,57 @@ bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr)  *  Paramètres  : format = instance à traiter.                                 *  *                status = barre de statut à tenir informée.                   *  *                                                                             * -*  Description : Effectue les ultimes opérations de chargement d'un binaire.  * +*  Description : Crée les portions potentiellement utiles aux traductions.    *  *                                                                             * -*  Retour      : Bilan de l'opération.                                        * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -bool g_executable_format_complete_loading(GExeFormat *format, GtkStatusStack *status) +void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *status)  { -    bool result;                            /* Bilan à faire remonter      */      GBinFormat *base;                       /* Version basique du format   */      vmpa2t addr;                            /* Emplacement vide de sens    */      phys_t length;                          /* Taille de portion globale   */      base = G_BIN_FORMAT(format); -    result = g_binary_format_complete_loading(base, status); +    /** +     * Avant de lire l'entête du format, on ne sait pas où on se trouve ! +     */ +    init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); -    if (result) -    { -        /** -         * Avant de lire l'entête du format, on ne sait pas où on se trouve ! -         */ -        init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); +    length = g_binary_content_compute_size(base->content); + +    format->portions = g_binary_portion_new(BPC_RAW, &addr, length); -        length = g_binary_content_compute_size(base->content); +    G_EXE_FORMAT_GET_CLASS(format)->refine_portions(format); -        format->portions = g_binary_portion_new(BPC_RAW, &addr, length); +} -        G_EXE_FORMAT_GET_CLASS(format)->refine_portions(format); -    } +/****************************************************************************** +*                                                                             * +*  Paramètres  : format = instance à traiter.                                 * +*                status = barre de statut à tenir informée.                   * +*                                                                             * +*  Description : Effectue les ultimes opérations de chargement d'un binaire.  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_executable_format_complete_loading(GExeFormat *format, GtkStatusStack *status) +{ +    bool result;                            /* Bilan à faire remonter      */ +    GBinFormat *base;                       /* Version basique du format   */ + +    base = G_BIN_FORMAT(format); + +    result = g_binary_format_complete_loading(base, status);      return result; @@ -447,7 +465,7 @@ GBinPortion *g_exe_format_get_portions(GExeFormat *format)  *                                                                             *  ******************************************************************************/ -bool g_exe_format_translate_offset_into_vmpa(const GExeFormat *format, phys_t off, vmpa2t *pos) +bool g_exe_format_translate_offset_into_vmpa(GExeFormat *format, phys_t off, vmpa2t *pos)  {      bool result;                            /* Bilan à retourner           */ @@ -472,7 +490,7 @@ bool g_exe_format_translate_offset_into_vmpa(const GExeFormat *format, phys_t of  *                                                                             *  ******************************************************************************/ -bool g_exe_format_translate_address_into_vmpa(const GExeFormat *format, virt_t addr, vmpa2t *pos) +bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, vmpa2t *pos)  {      bool result;                            /* Bilan à retourner           */ diff --git a/src/format/executable.h b/src/format/executable.h index af69029..293a0c0 100644 --- a/src/format/executable.h +++ b/src/format/executable.h @@ -76,10 +76,10 @@ GBinPortion *g_exe_format_get_portions(GExeFormat *);  mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count);  /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_offset_into_vmpa(const GExeFormat *, phys_t, vmpa2t *); +bool g_exe_format_translate_offset_into_vmpa(GExeFormat *, phys_t, vmpa2t *);  /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_address_into_vmpa(const GExeFormat *, virt_t, vmpa2t *); +bool g_exe_format_translate_address_into_vmpa(GExeFormat *, virt_t, vmpa2t *);  #define g_exe_format_translate_offset_into_address(fmt, off, addr)              \ | 
