summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-07-26 23:23:42 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-07-26 23:23:42 (GMT)
commit9606b8e49299e37b297da039fc8a645f1ab4cf2d (patch)
tree16eb18d5292ec04ee4b7a24756e59d3c430f104e
parentb80a36ab9746ca47b9c50827efe3856ce2840144 (diff)
Updated the process collecting line widths.
-rw-r--r--plugins/ropgadgets/select.c3
-rw-r--r--src/analysis/disass/block.c2
-rw-r--r--src/analysis/disass/disassembler.c2
-rw-r--r--src/glibext/buffercache.c31
-rw-r--r--src/glibext/buffercache.h4
-rw-r--r--src/glibext/bufferline.c68
-rw-r--r--src/glibext/bufferline.h4
-rw-r--r--src/glibext/widthtracker.c64
-rw-r--r--src/glibext/widthtracker.h6
-rw-r--r--src/gtkext/hexdisplay.c2
10 files changed, 87 insertions, 99 deletions
diff --git a/plugins/ropgadgets/select.c b/plugins/ropgadgets/select.c
index 099560a..1d0521d 100644
--- a/plugins/ropgadgets/select.c
+++ b/plugins/ropgadgets/select.c
@@ -43,6 +43,7 @@
#include <format/known.h>
#include <gui/core/global.h>
#include <gtkext/easygtk.h>
+#include <gtkext/gtkblockdisplay.h>
#include "finder.h"
@@ -1533,7 +1534,7 @@ static void add_new_gadgets_for_category(GExeFormat *format, GtkComboBoxText *co
{
instr = chain->instrs[j];
- line = g_buffer_line_new(BLC_ASSEMBLY);
+ line = g_buffer_line_new(DLC_COUNT);
g_line_generator_print(G_LINE_GENERATOR(instr), line, -1, 0, content);
if (j == 0)
diff --git a/src/analysis/disass/block.c b/src/analysis/disass/block.c
index 74aaf66..f0bee99 100644
--- a/src/analysis/disass/block.c
+++ b/src/analysis/disass/block.c
@@ -573,7 +573,7 @@ static char *g_basic_block_build_tooltip(const GBasicBlock *block)
if (label != NULL)
{
- cache = g_buffer_cache_new(NULL, DLC_COUNT);
+ cache = g_buffer_cache_new(NULL, DLC_COUNT, DLC_ASSEMBLY_LABEL);
g_buffer_cache_append(cache, G_LINE_GENERATOR(symbol), BLF_NONE);
line = g_buffer_cache_find_line_by_index(cache, 0);
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 9e4cd3e..0b81180 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -405,7 +405,7 @@ void output_disassembly(GLoadedBinary *binary, GProcContext *context, GtkStatusS
content = g_known_format_get_content(G_KNOWN_FORMAT(format));
lang = g_asm_language_new();
- *cache = g_buffer_cache_new(content, DLC_COUNT);
+ *cache = g_buffer_cache_new(content, DLC_COUNT, DLC_ASSEMBLY_LABEL);
g_generic_config_get_value(get_main_configuration(), MPK_LABEL_OFFSET, &offset);
diff --git a/src/glibext/buffercache.c b/src/glibext/buffercache.c
index 04d6dba..6f52956 100644
--- a/src/glibext/buffercache.c
+++ b/src/glibext/buffercache.c
@@ -60,7 +60,7 @@ static void get_cache_info_cursor(const cache_info *, size_t, gint, GLineCursor
static void on_line_ref_toggle(cache_info *, GBufferLine *, gboolean);
/* Fournit la ligne de tampon correspondant aux générateurs. */
-static GBufferLine *get_cache_info_line(cache_info *, size_t, const GBinContent *);
+static GBufferLine *get_cache_info_line(cache_info *, const GWidthTracker *, size_t, const GBinContent *);
/* Force la réinitialisation d'une éventuelle ligne cachée. */
static void _reset_cache_info_line_unlocked(cache_info *);
@@ -372,6 +372,7 @@ static void on_line_ref_toggle(cache_info *info, GBufferLine *line, gboolean las
/******************************************************************************
* *
* Paramètres : info = informations sur une ligne à venir manipuler. *
+* tracker = gestionnaire de largeurs à consulter si besoin est.*
* index = indice de la ligne à constituer. *
* content = éventuel contenu binaire brut à imprimer. *
* *
@@ -383,7 +384,7 @@ static void on_line_ref_toggle(cache_info *info, GBufferLine *line, gboolean las
* *
******************************************************************************/
-static GBufferLine *get_cache_info_line(cache_info *info, size_t index, const GBinContent *content)
+static GBufferLine *get_cache_info_line(cache_info *info, const GWidthTracker *tracker, size_t index, const GBinContent *content)
{
GBufferLine *result; /* Construction à retourner */
size_t i; /* Boucle de parcours */
@@ -394,7 +395,7 @@ static GBufferLine *get_cache_info_line(cache_info *info, size_t index, const GB
if (result == NULL)
{
- result = g_buffer_line_new(0/* !! */);
+ result = g_buffer_line_new(g_width_tracker_count_columns(tracker));
g_object_add_toggle_ref(G_OBJECT(result), (GToggleNotify)on_line_ref_toggle, info);
@@ -622,6 +623,7 @@ static void g_buffer_cache_finalize(GBufferCache *cache)
* *
* Paramètres : content = éventuel contenu binaire brut à référencer. *
* col_count = quantité maximale de colonnes à considérer. *
+* opt_count = quantité de colonnes optionnelles. *
* *
* Description : Crée un nouveau composant de tampon pour code désassemblé. *
* *
@@ -631,7 +633,7 @@ static void g_buffer_cache_finalize(GBufferCache *cache)
* *
******************************************************************************/
-GBufferCache *g_buffer_cache_new(GBinContent *content, size_t col_count)
+GBufferCache *g_buffer_cache_new(GBinContent *content, size_t col_count, size_t opt_count)
{
GBufferCache *result; /* Composant à retourner */
@@ -643,7 +645,7 @@ GBufferCache *g_buffer_cache_new(GBinContent *content, size_t col_count)
g_object_ref(G_OBJECT(content));
}
- result->tracker = g_width_tracker_new(result, col_count);
+ result->tracker = g_width_tracker_new(result, col_count, opt_count);
return result;
@@ -1395,7 +1397,7 @@ GBufferLine *g_buffer_cache_find_line_by_index(const GBufferCache *cache, size_t
GBufferLine *result; /* Ligne trouvée à retourner */
if (index < cache->used)
- result = get_cache_info_line(&cache->lines[index], index, cache->content);
+ result = get_cache_info_line(&cache->lines[index], cache->tracker, index, cache->content);
else
result = NULL;
@@ -1406,9 +1408,12 @@ GBufferLine *g_buffer_cache_find_line_by_index(const GBufferCache *cache, size_t
/******************************************************************************
* *
-* Paramètres : cache = tampon de lignes à venir consulter. *
-* index = indice de la ligne à mesurer. *
-* summary = largeurs maximales à faire évoluer. *
+* Paramètres : cache = tampon de lignes à venir consulter. *
+* index = indice de la ligne à mesurer. *
+* col_count = quantité de colonnes à considérer. *
+* opt_count = quantité de colonnes optionnelles. *
+* widths = largeur mesurée pour chacune des colonnes. [OUT] *
+* merged = largeur cumulée en cas de fusion. [OUT] *
* *
* Description : Fait remonter les largeurs requises par une ligne donnée. *
* *
@@ -1418,13 +1423,13 @@ GBufferLine *g_buffer_cache_find_line_by_index(const GBufferCache *cache, size_t
* *
******************************************************************************/
-void g_buffer_cache_collect_widths(GBufferCache *cache, size_t index, line_width_summary *summary)
+void g_buffer_cache_collect_widths(GBufferCache *cache, size_t index, size_t col_count, size_t opt_count, gint *widths, gint *merged)
{
GBufferLine *line; /* Ligne éphémère à mesurer */
- line = get_cache_info_line(&cache->lines[index], index, cache->content);
+ line = get_cache_info_line(&cache->lines[index], cache->tracker, index, cache->content);
- g_buffer_line_collect_widths(line, summary);
+ g_buffer_line_collect_widths(line, col_count, opt_count, widths, merged);
g_object_unref(G_OBJECT(line));
@@ -1482,7 +1487,7 @@ void g_buffer_cache_draw(const GBufferCache *cache, cairo_t *cr, size_t first, s
info = &cache->lines[i];
- line = get_cache_info_line(info, i, cache->content);
+ line = get_cache_info_line(info, cache->tracker, i, cache->content);
g_buffer_line_draw(line, i, cr, class->text_pos, y, cache->tracker, options, list);
diff --git a/src/glibext/buffercache.h b/src/glibext/buffercache.h
index 70154a0..61114b0 100644
--- a/src/glibext/buffercache.h
+++ b/src/glibext/buffercache.h
@@ -58,7 +58,7 @@ typedef struct _GBufferCacheClass GBufferCacheClass;
GType g_buffer_cache_get_type(void);
/* Crée un nouveau composant de tampon pour code désassemblé. */
-GBufferCache *g_buffer_cache_new(GBinContent *, size_t);
+GBufferCache *g_buffer_cache_new(GBinContent *, size_t, size_t);
/* Indique l'éventuel contenu binaire associé au cache. */
GBinContent *g_buffer_cache_get_content(const GBufferCache *);
@@ -111,7 +111,7 @@ BufferLineFlags g_buffer_cache_get_line_flags(const GBufferCache *, size_t);
GBufferLine *g_buffer_cache_find_line_by_index(const GBufferCache *, size_t);
/* Fait remonter les largeurs requises par une ligne donnée. */
-void g_buffer_cache_collect_widths(GBufferCache *, size_t, line_width_summary *);
+void g_buffer_cache_collect_widths(GBufferCache *, size_t, size_t, size_t, gint *, gint *);
/* Imprime une partie choisie du tampon contenant des lignes. */
void g_buffer_cache_draw(const GBufferCache *, cairo_t *, size_t, size_t, const cairo_rectangle_int_t *, const GDisplayOptions *, const gint *, const segcnt_list *);
diff --git a/src/glibext/bufferline.c b/src/glibext/bufferline.c
index 3e93c9c..5eec1db 100644
--- a/src/glibext/bufferline.c
+++ b/src/glibext/bufferline.c
@@ -53,10 +53,8 @@ struct _GBufferLine
{
GObject parent; /* A laisser en premier */
- mrange_t range; /* Couverture geographique */
- BufferLineColumn main_column; /* Colonne principale */
-
- line_column columns[BLC_COUNT]; /* Répartition du texte */
+ 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 */
@@ -177,13 +175,10 @@ static void g_buffer_line_class_init(GBufferLineClass *class)
static void g_buffer_line_init(GBufferLine *line)
{
- BufferLineColumn i; /* Boucle de parcours */
-
- for (i = 0; i < BLC_COUNT; i++)
- init_line_column(&line->columns[i]);
-
- line->merge_start = BLC_COUNT;
- line->last_used = BLC_COUNT;
+ line->columns = NULL;
+ line->col_count = 0;
+ line->merge_start = -1;
+ line->last_used = -1;
}
@@ -226,11 +221,14 @@ static void g_buffer_line_dispose(GBufferLine *line)
static void g_buffer_line_finalize(GBufferLine *line)
{
- BufferLineColumn i; /* Boucle de parcours */
+ size_t i; /* Boucle de parcours */
- for (i = 0; i < BLC_COUNT; i++)
+ for (i = 0; i < line->col_count; i++)
reset_line_column(&line->columns[i]);
+ if (line->columns != NULL)
+ free(line->columns);
+
if (line->origins != NULL)
free(line->origins);
@@ -241,7 +239,7 @@ static void g_buffer_line_finalize(GBufferLine *line)
/******************************************************************************
* *
-* Paramètres : main = colonne à référencer comme étant la principale. *
+* Paramètres : col_count = quantité de colonnes à considérer. *
* *
* Description : Crée une nouvelle représentation de fragments de texte. *
* *
@@ -251,13 +249,19 @@ static void g_buffer_line_finalize(GBufferLine *line)
* *
******************************************************************************/
-GBufferLine *g_buffer_line_new(BufferLineColumn main)
+GBufferLine *g_buffer_line_new(size_t col_count)
{
GBufferLine *result; /* Composant à retourner */
+ size_t i; /* Boucle de parcours */
result = g_object_new(G_TYPE_BUFFER_LINE, NULL);
- result->main_column = main;
+ result->columns = malloc(col_count * sizeof(line_column));
+
+ for (i = 0; i < col_count; i++)
+ init_line_column(&result->columns[i]);
+
+ result->col_count = col_count;
return result;
@@ -887,8 +891,11 @@ void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferE
/******************************************************************************
* *
-* Paramètres : line = ligne à venir consulter. *
-* summary = largeurs maximales à faire évoluer. *
+* Paramètres : line = ligne à venir consulter. *
+* col_count = quantité de colonnes à considérer. *
+* opt_count = quantité de colonnes optionnelles. *
+* widths = largeur mesurée pour chacune des colonnes. [OUT] *
+* merged = largeur cumulée en cas de fusion. [OUT] *
* *
* Description : Fait remonter les largeurs requises par une ligne donnée. *
* *
@@ -898,35 +905,32 @@ void g_buffer_line_export(GBufferLine *line, buffer_export_context *ctx, BufferE
* *
******************************************************************************/
-void g_buffer_line_collect_widths(GBufferLine *line, line_width_summary *summary)
+void g_buffer_line_collect_widths(const GBufferLine *line, size_t col_count, size_t opt_count, gint *widths, gint *merged)
{
- gint merged_width; /* Largeur cumulée avant fusion*/
- BufferLineColumn i; /* Boucle de parcours */
+ size_t i; /* Boucle de parcours */
gint width; /* Largeur d'une colonne */
- merged_width = 0;
+ assert(col_count == line->col_count);
- for (i = 0; i < BLC_COUNT; i++)
+ *merged = 0;
+
+ for (i = 0; i < col_count; i++)
{
width = get_column_width(&line->columns[i]);
- if (i < line->merge_start)
- summary->max_widths[i] = MAX(summary->max_widths[i], width);
+ widths[i] = (i < line->merge_start ? width : 0);
- if (i >= BLC_DISPLAY)
+ if (line->merge_start != -1 && i >= opt_count)
{
- merged_width += width;
+ *merged += width;
- if (i < line->merge_start && (i + 1) < BLC_COUNT)
- merged_width += COL_MARGIN;
+ if (i < line->merge_start && (i + 1) < col_count)
+ *merged += COL_MARGIN;
}
}
- if (line->merge_start != BLC_COUNT)
- summary->merged_width = MAX(summary->merged_width, merged_width);
-
}
diff --git a/src/glibext/bufferline.h b/src/glibext/bufferline.h
index b911c21..0e20b37 100644
--- a/src/glibext/bufferline.h
+++ b/src/glibext/bufferline.h
@@ -104,7 +104,7 @@ typedef enum _BufferLineFlags
GType g_buffer_line_get_type(void);
/* Crée une nouvelle représentation de fragments de texte. */
-GBufferLine *g_buffer_line_new(BufferLineColumn);
+GBufferLine *g_buffer_line_new(size_t);
/* Construit le tronc commun d'une ligne autour de sa position. */
void g_buffer_line_fill_phys(GBufferLine *, size_t, MemoryDataSize, const vmpa2t *);
@@ -166,7 +166,7 @@ typedef struct _col_coord_t
/* Fait remonter les largeurs requises par une ligne donnée. */
-void g_buffer_line_collect_widths(GBufferLine *, line_width_summary *);
+void g_buffer_line_collect_widths(const GBufferLine *, size_t, size_t, gint *, gint *);
/* Fournit le segment présent à une position donnée. */
line_segment *g_buffer_line_get_segment_from_coord(const GBufferLine *, const col_coord_t *);
diff --git a/src/glibext/widthtracker.c b/src/glibext/widthtracker.c
index 8ecaad0..f0e2068 100644
--- a/src/glibext/widthtracker.c
+++ b/src/glibext/widthtracker.c
@@ -123,6 +123,7 @@ struct _GWidthTracker
GBufferCache *cache; /* Ensemble complet de lignes */
size_t col_count; /* Nombre maximum de colonnes */
+ size_t opt_count; /* Qté de colonnes en option */
common_metrics *portions; /* Portions représentées */
size_t count; /* Quantité de ces portions */
@@ -472,6 +473,7 @@ static void g_width_tracker_finalize(GWidthTracker *tracker)
* *
* Paramètres : cache = tampon de lignes à lier au futur élément. *
* col_count = quantité maximale de colonnes à considérer. *
+* opt_count = quantité de colonnes optionnelles. *
* *
* Description : Crée un nouveau suivi de largeurs au sein de lignes. *
* *
@@ -481,7 +483,7 @@ static void g_width_tracker_finalize(GWidthTracker *tracker)
* *
******************************************************************************/
-GWidthTracker *g_width_tracker_new(GBufferCache *cache, size_t col_count)
+GWidthTracker *g_width_tracker_new(GBufferCache *cache, size_t col_count, size_t opt_count)
{
GWidthTracker *result; /* Composant à retourner */
@@ -491,6 +493,7 @@ GWidthTracker *g_width_tracker_new(GBufferCache *cache, size_t col_count)
result->cache = cache;
result->col_count = col_count;
+ result->opt_count = opt_count;
result->min_widths = calloc(col_count, sizeof(gint));
@@ -526,6 +529,7 @@ GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *template, siz
result->cache = template->cache;
result->col_count = template->col_count;
+ result->opt_count = template->opt_count;
start = g_width_tracker_find_metrics(template, first);
assert(start < template->count);
@@ -744,7 +748,10 @@ static void g_width_tracker_reset_widths(GWidthTracker *tracker, size_t index)
static const line_width_summary *g_width_tracker_get_up_to_date_widths(GWidthTracker *tracker, size_t index)
{
common_metrics *portion; /* Portion à actualiser */
- size_t i; /* Boucle de parcours */
+ gint *widths; /* Collecte de largeurs */
+ gint merged; /* Collecte de fusion */
+ size_t i; /* Boucle de parcours #1 */
+ size_t k; /* Boucle de parcours #2 */
assert(index < tracker->count);
@@ -758,8 +765,21 @@ static const line_width_summary *g_width_tracker_get_up_to_date_widths(GWidthTra
/* Collecte */
+ widths = malloc(tracker->col_count * sizeof(gint));
+
for (i = portion->first; i <= portion->last; i++)
- g_buffer_cache_collect_widths(tracker->cache, i, &portion->summary);
+ {
+ g_buffer_cache_collect_widths(tracker->cache, i, tracker->col_count, tracker->opt_count,
+ widths, &merged);
+
+ for (k = 0; k < tracker->col_count; k++)
+ portion->summary.max_widths[k] = MAX(portion->summary.max_widths[k], widths[k]);
+
+ portion->summary.merged_width = MAX(portion->summary.merged_width, merged);
+
+ }
+
+ free(widths);
/* Marquage pour mémoire */
@@ -1160,44 +1180,6 @@ static void g_width_tracker_ensure_valid_required_widths(GWidthTracker *tracker)
/******************************************************************************
* *
* Paramètres : tracker = suivi de largeurs à consulter. *
-* index = indice de la ligne dont la portion est recherchée. *
-* summary = ensemble ciblé de largeurs collectées. [OUT] *
-* *
-* Description : Fournit un résumé local des largeurs en vigueur. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_width_tracker_get_local_width_summary(GWidthTracker *tracker, size_t index, line_width_summary *summary)
-{
- size_t current; /* Indice de portion visée */
- const line_width_summary *local; /* Valeurs à intégrer */
- BufferLineColumn i; /* Boucle de parcours */
-
- g_width_tracker_ensure_valid_required_widths(tracker);
-
- current = g_width_tracker_find_metrics(tracker, index);
- assert(current < tracker->count);
-
- local = g_width_tracker_get_up_to_date_widths(tracker, current);
-
- for (i = BLC_FIRST; i < BLC_DISPLAY; i++)
- summary->max_widths[i] = tracker->summary.max_widths[i];
-
- for (i = BLC_DISPLAY; i < BLC_COUNT; i++)
- summary->max_widths[i] = local->max_widths[i];
-
- summary->merged_width = local->merged_width;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : tracker = suivi de largeurs à consulter. *
* options = règles d'affichage des colonnes modulables. *
* *
* Description : Fournit la largeur requise par une visualisation. *
diff --git a/src/glibext/widthtracker.h b/src/glibext/widthtracker.h
index 82442ae..4920f9b 100644
--- a/src/glibext/widthtracker.h
+++ b/src/glibext/widthtracker.h
@@ -29,7 +29,6 @@
#include <stdbool.h>
-//#include "bufferline.h"
#include "delayed.h"
#include "gdisplayoptions.h"
@@ -72,7 +71,7 @@ typedef struct _GWidthTrackerClass GWidthTrackerClass;
GType g_width_tracker_get_type(void);
/* Crée un nouveau suivi de largeurs au sein de lignes. */
-GWidthTracker *g_width_tracker_new(GBufferCache *, size_t);
+GWidthTracker *g_width_tracker_new(GBufferCache *, size_t, size_t);
/* Crée un nouveau suivi de largeurs au sein de lignes. */
GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *, size_t, size_t);
@@ -95,9 +94,6 @@ void g_width_tracker_update_deleted(GWidthTracker *, size_t, size_t);
/* Calcule les largeurs requises par un ensemble de lignes. */
void g_width_tracker_build_initial_cache(GWidthTracker *, wgroup_id_t, GtkStatusStack *);
-/* Fournit un résumé local des largeurs en vigueur. */
-void g_width_tracker_get_local_width_summary(GWidthTracker *, size_t, line_width_summary *);
-
/* Fournit la largeur requise par une visualisation. */
gint g_width_tracker_get_width(GWidthTracker *, const GDisplayOptions *);
diff --git a/src/gtkext/hexdisplay.c b/src/gtkext/hexdisplay.c
index cf1f600..ea662ae 100644
--- a/src/gtkext/hexdisplay.c
+++ b/src/gtkext/hexdisplay.c
@@ -191,7 +191,7 @@ GtkWidget *gtk_hex_display_new(GBinContent *content)
result = g_object_new(GTK_TYPE_HEX_DISPLAY, NULL);
- result->cache = g_buffer_cache_new(content, HLC_COUNT);
+ result->cache = g_buffer_cache_new(content, HLC_COUNT, HLC_BINARY);
g_object_ref_sink(G_OBJECT(result->cache));
g_generic_config_get_value(get_main_configuration(), MPK_HEX_PADDING, &padding);