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/glibext | |
| parent | 7135e7944c91d2e8b787c8782375423b9a90ed5b (diff) | |
Translated offsets and addresses with more accuracy.
Diffstat (limited to 'src/glibext')
| -rw-r--r-- | src/glibext/gbinportion.c | 200 | ||||
| -rw-r--r-- | src/glibext/gbinportion.h | 6 | 
2 files changed, 203 insertions, 3 deletions
diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c index 2275583..27413f6 100644 --- a/src/glibext/gbinportion.c +++ b/src/glibext/gbinportion.c @@ -119,7 +119,13 @@ static void g_binary_portion_print(GBinPortion *, GBufferLine *, size_t, size_t,  /* Détermine si une portion contient une adresse donnée. */ -static bool g_portion_layer_contains_addr(const GBinPortion *, const vmpa2t *); +static bool g_binary_portion_contains_vmpa(const GBinPortion *, const vmpa2t *); + +/* Détermine si une portion contient une position donnée. */ +static bool g_binary_portion_contains_physical(const GBinPortion *, phys_t); + +/* Détermine si une portion contient une adresse donnée. */ +static bool g_binary_portion_contains_virtual(const GBinPortion *, virt_t); @@ -1196,7 +1202,7 @@ GBinPortion *g_binary_portion_find_at_pos(GBinPortion *portion, gint x, GdkRecta  *                                                                             *  ******************************************************************************/ -static bool g_portion_layer_contains_addr(const GBinPortion *portion, const vmpa2t *addr) +static bool g_binary_portion_contains_vmpa(const GBinPortion *portion, const vmpa2t *addr)  {      bool result;                            /* Bilan à retourner           */ @@ -1245,7 +1251,7 @@ GBinPortion *g_binary_portion_find_at_addr(GBinPortion *portion, const vmpa2t *a      {          sub = portion->subs[i]; -        if (!g_portion_layer_contains_addr(sub, addr)) +        if (!g_binary_portion_contains_vmpa(sub, addr))              continue;          if (!g_binary_portion_compute_sub_area(sub, full, area, &sub_area)) @@ -1372,3 +1378,191 @@ gboolean query_tooltip_for_binary_portion(GBinPortion *root, gint x, gint y, con      return TRUE;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : portion = portion mère à consulter.                          * +*                off     = position physique du point de recherche.           * +*                                                                             * +*  Description : Détermine si une portion contient une position donnée.       * +*                                                                             * +*  Retour      : true ou false selon le résultat.                             * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_binary_portion_contains_physical(const GBinPortion *portion, phys_t off) +{ +    bool result;                            /* Bilan à retourner           */ +    const mrange_t *range;                  /* Emplacement de portion      */ +    const vmpa2t *addr;                     /* Départ de la portion        */ + +    range = g_binary_portion_get_range(portion); +    addr = get_mrange_addr(range); + +    if (!has_phys_addr(addr)) +        result = false; + +    else +        result = (addr->physical <= off && off < (addr->physical + range->length)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : portion = couche de portions à parcourir pour les recherches.* +*                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_binary_portion_translate_offset_into_vmpa(const GBinPortion *portion, phys_t off, vmpa2t *pos) +{ +    bool result;                            /* Bilan à retourner           */ +    size_t i;                               /* Boucle de parcours #1       */ +    GBinPortion *sub;                       /* Portion incluse à traiter   */ +    const mrange_t *range;                  /* Emplacement de portion      */ +    const vmpa2t *addr;                     /* Départ de la portion        */ + +    result = false; + +    for (i = 0; i < portion->count; i++) +    { +        sub = portion->subs[i]; + +        if (!g_binary_portion_contains_physical(sub, off)) +            continue; + +        result = g_binary_portion_translate_offset_into_vmpa(sub, off, pos); + +        break; + +    } + +    if (i == portion->count) +    { +        result = g_binary_portion_contains_physical(portion, off); + +        if (result) +        { +            range = g_binary_portion_get_range(portion); +            addr = get_mrange_addr(range); + +            if (has_virt_addr(get_mrange_addr(range))) +                init_vmpa(pos, off, addr->virtual + off - addr->physical); + +            else +                init_vmpa(pos, off, VMPA_NO_VIRTUAL); + +        } + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : portion = portion mère à consulter.                          * +*                virt    = adresse virtuelle du point de recherche.           * +*                                                                             * +*  Description : Détermine si une portion contient une adresse donnée.        * +*                                                                             * +*  Retour      : true ou false selon le résultat.                             * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_binary_portion_contains_virtual(const GBinPortion *portion, virt_t virt) +{ +    bool result;                            /* Bilan à retourner           */ +    const mrange_t *range;                  /* Emplacement de portion      */ +    const vmpa2t *addr;                     /* Départ de la portion        */ + +    range = g_binary_portion_get_range(portion); +    addr = get_mrange_addr(range); + +    if (!has_virt_addr(addr)) +        result = false; + +    else +        result = (addr->virtual <= virt && virt < (addr->virtual + range->length)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : portion = couche de portions à parcourir pour les recherches.* +*                virt    = adresse virtuelle à retrouver.                     * +*                pos     = position correspondante. [OUT]                     * +*                                                                             * +*  Description : Fournit l'emplacement correspondant à une adresse virtuelle. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_binary_portion_translate_address_into_vmpa(const GBinPortion *portion, virt_t virt, vmpa2t *pos) +{ +    bool result;                            /* Bilan à retourner           */ +    size_t i;                               /* Boucle de parcours #1       */ +    GBinPortion *sub;                       /* Portion incluse à traiter   */ +    const mrange_t *range;                  /* Emplacement de portion      */ +    const vmpa2t *addr;                     /* Départ de la portion        */ + +    result = false; + +    for (i = 0; i < portion->count; i++) +    { +        sub = portion->subs[i]; + +        if (!g_binary_portion_contains_virtual(sub, virt)) +            continue; + +        result = g_binary_portion_translate_address_into_vmpa(sub, virt, pos); + +        break; + +    } + +    if (i == portion->count) +    { +        result = g_binary_portion_contains_virtual(portion, virt); + +        if (result) +        { +            range = g_binary_portion_get_range(portion); +            addr = get_mrange_addr(range); + +            if (has_phys_addr(addr) && has_virt_addr(addr)) +                init_vmpa(pos, addr->physical + virt - addr->virtual, virt); + +            else +                init_vmpa(pos, VMPA_NO_PHYSICAL, virt); + +        } + +    } + +    return result; + +} diff --git a/src/glibext/gbinportion.h b/src/glibext/gbinportion.h index b1184fb..581be68 100644 --- a/src/glibext/gbinportion.h +++ b/src/glibext/gbinportion.h @@ -159,6 +159,12 @@ bool get_binary_portion_pos_from_addr(GBinPortion *, const vmpa2t *, const GdkRe  /* Prépare une astuce concernant une portion pour son affichage. */  gboolean query_tooltip_for_binary_portion(GBinPortion *, gint, gint, const GdkRectangle *, GtkTooltip *); +/* Fournit l'emplacement correspondant à une position physique. */ +bool g_binary_portion_translate_offset_into_vmpa(const GBinPortion *, phys_t, vmpa2t *); + +/* Fournit l'emplacement correspondant à une adresse virtuelle. */ +bool g_binary_portion_translate_address_into_vmpa(const GBinPortion *, virt_t, vmpa2t *); +  #endif  /* _GLIBEXT_BINPORTION_H */  | 
