summaryrefslogtreecommitdiff
path: root/src/glibext/gbinportion.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/gbinportion.c')
-rw-r--r--src/glibext/gbinportion.c345
1 files changed, 250 insertions, 95 deletions
diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c
index 4137763..eec9651 100644
--- a/src/glibext/gbinportion.c
+++ b/src/glibext/gbinportion.c
@@ -26,6 +26,7 @@
#include <assert.h>
#include <malloc.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -33,8 +34,10 @@
#include <i18n.h>
+#include "../analysis/human/asm/lang.h" // TODO : REMME -> format !
#include "../common/extstr.h"
#include "../common/sort.h"
+#include "../glibext/linegen-int.h"
@@ -49,6 +52,8 @@ struct _GBinPortion
char *code; /* Code de la couleur de fond */
char *desc; /* Désignation humaine */
+ char **text; /* Lignes brutes à représenter */
+ size_t lcount; /* Quantité de ces lignes */
mrange_t range; /* Emplacement dans le code */
@@ -73,6 +78,9 @@ static void g_binary_portion_class_init(GBinPortionClass *);
/* Initialise une instance de portion de données binaires. */
static void g_binary_portion_init(GBinPortion *);
+/* Procède à l'initialisation de l'interface de génération. */
+static void g_binary_portion_interface_init(GLineGeneratorInterface *);
+
/* Supprime toutes les références externes. */
static void g_binary_portion_dispose(GBinPortion *);
@@ -84,6 +92,26 @@ static bool g_binary_portion_compute_sub_area(const GBinPortion *, phys_t, const
+/* ------------------------ OFFRE DE CAPACITES DE GENERATION ------------------------ */
+
+
+/* Indique le nombre de ligne prêtes à être générées. */
+static size_t g_binary_portion_count_lines(const GBinPortion *);
+
+/* Retrouve l'emplacement correspondant à une position donnée. */
+static void g_binary_portion_compute_addr(const GBinPortion *, gint, vmpa2t *, size_t, size_t);
+
+/* Détermine si le conteneur s'inscrit dans une plage donnée. */
+static int g_binary_portion_contains_addr(const GBinPortion *, const vmpa2t *, size_t, size_t);
+
+/* Renseigne sur les propriétés liées à un générateur. */
+static BufferLineFlags g_binary_portion_get_flags(const GBinPortion *, size_t, size_t);
+
+/* Imprime dans une ligne de rendu le contenu représenté. */
+static void g_binary_portion_print(GBinPortion *, GBufferLine *, size_t, size_t);
+
+
+
/* ------------------------ PARCOURS D'ENSEMBLES DE PORTIONS ------------------------ */
@@ -98,7 +126,8 @@ static bool g_portion_layer_contains_addr(const GBinPortion *, const vmpa2t *);
/* Indique le type défini par la GLib pour les portions de données binaires. */
-G_DEFINE_TYPE(GBinPortion, g_binary_portion, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_CODE(GBinPortion, g_binary_portion, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE(G_TYPE_LINE_GENERATOR, g_binary_portion_interface_init));
/******************************************************************************
@@ -140,6 +169,32 @@ static void g_binary_portion_class_init(GBinPortionClass *klass)
static void g_binary_portion_init(GBinPortion *portion)
{
+ portion->desc = NULL;
+ portion->text = NULL;
+ portion->lcount = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de génération. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_portion_interface_init(GLineGeneratorInterface *iface)
+{
+ iface->count = (linegen_count_lines_fc)g_binary_portion_count_lines;
+ iface->compute = (linegen_compute_fc)g_binary_portion_compute_addr;
+ iface->contains = (linegen_contains_fc)g_binary_portion_contains_addr;
+ iface->get_flags = (linegen_get_flags_fc)g_binary_portion_get_flags;
+ iface->print = (linegen_print_fc)g_binary_portion_print;
}
@@ -177,11 +232,19 @@ static void g_binary_portion_dispose(GBinPortion *portion)
static void g_binary_portion_finalize(GBinPortion *portion)
{
+ size_t i; /* Boucle de parcours */
+
free(portion->code);
if (portion->desc != NULL)
free(portion->desc);
+ for (i = 0; i < portion->lcount; i++)
+ free(portion->text[i]);
+
+ if (portion->text != NULL)
+ free(portion->text);
+
G_OBJECT_CLASS(g_binary_portion_parent_class)->finalize(G_OBJECT(portion));
}
@@ -260,9 +323,66 @@ int g_binary_portion_compare(const GBinPortion **a, const GBinPortion **b)
void g_binary_portion_set_desc(GBinPortion *portion, const char *desc)
{
- if (portion->desc != NULL) free(portion->desc);
+ size_t i; /* Boucle de parcours */
+ GCodingLanguage *lang; /* Langage de sortie préféré */
+
+ if (portion->desc != NULL)
+ {
+ free(portion->desc);
+
+ for (i = 0; i < portion->lcount; i++)
+ free(portion->text[i]);
+
+ if (portion->text != NULL)
+ {
+ free(portion->text);
+ portion->text = NULL;
+ }
+
+ }
+
+ if (desc == NULL)
+ portion->desc = NULL;
+
+ else
+ {
+ portion->desc = strdup(desc);
+
+ /* Constitution du rendu */
+
+ portion->text = calloc(4, sizeof(char *));
+ portion->lcount = 4;
+
+ portion->text[0] = strdup("======================================================");
+ portion->text[1] = strdup("");
+
+ asprintf(&portion->text[2], "%s (%s%s%s%s)", portion->desc, _("rights: "),
+ portion->rights & PAC_READ ? "r" : "-",
+ portion->rights & PAC_WRITE ? "w" : "-",
+ portion->rights & PAC_EXEC ? "x" : "-");
- portion->desc = strdup(desc);
+ portion->text[3] = strdup("");
+ portion->text[4] = strdup("======================================================");
+
+ /* Ajout de la touche "commentaires" */
+
+ lang = g_asm_language_new();
+
+ g_coding_language_encapsulate_comments(lang, &portion->text, &portion->lcount);
+
+ g_object_unref(G_OBJECT(lang));
+
+ /* Ajout de deux bordures vides */
+
+ portion->lcount += 2;
+ portion->text = realloc(portion->text, portion->lcount * sizeof(char *));
+
+ memmove(&portion->text[1], &portion->text[0], (portion->lcount - 2) * sizeof(char *));
+
+ portion->text[0] = NULL;
+ portion->text[portion->lcount - 1] = NULL;
+
+ }
}
@@ -346,98 +466,6 @@ PortionAccessRights g_binary_portion_get_rights(const GBinPortion *portion)
/******************************************************************************
* *
-* Paramètres : portion = description de partie à consulter. *
-* buffer = espace où placer ledit contenu. *
-* msize = taille idéale des positions et adresses; *
-* *
-* Description : Insère dans un tampon une description de portion. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_binary_portion_print(const GBinPortion *portion, GCodeBuffer *buffer, MemoryDataSize msize)
-{
- mrange_t range; /* Couverture à fournir */
- GBufferLine *line; /* Nouvelle ligne à éditer */
- char rights[64]; /* Traduction en texte */
-
- /* On ne traite pas les portions anonymes ! */
- if (portion->desc == NULL) return;
-
- init_mrange(&range, get_mrange_addr(&portion->range), 0);
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
-
- g_buffer_line_add_flag(line, BLF_WIDTH_MANAGER);
-
- g_code_buffer_append_new_line(buffer, line);
-
- /* Séparation */
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
-
- g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD,
- "; ======================================================", 56, RTT_COMMENT, NULL);
-
- g_code_buffer_append_new_line(buffer, line);
-
- /* Retour à la ligne */
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
-
- g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "; ", 2, RTT_COMMENT, NULL);
-
- g_code_buffer_append_new_line(buffer, line);
-
- /* Description */
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
-
- g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
-
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "; ", 2, RTT_COMMENT, NULL);
-
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, portion->desc, strlen(portion->desc), RTT_COMMENT, NULL);
-
- snprintf(rights, sizeof(rights), " (%s%s%s%s)",
- _("rights: "),
- portion->rights & PAC_READ ? "r" : "-",
- portion->rights & PAC_WRITE ? "w" : "-",
- portion->rights & PAC_EXEC ? "x" : "-");
-
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, rights, strlen(rights), RTT_COMMENT, NULL);
-
- g_code_buffer_append_new_line(buffer, line);
-
- /* Retour à la ligne */
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
-
- g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "; ", 2, RTT_COMMENT, NULL);
-
- g_code_buffer_append_new_line(buffer, line);
-
- line = g_code_buffer_prepare_new_line(buffer, &range);
- g_buffer_line_fill_mrange(line, msize, msize);
- g_code_buffer_append_new_line(buffer, line);
-
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : portion = description de partie à mettre à jour. *
* tooltip = astuce à compléter. [OUT] *
* *
@@ -724,6 +752,133 @@ bool g_binary_portion_visit(GBinPortion *portion, visit_portion_fc visitor, void
/* ---------------------------------------------------------------------------------- */
+/* OFFRE DE CAPACITES DE GENERATION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : portion = générateur à consulter. *
+* *
+* Description : Indique le nombre de ligne prêtes à être générées. *
+* *
+* Retour : Nombre de lignes devant apparaître au final. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static size_t g_binary_portion_count_lines(const GBinPortion *portion)
+{
+ return portion->lcount;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : portion = générateur à consulter. *
+* x = position géographique sur la ligne concernée. *
+* addr = position en mémoire à analyser. *
+* index = indice de cette même ligne dans le tampon global. *
+* repeat = indice d'utilisations successives du générateur. *
+* *
+* Description : Retrouve l'emplacement correspondant à une position donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_portion_compute_addr(const GBinPortion *portion, gint x, vmpa2t *addr, size_t index, size_t repeat)
+{
+ copy_vmpa(addr, get_mrange_addr(&portion->range));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : portion = générateur à consulter. *
+* addr = position en mémoire à analyser. *
+* index = indice de cette même ligne dans le tampon global. *
+* repeat = indice d'utilisations successives du générateur. *
+* *
+* Description : Détermine si le conteneur s'inscrit dans une plage donnée. *
+* *
+* Retour : Bilan de la détermination, utilisable en comparaisons. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int g_binary_portion_contains_addr(const GBinPortion *portion, const vmpa2t *addr, size_t index, size_t repeat)
+{
+ int result; /* Conclusion à retourner */
+
+ result = cmp_vmpa(addr, get_mrange_addr(&portion->range));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : portion = générateur à consulter. *
+* index = indice de cette même ligne dans le tampon global. *
+* repeat = indice d'utilisations successives du générateur. *
+* *
+* Description : Renseigne sur les propriétés liées à un générateur. *
+* *
+* Retour : Propriétés particulières associées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static BufferLineFlags g_binary_portion_get_flags(const GBinPortion *portion, size_t index, size_t repeat)
+{
+ return (repeat == 0 ? BLF_WIDTH_MANAGER : BLF_HAS_CODE);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : portion = générateur à utiliser pour l'impression. *
+* line = ligne de rendu à compléter. *
+* index = indice de cette même ligne dans le tampon global. *
+* repeat = indice d'utilisations successives du générateur. *
+* *
+* Description : Imprime dans une ligne de rendu le contenu représenté. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_portion_print(GBinPortion *portion, GBufferLine *line, size_t index, size_t repeat)
+{
+ assert(repeat < portion->lcount);
+
+ g_buffer_line_fill_vmpa(line, get_mrange_addr(&portion->range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED);
+
+ if (portion->text[repeat] != NULL)
+ {
+ g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
+
+ g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, SL(portion->text[repeat]), RTT_COMMENT, NULL);
+
+ }
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
/* PARCOURS D'ENSEMBLES DE PORTIONS */
/* ---------------------------------------------------------------------------------- */