From 703e0d10d56bb288b515526f0d0f1994391619bf Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 27 Jul 2020 23:54:34 +0200 Subject: Removed some extra special column indexes. --- plugins/pychrysalide/glibext/bufferline.c | 5 --- src/arch/operands/immediate.c | 5 +-- src/arch/operands/target.c | 13 ++++---- src/glibext/bufferline.c | 51 ++++++++++++++----------------- src/glibext/bufferline.h | 12 +------- src/glibext/gdisplayoptions.c | 34 +++++++++++++++++++-- src/glibext/gdisplayoptions.h | 5 ++- src/gui/dialogs/export_disass.c | 37 ++++++++++++---------- 8 files changed, 91 insertions(+), 71 deletions(-) diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c index 274300a..d30d11d 100644 --- a/plugins/pychrysalide/glibext/bufferline.c +++ b/plugins/pychrysalide/glibext/bufferline.c @@ -368,11 +368,6 @@ static bool py_buffer_line_define_constants(PyTypeObject *obj_type) result &= PyDict_AddULongMacro(obj_type, BLC_ASSEMBLY); result &= PyDict_AddULongMacro(obj_type, BLC_COMMENTS); result &= PyDict_AddULongMacro(obj_type, BLC_COUNT); - result &= PyDict_AddULongMacro(obj_type, BLC_LAST_USED); - result &= PyDict_AddULongMacro(obj_type, BLC_INVALID); - result &= PyDict_AddULongMacro(obj_type, BLC_MAIN); - result &= PyDict_AddULongMacro(obj_type, BLC_FIRST); - result &= PyDict_AddULongMacro(obj_type, BLC_DISPLAY); return result; diff --git a/src/arch/operands/immediate.c b/src/arch/operands/immediate.c index 769826b..746bcae 100644 --- a/src/arch/operands/immediate.c +++ b/src/arch/operands/immediate.c @@ -45,6 +45,7 @@ #include "../../core/logs.h" #include "../../format/format.h" #include "../../glibext/objhole.h" +#include "../../gtkext/gtkblockdisplay.h" @@ -1351,7 +1352,7 @@ static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line) len = g_imm_operand_to_string(operand, value); - g_buffer_line_append_text(line, BLC_MAIN, value, len, RTT_IMMEDIATE, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, value, len, RTT_IMMEDIATE, G_OBJECT(operand)); } @@ -1940,7 +1941,7 @@ static void g_known_imm_operand_print(const GKnownImmOperand *operand, GBufferLi len = strlen(operand->alt_text); - g_buffer_line_append_text(line, BLC_MAIN, operand->alt_text, len, RTT_IMMEDIATE, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, operand->alt_text, len, RTT_IMMEDIATE, G_OBJECT(operand)); } diff --git a/src/arch/operands/target.c b/src/arch/operands/target.c index d921200..9b93548 100644 --- a/src/arch/operands/target.c +++ b/src/arch/operands/target.c @@ -40,6 +40,7 @@ #include "../../format/format.h" #include "../../format/strsym.h" #include "../../glibext/gbinarycursor.h" +#include "../../gtkext/gtkblockdisplay.h" @@ -301,20 +302,20 @@ static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *l if (operand->symbol != NULL && label != NULL) { if (operand->diff > 0) - g_buffer_line_append_text(line, BLC_MAIN, "<", 1, RTT_LTGT, NULL); + g_buffer_line_append_text(line, DLC_ASSEMBLY, "<", 1, RTT_LTGT, NULL); - g_buffer_line_append_text(line, BLC_MAIN, label, strlen(label), RTT_LABEL, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, label, strlen(label), RTT_LABEL, G_OBJECT(operand)); if (operand->diff > 0) { - g_buffer_line_append_text(line, BLC_MAIN, "+", 1, RTT_SIGNS, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, "+", 1, RTT_SIGNS, G_OBJECT(operand)); init_vmpa(&tmp, operand->diff, VMPA_NO_VIRTUAL); vmpa2_phys_to_string(&tmp, MDS_4_BITS, value, &len); - g_buffer_line_append_text(line, BLC_MAIN, value, len, RTT_LABEL, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, value, len, RTT_LABEL, G_OBJECT(operand)); - g_buffer_line_append_text(line, BLC_MAIN, ">", 1, RTT_LTGT, NULL); + g_buffer_line_append_text(line, DLC_ASSEMBLY, ">", 1, RTT_LTGT, NULL); } @@ -323,7 +324,7 @@ static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *l { vmpa2_to_string(&operand->addr, operand->size, value, &len); - g_buffer_line_append_text(line, BLC_MAIN, value, len, RTT_LABEL, G_OBJECT(operand)); + g_buffer_line_append_text(line, DLC_ASSEMBLY, value, len, RTT_LABEL, G_OBJECT(operand)); } diff --git a/src/glibext/bufferline.c b/src/glibext/bufferline.c index 5eec1db..ec1176b 100644 --- a/src/glibext/bufferline.c +++ b/src/glibext/bufferline.c @@ -33,6 +33,7 @@ #include "linecolumn.h" #include "../common/extstr.h" #include "../core/paths.h" +#include "../gtkext/gtkblockdisplay.h" @@ -55,8 +56,7 @@ struct _GBufferLine line_column *columns; /* Répartition du texte */ size_t col_count; /* Nombre de colonnes présentes*/ - BufferLineColumn merge_start; /* Début de la zone globale */ - BufferLineColumn last_used; /* Dernière colonne utilisée */ + size_t merge_start; /* Début de la zone globale */ BufferLineFlags flags; /* Drapeaux particuliers */ @@ -178,7 +178,6 @@ static void g_buffer_line_init(GBufferLine *line) line->columns = NULL; line->col_count = 0; line->merge_start = -1; - line->last_used = -1; } @@ -503,19 +502,9 @@ void g_buffer_line_append_text(GBufferLine *line, size_t column, const char *tex size_t index; /* Indice d'insertion */ content_origin *origin; /* Définition d'une origine */ + assert(column < line->col_count); assert(length > 0); - if (column == -1) - column = BLC_LAST_USED; - - if (column == BLC_MAIN) - column = BLC_ASSEMBLY;//line->main_column; - - if (column == BLC_LAST_USED) - column = line->last_used; - else - line->last_used = column; - index = append_text_to_line_column(&line->columns[column], text, length, type); if (creator != NULL) @@ -720,10 +709,7 @@ BufferLineColumn g_buffer_line_get_merge_start(const GBufferLine *line) void g_buffer_line_start_merge_at(GBufferLine *line, BufferLineColumn start) { - if (start == BLC_LAST_USED) - line->merge_start = line->last_used; - else - line->merge_start = start; + line->merge_start = start; } @@ -801,10 +787,11 @@ void g_buffer_line_remove_flag(GBufferLine *line, BufferLineFlags flag) /****************************************************************************** * * -* Paramètres : line = ligne de texte à manipuler. * -* ctx = éléments à disposition pour l'exportation. * -* type = type d'exportation attendue. * -* display = règles d'affichage des colonnes modulables. * +* Paramètres : line = ligne de texte à manipuler. * +* ctx = éléments à disposition pour l'exportation. * +* type = type d'exportation attendue. * +* col_count = quantité de colonnes existantes au total. * +* options = règles d'affichage des colonnes modulables. * * * * Description : Exporte la ligne de texte représentée. * * * @@ -814,9 +801,10 @@ void g_buffer_line_remove_flag(GBufferLine *line, BufferLineFlags flag) * * ******************************************************************************/ -void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferExportType type, const bool *display) +void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferExportType type, const GDisplayOptions *options) { - BufferLineColumn i; /* Boucle de parcours */ + size_t opt_count; /* Qté de colonnes en option */ + size_t i; /* Boucle de parcours */ int col_span; /* Fusion de colonnes ? */ switch (type) @@ -828,9 +816,16 @@ void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferE break; } - for (i = 0; i < BLC_COUNT; i++) + opt_count = g_display_options_count(options); + assert(opt_count < line->col_count); + + for (i = 0; i < line->col_count; i++) { - if (i < BLC_DISPLAY && !display[i]) continue; + if (i < opt_count) + { + if (!g_display_options_get(options, i)) + continue; + } switch (type) { @@ -859,10 +854,10 @@ void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferE col_span = 1; else if (i == line->merge_start) - col_span = BLC_COUNT - i; + col_span = line->col_count - i; else - col_span = ((i + 1) == BLC_COUNT ? -1 : 0); + col_span = ((i + 1) == line->col_count ? -1 : 0); export_line_column_segments(&line->columns[i], ctx, type, col_span); diff --git a/src/glibext/bufferline.h b/src/glibext/bufferline.h index 0e20b37..319f9b7 100644 --- a/src/glibext/bufferline.h +++ b/src/glibext/bufferline.h @@ -65,18 +65,8 @@ typedef enum _BufferLineColumn BLC_COUNT, - BLC_LAST_USED, /* Dernière colonne utilisée */ - BLC_INVALID, /* Valeur de non-initialisation*/ - BLC_MAIN /* Colonne principale (cf. imm)*/ - } BufferLineColumn; -/* Première colonne de l'ensemble */ -#define BLC_FIRST BLC_PHYSICAL - -/* Première colonne toujours affichée */ -#define BLC_DISPLAY BLC_ASSEMBLY_LABEL - /* Confort pour l'insertion de texte */ #define SL(str) str, strlen(str) @@ -149,7 +139,7 @@ BufferLineFlags g_buffer_line_get_flags(const GBufferLine *); void g_buffer_line_remove_flag(GBufferLine *, BufferLineFlags); /* Exporte la ligne de texte représentée. */ -void g_buffer_line_export(GBufferLine *, buffer_export_context *, BufferExportType, const bool *); +void g_buffer_line_export(GBufferLine *, buffer_export_context *, BufferExportType, const GDisplayOptions *); diff --git a/src/glibext/gdisplayoptions.c b/src/glibext/gdisplayoptions.c index c0fa614..a8f835b 100644 --- a/src/glibext/gdisplayoptions.c +++ b/src/glibext/gdisplayoptions.c @@ -189,7 +189,7 @@ static void g_display_options_finalize(GDisplayOptions *options) * * * Paramètres : - * * * -* Description : Crée un un groupe d'options pour le rendu des lignes. * +* Description : Crée un groupe d'options pour le rendu des lignes. * * * * Retour : Adresse de la structure mise en place. * * * @@ -199,7 +199,7 @@ static void g_display_options_finalize(GDisplayOptions *options) GDisplayOptions *g_display_options_new(void) { - GDisplayOptions *result; /* Structure à retourner */ + GDisplayOptions *result; /* Structure à retourner */ result = g_object_new(G_TYPE_DISPLAY_OPTIONS, NULL); @@ -210,6 +210,36 @@ GDisplayOptions *g_display_options_new(void) /****************************************************************************** * * +* Paramètres : template = modèle de groupe à copier. * +* * +* Description : Copie un groupe d'options pour le rendu des lignes. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDisplayOptions *g_display_options_dup(const GDisplayOptions *template) +{ + GDisplayOptions *result; /* Structure à retourner */ + size_t count; /* Nombre d'options à copier */ + size_t i; /* Boucle de parcours */ + + result = g_display_options_new(); + + count = g_display_options_count(template); + + for (i = 0; i < count; i++) + g_display_options_add(result, template->names[i], template->values[i]); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : options = options à consulter. * * * * Description : Dénombre la quantité d'options représentées. * diff --git a/src/glibext/gdisplayoptions.h b/src/glibext/gdisplayoptions.h index 7549897..1a30e81 100644 --- a/src/glibext/gdisplayoptions.h +++ b/src/glibext/gdisplayoptions.h @@ -48,9 +48,12 @@ typedef struct _GDisplayOptionsClass GDisplayOptionsClass; /* Indique le type défini pour des options de représentation. */ GType g_display_options_get_type(void); -/* Crée un un groupe d'options pour le rendu des lignes. */ +/* Crée un groupe d'options pour le rendu des lignes. */ GDisplayOptions *g_display_options_new(void); +/* Copie un groupe d'options pour le rendu des lignes. */ +GDisplayOptions *g_display_options_dup(const GDisplayOptions *); + /* Dénombre la quantité d'options représentées. */ size_t g_display_options_count(const GDisplayOptions *); diff --git a/src/gui/dialogs/export_disass.c b/src/gui/dialogs/export_disass.c index 314b9cf..c15dcbc 100644 --- a/src/gui/dialogs/export_disass.c +++ b/src/gui/dialogs/export_disass.c @@ -41,6 +41,7 @@ #include "../../core/queue.h" #include "../../glibext/seq.h" #include "../../gtkext/easygtk.h" +#include "../../gtkext/gtkblockdisplay.h" @@ -60,14 +61,14 @@ typedef struct _export_info_t buffer_export_context *ctx; /* Contexte d'exportation */ BufferExportType type; /* Type d'exportation menée */ - bool display[BLC_COUNT]; /* Paramètres d'affichage */ + GDisplayOptions *options; /* Paramètres d'affichage */ activity_id_t msg; /* Message de progression */ } export_info_t; /* Lance l'exportation d'un contenu binaire comme demandé. */ -static void start_binary_export(GBufferCache *, buffer_export_context *, BufferExportType, const bool *); +static void start_binary_export(GBufferCache *, buffer_export_context *, BufferExportType, GDisplayOptions *); /* Réalise l'exportation d'une ligne particulière. */ static void export_one_binary_line(const export_info_t *, size_t, GtkStatusStack *, activity_id_t); @@ -211,8 +212,9 @@ static void export_assistant_close(GtkAssistant *assistant, GObject *ref) GtkEntry *entry; /* Zone de saisie */ const gchar *filename; /* Chemin d'accès du fichier */ GtkToggleButton *checkbutton; /* Coche à retrouver */ - bool display[BLC_DISPLAY]; /* Affichage à garantir */ GLoadedBinary *binary; /* Binaire chargé à parcourir */ + GDisplayOptions *template; /* Options courantes */ + GDisplayOptions *options; /* Options d'affichage */ GBufferCache *cache; /* Tampon de code à traiter */ GObject *support; /* Support interne à supprimer */ @@ -236,14 +238,20 @@ static void export_assistant_close(GtkAssistant *assistant, GObject *ref) /* Eléments à afficher */ + binary = G_LOADED_BINARY(g_object_get_data(ref, "binary")); + + template = g_loaded_content_get_display_options(G_LOADED_CONTENT(binary), BVW_BLOCK); + options = g_display_options_dup(template); + g_object_unref(G_OBJECT(template)); + checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "physical_off")); - display[BLC_PHYSICAL] = gtk_toggle_button_get_active(checkbutton); + g_display_options_set(options, BLC_PHYSICAL, gtk_toggle_button_get_active(checkbutton)); checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "virtual_addr")); - display[BLC_VIRTUAL] = gtk_toggle_button_get_active(checkbutton); + g_display_options_set(options, BLC_VIRTUAL, gtk_toggle_button_get_active(checkbutton)); checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "binary_code")); - display[BLC_BINARY] = gtk_toggle_button_get_active(checkbutton); + g_display_options_set(options, BLC_BINARY, gtk_toggle_button_get_active(checkbutton)); /* Options éventuelles */ @@ -275,11 +283,9 @@ static void export_assistant_close(GtkAssistant *assistant, GObject *ref) /* Programmation de la tâche */ - binary = G_LOADED_BINARY(g_object_get_data(ref, "binary")); - cache = g_loaded_binary_get_disassembly_cache(binary); - start_binary_export(cache, &ctx, type, display); + start_binary_export(cache, &ctx, type, options); g_object_unref(G_OBJECT(cache)); @@ -301,7 +307,7 @@ static void export_assistant_close(GtkAssistant *assistant, GObject *ref) * Paramètres : cache = tampon de données à utiliser. * * template = paramètres dont s'inspirer pour l'exportation. * * type = type d'exportation attendue. * -* display = règles d'affichage des colonnes modulables. * +* options = règles d'affichage des colonnes modulables. * * * * Description : Lance l'exportation d'un contenu binaire comme demandé. * * * @@ -311,10 +317,9 @@ static void export_assistant_close(GtkAssistant *assistant, GObject *ref) * * ******************************************************************************/ -static void start_binary_export(GBufferCache *cache, buffer_export_context *template, BufferExportType type, const bool *display) +static void start_binary_export(GBufferCache *cache, buffer_export_context *template, BufferExportType type, GDisplayOptions *options) { export_info_t *info; /* Infos à faire circuler */ - BufferLineColumn i; /* Boucle de parcours */ GWorkQueue *queue; /* Gestionnaire de différés */ size_t count; /* Quantité de lignes à traiter*/ GSeqWork *work; /* Tâche de chargement à lancer*/ @@ -347,9 +352,7 @@ static void start_binary_export(GBufferCache *cache, buffer_export_context *temp } info->type = type; - - for (i = 0; i < BLC_DISPLAY; i++) - info->display[i] = display[i]; + info->options = options; /* Données exportées initiales */ @@ -421,7 +424,7 @@ static void export_one_binary_line(const export_info_t *info, size_t i, GtkStatu line = g_buffer_cache_find_line_by_index(info->cache, i); - g_buffer_line_export(line, info->ctx, info->type, info->display); + g_buffer_line_export(line, info->ctx, info->type, info->options); g_object_unref(G_OBJECT(line)); @@ -463,6 +466,8 @@ static void on_binary_export_completed(GSeqWork *work, export_info_t *info) g_buffer_cache_unlock(info->cache); g_object_unref(G_OBJECT(info->cache)); + g_object_unref(G_OBJECT(info->options)); + close(info->ctx->fd); switch (info->type) -- cgit v0.11.2-87-g4458