diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2012-12-16 21:55:04 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2012-12-16 21:55:04 (GMT) |
commit | 64e09a6c3e39785975b5322973ed83734cedb82e (patch) | |
tree | a87d29cca9d86ccd26676460282ddf59c4e9cb17 /src/analysis/disass | |
parent | 2581d80875304c466e8930dbe67986ceb95752b2 (diff) |
Reintroduced the delayed disassembling of binaries.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@304 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/disass')
-rw-r--r-- | src/analysis/disass/disassembler.c | 40 | ||||
-rw-r--r-- | src/analysis/disass/disassembler.h | 31 | ||||
-rw-r--r-- | src/analysis/disass/output.c | 25 | ||||
-rw-r--r-- | src/analysis/disass/output.h | 3 |
4 files changed, 64 insertions, 35 deletions
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index ee56043..e7c972d 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -48,16 +48,8 @@ /* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */ -#define G_TYPE_DELAYED_DISASSEMBLY g_delayed_disassembly_get_type() -#define G_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_disassembly_get_type(), GDelayedDisassembly)) -#define G_IS_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_disassembly_get_type())) -#define G_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) -#define G_IS_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DELAYED_DISASSEMBLY)) -#define G_DELAYED_DISASSEMBLY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) - - /* Ensembles binaires à désassembler (instance) */ -typedef struct _GDelayedDisassembly +struct _GDelayedDisassembly { GDelayedWork parent; /* A laisser en premier */ @@ -70,19 +62,16 @@ typedef struct _GDelayedDisassembly GArchInstruction **instrs; /* Instructions résultantes */ GCodeBuffer *buffer; /* Tampon pour le rendu */ -} GDelayedDisassembly; +}; /* Ensembles binaires à désassembler (classe) */ -typedef struct _GDelayedDisassemblyClass +struct _GDelayedDisassemblyClass { GDelayedWorkClass parent; /* A laisser en premier */ -} GDelayedDisassemblyClass; +}; -/* Indique le type défini pour les tâches de désassemblage différé. */ -static GType g_delayed_disassembly_get_type(void); - /* Initialise la classe des tâches de désassemblage différé. */ static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *); @@ -99,6 +88,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar /* -------------------------- GESTION GLOBALE DE PROCEDURE -------------------------- */ + /* Construit la description d'introduction du désassemblage. */ static void build_disass_prologue(GCodeBuffer *, const char *, const uint8_t *, off_t); @@ -242,7 +232,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta #endif - run_plugins_on_binary(disass->binary, PGA_BINARY_DISASSEMBLED); + run_plugins_on_binary(disass->binary, PGA_BINARY_DISASSEMBLED, true); /* Seconde étape */ @@ -252,7 +242,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta gtk_extended_status_bar_remove(statusbar, id); - run_plugins_on_binary(disass->binary, PGA_BINARY_LINKED); + run_plugins_on_binary(disass->binary, PGA_BINARY_LINKED, true); /* Troisième étape */ @@ -264,7 +254,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta gtk_extended_status_bar_remove(statusbar, id); - run_plugins_on_binary(disass->binary, PGA_BINARY_BOUNDED); + run_plugins_on_binary(disass->binary, PGA_BINARY_BOUNDED, true); /* Quatrième étape */ @@ -276,7 +266,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta gtk_extended_status_bar_remove(statusbar, id); - run_plugins_on_binary(disass->binary, PGA_BINARY_GROUPED); + run_plugins_on_binary(disass->binary, PGA_BINARY_GROUPED, true); /* Cinquième étape */ @@ -285,11 +275,11 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_compare); print_disassembled_instructions(disass->buffer, disass->format, *disass->instrs, - routines, routines_count); + routines, routines_count, statusbar, id); gtk_extended_status_bar_remove(statusbar, id); - run_plugins_on_binary(disass->binary, PGA_BINARY_PRINTED); + run_plugins_on_binary(disass->binary, PGA_BINARY_PRINTED, true); } @@ -395,6 +385,7 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con * count = nombre de parties à traiter. * * instrs = liste des instructions chargées. [OUT] * * buffer = tampon de code mis en place. [OUT] * +* ack = fonction à appeler une fois l'opération terminée. * * * * Description : Procède au désassemblage d'un contenu binaire donné. * * * @@ -404,7 +395,7 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con * * ******************************************************************************/ -void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer) +void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer, disassembly_ack_fc ack) { const uint8_t *data; /* Données binaires brutes */ off_t length; /* Quantité de ces données */ @@ -417,12 +408,9 @@ void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_co build_disass_prologue(*buffer, g_loaded_binary_get_filename(binary, true), data, length); disass = g_delayed_disassembly_new(binary, parts, parts_count, instrs, *buffer); + g_signal_connect(disass, "work-completed", G_CALLBACK(ack), binary); queue = get_work_queue(); g_work_queue_schedule_work(queue, G_DELAYED_WORK(disass)); - g_delayed_work_wait_for_completion(G_DELAYED_WORK(disass)); - - g_object_unref(G_OBJECT(disass)); - } diff --git a/src/analysis/disass/disassembler.h b/src/analysis/disass/disassembler.h index 8cca194..b7c286c 100644 --- a/src/analysis/disass/disassembler.h +++ b/src/analysis/disass/disassembler.h @@ -30,8 +30,37 @@ +/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */ + + +#define G_TYPE_DELAYED_DISASSEMBLY g_delayed_disassembly_get_type() +#define G_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_disassembly_get_type(), GDelayedDisassembly)) +#define G_IS_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_disassembly_get_type())) +#define G_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) +#define G_IS_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DELAYED_DISASSEMBLY)) +#define G_DELAYED_DISASSEMBLY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) + + +/* Ensembles binaires à désassembler (instance) */ +typedef struct _GDelayedDisassembly GDelayedDisassembly; + +/* Ensembles binaires à désassembler (classe) */ +typedef struct _GDelayedDisassemblyClass GDelayedDisassemblyClass; + + +/* Indique le type défini pour les tâches de désassemblage différé. */ +GType g_delayed_disassembly_get_type(void); + + + +/* -------------------------- GESTION GLOBALE DE PROCEDURE -------------------------- */ + + +/* Acquitte la fin d'un désasemblage différé et complet. */ +typedef void (* disassembly_ack_fc) (GDelayedDisassembly *, GLoadedBinary *); + /* Procède à la décompilation des routines d'un fichier donné. */ -void disassemble_binary(GLoadedBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **); +void disassemble_binary(GLoadedBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **, disassembly_ack_fc); diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c index 812b811..135168e 100644 --- a/src/analysis/disass/output.c +++ b/src/analysis/disass/output.c @@ -32,10 +32,13 @@ /****************************************************************************** * * -* Paramètres : buffer = tampon de récueil des résultats d'impression. * -* instrs = ensemble d'instructions à traiter. * -* routines = liste de routines intervenant dans le flot. * -* count = quantité de ces routines. * +* Paramètres : buffer = tampon de récueil des résultats d'impression. * +* format = format du binaire traité. * +* instrs = ensemble d'instructions à traiter. * +* routines = liste de routines intervenant dans le flot. * +* count = quantité de ces routines. * +* statusbar = barre de statut avec progression à mettre à jour.* +* id = identifiant du message affiché à l'utilisateur. * * * * Description : Transcrit du code désassemblé en texte humainement lisible. * * * @@ -45,12 +48,14 @@ * * ******************************************************************************/ -void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *format, const GArchInstruction *instrs, GBinRoutine * const *routines, size_t count) +void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *format, const GArchInstruction *instrs, GBinRoutine * const *routines, size_t count, GtkExtStatusBar *statusbar, guint id) { GLangOutput *output; /* Modèle de sortie adéquat */ GArchProcessor *proc; /* Architecture du binaire */ MemoryDataSize msize; /* Taille du bus d'adresses */ const bin_t *content; /* Contenu binaire global */ + vmpa_t start; /* Adresse de départ */ + vmpa_t end; /* Adresse de fin */ const GArchInstruction *iter; /* Boucle de parcours #1 */ size_t i; /* Boucle de parcours #2 */ vmpa_t iaddr; /* Adresse d'instruction */ @@ -63,16 +68,20 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form content = g_binary_format_get_content(G_BIN_FORMAT(format), NULL); + g_arch_instruction_get_location(instrs, NULL, NULL, &start); + iter = g_arch_instruction_find_last(instrs); + g_arch_instruction_get_location(iter, NULL, NULL, &end); + for (iter = instrs, i = 0; iter != NULL; iter = g_arch_instruction_get_next_iter(instrs, iter, VMPA_MAX)) { + g_arch_instruction_get_location(iter, NULL, NULL, &iaddr); + /* Ajout des prototypes de fonction */ for (; i < count; i++) { - g_arch_instruction_get_location(iter, NULL, NULL, &iaddr); raddr = g_binary_routine_get_address(routines[i]); - if (raddr > iaddr) break; g_binary_routine_output_info(routines[i], output, buffer); @@ -81,6 +90,8 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form g_arch_instruction_print(iter, buffer, msize, content, ASX_INTEL); + gtk_extended_status_bar_update_activity(statusbar, id, (iaddr - start) * 1.0 / (end - start)); + } g_object_unref(G_OBJECT(output)); diff --git a/src/analysis/disass/output.h b/src/analysis/disass/output.h index 7e0a3cc..81c028d 100644 --- a/src/analysis/disass/output.h +++ b/src/analysis/disass/output.h @@ -28,11 +28,12 @@ #include "../routine.h" #include "../../arch/instruction.h" #include "../../glibext/gcodebuffer.h" +#include "../../gtkext/gtkextstatusbar.h" /* Transcrit du code désassemblé en texte humainement lisible. */ -void print_disassembled_instructions(GCodeBuffer *, const GExeFormat *, const GArchInstruction *, GBinRoutine * const *, size_t); +void print_disassembled_instructions(GCodeBuffer *, const GExeFormat *, const GArchInstruction *, GBinRoutine * const *, size_t, GtkExtStatusBar *, guint); |