summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-12-20 00:28:36 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-12-20 00:28:36 (GMT)
commit56deaf395c65658102ef0111cfc072d65335331a (patch)
treeba6d6fd0dbc781e9ad3b3cf6b2eb529a7d7a6aa3 /src/analysis
parentd9fdfcf887a7a596a68db2500bb5e4d0b692abb6 (diff)
Begun to clean the code by moving the disassembling process into disass/.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@202 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis')
-rwxr-xr-xsrc/analysis/Makefile.am5
-rw-r--r--src/analysis/binary.c529
-rw-r--r--src/analysis/binary.h3
-rw-r--r--src/analysis/decomp/decompiler.c29
-rw-r--r--src/analysis/disass/Makefile.am17
-rw-r--r--src/analysis/disass/disassembler.c374
-rw-r--r--src/analysis/disass/disassembler.h38
-rw-r--r--src/analysis/disass/fetch.c109
-rw-r--r--src/analysis/disass/fetch.h38
-rw-r--r--src/analysis/disass/links.c115
-rw-r--r--src/analysis/disass/links.h37
-rw-r--r--src/analysis/disass/output.c59
-rw-r--r--src/analysis/disass/output.h39
13 files changed, 883 insertions, 509 deletions
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am
index 604835d..e59b648 100755
--- a/src/analysis/Makefile.am
+++ b/src/analysis/Makefile.am
@@ -16,7 +16,8 @@ libanalysis_la_SOURCES = \
variable.h variable.c
libanalysis_la_LIBADD = \
- decomp/libanalysisdecomp.la
+ decomp/libanalysisdecomp.la \
+ disass/libanalysisdisass.la
libanalysis_la_LDFLAGS =
@@ -27,4 +28,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = decomp
+SUBDIRS = decomp disass
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 4093f6e..f13a887 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -41,10 +41,11 @@
#include "line_comment.h" /* TODO : supprimer ? */
#include "line_prologue.h"
#include "routine.h"
+#include "decomp/decompiler.h"
+#include "disass/disassembler.h"
#include "../common/cpp.h"
#include "../common/extstr.h"
#include "../debug/break.h"
-#include "../glibext/delayed-int.h"
#include "../format/format.h"
#include "../panels/log.h"
#include "../plugins/pglist.h"
@@ -59,56 +60,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
-{
- GDelayedWork parent; /* A laisser en premier */
-
- GOpenidaBinary *binary; /* Destinataire final */
-
- GBinPart **parts; /* Parties binaires à traiter */
- size_t count; /* Nombre de ces parties */
-
- GRenderingLine *lines; /* Lignes de rendu résultantes */
-
-} GDelayedDisassembly;
-
-/* Ensembles binaires à désassembler (classe) */
-typedef 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 *);
-
-/* Initialise une tâche de désassemblage différé. */
-static void g_delayed_disassembly_init(GDelayedDisassembly *);
-
-/* Crée une tâche de désassemblage différé. */
-static GDelayedDisassembly *g_delayed_disassembly_new(GOpenidaBinary *, GBinPart **, size_t);
-
-/* Assure le désassemblage en différé. */
-static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar *);
-
-/* Procède au désassemblage basique d'un contenu binaire. */
-static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *, GBinRoutine **, size_t, GtkExtStatusBar *, guint);
+#if 0
-/* Etablit les liens entres les différentes lignes de code. */
-static void establish_links_between_lines(GRenderingLine *, GBinRoutine **, size_t, GtkExtStatusBar *, guint);
/* S'assure que toutes les routines ont une taille définie. */
static void limit_all_routines(GRenderingLine *, GBinRoutine **, size_t, GtkExtStatusBar *, guint);
@@ -118,6 +71,7 @@ static vmpa_t find_best_ending_address_for_routine(GRenderingLine *, size_t, con
+#endif
@@ -142,6 +96,7 @@ struct _GOpenidaBinary
GRenderingLine *lines; /* Lignes de rendu en place */
GRenderingOptions *options; /* Options de désassemblage */
+ GCodeBuffer *disass_buffer; /* Instructions lisibles */
GCodeBuffer **dec_buffers; /* Sources sous forme de texte */
size_t decbuf_count; /* Taille des tableaux */
size_t defsrc; /* Fichier source principal */
@@ -173,11 +128,8 @@ static void g_openida_binary_init(GOpenidaBinary *);
/* Charge en mémoire le contenu d'un fichier. */
bin_t *map_binary_file(const char *, off_t *);
-/* Construit la description d'introduction du désassemblage. */
-GRenderingLine *build_binary_prologue(const char *, const uint8_t *, off_t);
-
/* Acquitte la fin d'un désasemblage différé et complet. */
-void ack_completed_disassembly(GDelayedDisassembly *, GOpenidaBinary *);
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *, GOpenidaBinary *);
@@ -193,361 +145,9 @@ static void g_openida_binary_breakpoint_added(GBreakGroup *, GBreakPoint *, GOpe
static void g_openida_binary_breakpoint_removed(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
-
-/* ---------------------------------------------------------------------------------- */
-/* DESASSEMBLAGE DE BINAIRE DIFFERE */
-/* ---------------------------------------------------------------------------------- */
-
-
-/* Indique le type défini pour les tâches de désassemblage différé. */
-G_DEFINE_TYPE(GDelayedDisassembly, g_delayed_disassembly, G_TYPE_DELAYED_WORK);
-
-
-/******************************************************************************
-* *
-* Paramètres : klass = classe à initialiser. *
-* *
-* Description : Initialise la classe des tâches de désassemblage différé. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *klass)
-{
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : disass = instance à initialiser. *
-* *
-* Description : Initialise une tâche de désassemblage différé. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
-{
- G_DELAYED_WORK(disass)->run = (run_task_fc)g_delayed_disassembly_process;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = binaire chargé en attente des résultats. *
-* parts = parties binaires à désassembler. *
-* count = nombre de parties à traiter. *
-* *
-* Description : Crée une tâche de désassemblage différé. *
-* *
-* Retour : Tâche créée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static GDelayedDisassembly *g_delayed_disassembly_new(GOpenidaBinary *binary, GBinPart **parts, size_t count)
-{
- GDelayedDisassembly *result; /* Tâche à retourner */
-
- result = g_object_new(G_TYPE_DELAYED_DISASSEMBLY, NULL);
-
- result->binary = binary;
-
- result->parts = parts;
- result->count = count;
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : disass = analyse à mener. *
-* statusbar = barre de statut à tenir informée. *
-* *
-* Description : Assure le désassemblage en différé. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtStatusBar *statusbar)
-{
- GBinRoutine **routines; /* Liste des routines trouvées */
- size_t routines_count; /* Nombre de ces routines */
- guint id; /* Identifiant de statut */
-
- routines = g_binary_format_get_routines(G_BIN_FORMAT(disass->binary->format), &routines_count);
- qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_rcompare);
-
- /* Première étape */
-
- id = gtk_extended_status_bar_push(statusbar, _("Disassembling..."), true);
-
- disass->lines = disassemble_binary_parts(disass, routines, routines_count, statusbar, id);
-
- gtk_extended_status_bar_remove(statusbar, id);
-
- /* Seconde étape */
-
- id = gtk_extended_status_bar_push(statusbar, _("Establishing links..."), true);
-
- establish_links_between_lines(disass->lines, routines, routines_count, statusbar, id);
-
- gtk_extended_status_bar_remove(statusbar, id);
-
- /* Troisième étape */
-
- id = gtk_extended_status_bar_push(statusbar, _("Finding remaining limits..."), true);
-
- limit_all_routines(disass->lines, routines, routines_count, statusbar, id);
-
- gtk_extended_status_bar_remove(statusbar, id);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : disass = tâche à l'origine du traitement. *
-* routines = prototypes existants à insérer. *
-* count = quantité de ces prototypes. *
-* statusbar = barre de statut avec progression à mettre à jour.*
-* id = identifiant du message affiché à l'utilisateur. *
-* *
-* Description : Procède au désassemblage basique d'un contenu binaire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id)
-{
- GRenderingLine *result; /* Ligne de rendu à retourner */
- GArchInstruction *first; /* Première instruction vue */
- GArchProcessor *proc; /* Architecture du binaire */
- GRenderingOptions *options; /* Options de désassemblage */
- bin_t *bin_data; /* Données binaires à lire */
- size_t i; /* Boucle de parcours #1 */
- off_t sum; /* Somme de toutes les tailles */
- off_t done; /* Quantité déjà traitée */
- off_t pos; /* Début d'une zone binaire */
- off_t len; /* Taille de cette même zone */
- vmpa_t base; /* Adresse de la zone binaire */
- off_t start; /* Conservation du pt de départ*/
- vmpa_t addr; /* Adresse d'une instruction */
- GArchInstruction *instr; /* Instruction décodée */
- GRenderingLine *line; /* Nouvelle ligne de rendu */
- size_t k; /* Boucle de parcours #2 */
- uint64_t routine_offset; /* Point de départ de routine */
- char *routine_desc; /* Prototype d'une routine */
-
- result = NULL;
-
- first = NULL;
-
- proc = get_arch_processor_from_format(g_openida_binary_get_format(disass->binary));
- options = g_openida_binary_get_options(disass->binary);
- bin_data = g_openida_binary_get_data(disass->binary, NULL);
-
- /* Préparation du suivi de la progression */
-
- sum = 0;
-
- for (i = 0; i < disass->count; i++)
- {
- g_binary_part_get_values(disass->parts[i], NULL, &len, NULL);
- if (len > disass->binary->bin_length) continue;
- sum += len;
- }
-
- done = 0;
-
- k = 0;
-
- for (i = 0; i < disass->count; i++)
- {
- g_binary_part_get_values(disass->parts[i], &pos, &len, &base);
-
- if (len > disass->binary->bin_length) continue;
-
- /* Décodage des instructions */
-
- start = pos;
- pos = 0;
-
- while (pos < len)
- {
- addr = base + pos;
-
- instr = g_arch_processor_decode_instruction(proc, &bin_data[start],
- &pos, len, start, addr);
- g_arch_instruction_add_to_list(&first, instr);
-
- line = g_code_line_new(addr, instr, options);
- g_rendering_line_add_to_lines(&result, line);
-
- /* Ajout des prototypes de fonctions */
-
- for (; k < count; k++)
- {
- routine_offset = g_binary_routine_get_address(routines[k]);
-
- if (routine_offset > addr) break;
-
- routine_desc = g_binary_routine_to_string(routines[k]);
-
- line = g_comment_line_new(routine_offset, routine_desc, options);
- g_rendering_line_insert_into_lines(&result, line, true);
-
- free(routine_desc);
-
- }
-
- if (pos < len)
- gtk_extended_status_bar_update_activity(statusbar, id, (done + pos) * 1.0 / sum);
-
- }
-
- done += len;
- gtk_extended_status_bar_update_activity(statusbar, id, done * 1.0 / sum);
#if 0
- /* Ajout des prototypes de fonctions */
-
- printf("BASE == 0x%08llx\n", base);
-
- for (; k < count; k++)
- {
- routine_offset = g_binary_routine_get_address(routines[k]);
-
- if (!(base <= routine_offset && routine_offset < (base + len))) continue;
- routine_desc = g_binary_routine_to_string(routines[k]);
- line = g_comment_line_new(routine_offset, routine_desc, options);
- g_rendering_line_insert_into_lines(&result, line, true);
-
- free(routine_desc);
-
- }
-#endif
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : lines = lignes de rendu à relier. *
-* routines = prototypes existants à insérer. *
-* count = quantité de ces prototypes. *
-* statusbar = barre de statut avec progression à mettre à jour.*
-* id = identifiant du message affiché à l'utilisateur. *
-* *
-* Description : Etablit les liens entres les différentes lignes de code. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void establish_links_between_lines(GRenderingLine *lines, GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id)
-{
- size_t i; /* Boucle de parcours */
- vmpa_t start; /* Adresse de départ */
- vmpa_t end; /* Adresse de fin */
- GRenderingLine *iter; /* Boucle de parcours */
- GArchInstruction *instr; /* Instruction à ausculter */
- vmpa_t addr; /* Adresse référencée */
- InstructionLinkType type; /* Type de référence */
- GRenderingLine *target; /* Ligne visée par la référence*/
-
- for (i = 0; i < count; i++)
- {
- start = g_binary_routine_get_address(routines[i]);
- end = start + g_binary_routine_get_size(routines[i]);
-
- for (iter = g_rendering_line_find_by_address(lines, NULL, start);
- iter != NULL;
- iter = g_rendering_line_get_next_iter(lines, iter, NULL))
- {
- /* Si on sort de la zone... */
- if (get_rendering_line_address(iter) >= end) break;
-
- /* On ne traite que du code ici ! */
- if (!G_IS_CODE_LINE(iter)) continue;
-
- instr = g_code_line_get_instruction(G_CODE_LINE(iter));
- type = g_arch_instruction_get_link(instr, &addr);
-
- switch (type)
- {
- case ILT_NONE:
- break;
-
- case ILT_JUMP:
-
- target = g_rendering_line_find_by_address(lines, NULL, addr);
-
- if (target != NULL)
- g_rendering_line_link_with(iter, target, type);
-
- break;
-
- case ILT_JUMP_IF_FALSE:
- break;
-
- case ILT_JUMP_IF_TRUE:
-
- target = g_rendering_line_find_by_address(lines, NULL, addr);
-
- if (target != NULL)
- {
- g_rendering_line_link_with(iter, target, type);
-
- target = g_rendering_line_get_next_iter(lines, iter, NULL);
- if (target != NULL)
- g_rendering_line_link_with(iter, target, ILT_JUMP_IF_FALSE);
-
- }
-
- break;
-
- case ILT_CALL:
-
- target = g_rendering_line_find_by_address(lines, NULL, addr);
-
- if (target != NULL)
- g_rendering_line_link_with(iter, target, type);
-
- break;
-
- }
-
- }
-
- gtk_extended_status_bar_update_activity(statusbar, id, (i + 1) * 1.0 / count);
-
- }
-
-}
/******************************************************************************
@@ -696,7 +296,7 @@ static vmpa_t find_best_ending_address_for_routine(GRenderingLine *line, size_t
}
-
+#endif
@@ -806,7 +406,7 @@ GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
break;
}
- result->lines = build_binary_prologue(filename, result->bin_data, result->bin_length);
+ result->lines = NULL;
result->proc = get_arch_processor_from_format(result->format);
@@ -1148,13 +748,8 @@ GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *binary, BinaryPartM
void g_openida_binary_analyse(GOpenidaBinary *binary)
{
- GWorkQueue *queue; /* Gestionnaire de différés */
GBinPart **parts; /* Parties d'élément binaire */
size_t parts_count; /* Nombre de ces parties */
- GDelayedDisassembly *disass; /* Désassemblage à mener */
-
- queue = get_work_queue();
-
if (binary->parts_count[BPM_ROUTINES] > 0)
binary->model = BPM_ROUTINES;
@@ -1179,12 +774,10 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
}
}
- disass = g_delayed_disassembly_new(binary, parts, parts_count);
+ binary->disass_buffer = disassemble_binary(binary, parts, parts_count);
- g_signal_connect(disass, "work-completed",
- G_CALLBACK(ack_completed_disassembly), binary);
-
- g_work_queue_schedule_work(queue, G_DELAYED_WORK(disass));
+ /* TODO : remme ! */
+ ack_completed_disassembly(NULL, binary);
}
@@ -1363,6 +956,25 @@ GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *binary
/******************************************************************************
* *
* Paramètres : binary = élément binaire à consulter. *
+* *
+* Description : Fournit le tampon associé au contenu assembleur d'un binaire.*
+* *
+* Retour : Tampon mis en place ou NULL si aucun (!). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *binary)
+{
+ return binary->disass_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
* index = indice du fichier à retrouver. *
* *
* Description : Fournit le tampon associé au contenu d'un fichier source. *
@@ -1443,82 +1055,6 @@ bin_t *map_binary_file(const char *filename, off_t *length)
/******************************************************************************
* *
-* Paramètres : filename = nom du fichier chargé. *
-* data = données en mémoire pour l'empreinte. *
-* length = quantité de données à prendre en compte. *
-* *
-* Description : Construit la description d'introduction du désassemblage. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingLine *build_binary_prologue(const char *filename, const uint8_t *data, off_t length)
-{
- GRenderingLine *result; /* Contenu à renvoyer */
- size_t len; /* Taille du texte */
- char *content; /* Contenu textuel d'une ligne */
- GRenderingLine *line; /* Représentation à ajouter */
- GChecksum *checksum; /* Calcul de l'empreinte */
- const gchar *hex; /* Valeur hexadécimale du SHA */
-
- result = NULL;/* FIXME DL_LIST_HEAD_INIT( **/
-
- line = g_prologue_line_new(_("Disassembly generated by OpenIDA"));
- g_rendering_line_add_to_lines(&result, line);
-
- line = g_prologue_line_new("OpenIDA is free software - © 2008-2010 Cyrille Bagard");
- g_rendering_line_add_to_lines(&result, line);
-
- line = g_prologue_line_new("");
- g_rendering_line_add_to_lines(&result, line);
-
- /* Fichier */
-
- len = strlen(_("File: ")) + strlen(filename);
- content = (char *)calloc(len + 1, sizeof(char));
-
- snprintf(content, len + 1, "%s%s", _("File: "), filename);
-
- line = g_prologue_line_new(content);
- g_rendering_line_add_to_lines(&result, line);
-
- free(content);
-
- /* Checksum SHA256 */
-
- checksum = g_checksum_new(G_CHECKSUM_SHA256);
-
- g_checksum_update(checksum, data, length);
- hex = g_checksum_get_string(checksum);
-
- len = strlen(_("Sha256: ")) + strlen(hex);
- content = (char *)calloc(len + 1, sizeof(char));
-
- snprintf(content, len + 1, "%s%s", _("Sha256: "), hex);
-
- g_checksum_free(checksum);
-
- line = g_prologue_line_new(content);
- g_rendering_line_add_to_lines(&result, line);
-
- free(content);
-
- line = g_prologue_line_new("");
- g_rendering_line_add_to_lines(&result, line);
-
- line = g_prologue_line_new("");
- g_rendering_line_add_to_lines(&result, line);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : disass = travail de désassemblage mené à bien. *
* binary = représentation de binaire à l'origine de l'opérat°. *
* *
@@ -1530,7 +1066,7 @@ GRenderingLine *build_binary_prologue(const char *filename, const uint8_t *data,
* *
******************************************************************************/
-void ack_completed_disassembly(GDelayedDisassembly *disass, GOpenidaBinary *binary)
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GOpenidaBinary *binary)
{
GRenderingLine *line; /* "Première" ligne de rendu */
GPluginModule **pglist; /* Liste de greffons */
@@ -1556,7 +1092,7 @@ void ack_completed_disassembly(GDelayedDisassembly *disass, GOpenidaBinary *bina
-
+#if 0
g_rendering_line_merge(&binary->lines, &disass->lines);
@@ -1580,6 +1116,7 @@ void ack_completed_disassembly(GDelayedDisassembly *disass, GOpenidaBinary *bina
}
/* On réintègre le flot premier */
+#endif
g_signal_emit_by_name(binary, "disassembly-done");
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index cac3b86..1de0970 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -109,6 +109,9 @@ GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *);
/* Fournit les instructions issues du désassemblage. */
GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *);
+/* Fournit le tampon associé au contenu assembleur d'un binaire. */
+GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *);
+
/* Fournit le tampon associé au contenu d'un fichier source. */
GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *, size_t);
diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c
index c446c0e..de1b6d2 100644
--- a/src/analysis/decomp/decompiler.c
+++ b/src/analysis/decomp/decompiler.c
@@ -1,6 +1,6 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
- * decompiler.h - prototypes pour l'encadrement des phases de décompilation
+ * decompiler.c - encadrement des phases de décompilation
*
* Copyright (C) 2010 Cyrille Bagard
*
@@ -68,17 +68,20 @@ static void build_decomp_prologue(GCodeBuffer *buffer, const char *filename)
output = g_java_output_new();
+ line = g_lang_output_start_comments(output, buffer);
+ if (line != NULL) g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
/* Introduction */
- line = g_lang_output_write_comments(output, buffer,
- SL(_("Binary data decompiled by OpenIDA")));
+ line = g_lang_output_continue_comments(output, buffer,
+ SL(_("Binary data decompiled by OpenIDA")));
g_buffer_line_start_merge_at(line, BLC_ADDRESS);
- line = g_lang_output_write_comments(output, buffer,
- SL(_("OpenIDA is free software - © 2008-2010 Cyrille Bagard")));
+ line = g_lang_output_continue_comments(output, buffer,
+ SL(_("OpenIDA is free software - © 2008-2010 Cyrille Bagard")));
g_buffer_line_start_merge_at(line, BLC_ADDRESS);
- line = g_lang_output_write_comments(output, buffer, NULL, 0);
+ line = g_lang_output_continue_comments(output, buffer, NULL, 0);
g_buffer_line_start_merge_at(line, BLC_ADDRESS);
/* Fichier */
@@ -91,18 +94,22 @@ static void build_decomp_prologue(GCodeBuffer *buffer, const char *filename)
snprintf(content, len, "%s%s", _("File: "), filename);
- line = g_lang_output_write_comments(output, buffer, content, len - 1);
+ line = g_lang_output_continue_comments(output, buffer, content, len - 1);
g_buffer_line_start_merge_at(line, BLC_ADDRESS);
free(content);
- /* Lignes de séparation */
+ /* Ligne de séparation */
- line = g_lang_output_write_comments(output, buffer, NULL, 0);
+ line = g_lang_output_continue_comments(output, buffer, NULL, 0);
g_buffer_line_start_merge_at(line, BLC_ADDRESS);
- line = g_lang_output_write_comments(output, buffer, NULL, 0);
- g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+ /* Conclusion */
+
+ line = g_lang_output_end_comments(output, buffer);
+ if (line != NULL) g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ g_object_unref(G_OBJECT(output));
}
diff --git a/src/analysis/disass/Makefile.am b/src/analysis/disass/Makefile.am
new file mode 100644
index 0000000..784731a
--- /dev/null
+++ b/src/analysis/disass/Makefile.am
@@ -0,0 +1,17 @@
+
+noinst_LTLIBRARIES = libanalysisdisass.la
+
+libanalysisdisass_la_SOURCES = \
+ disassembler.h disassembler.c \
+ fetch.h fetch.c \
+ links.h links.c \
+ output.h output.c
+
+libanalysisdisass_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
new file mode 100644
index 0000000..4004de9
--- /dev/null
+++ b/src/analysis/disass/disassembler.c
@@ -0,0 +1,374 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * disassembler.c - encadrement des phases de désassemblage
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "disassembler.h"
+
+
+#include <malloc.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#include <i18n.h>
+
+
+#include "fetch.h"
+#include "links.h"
+#include "output.h"
+#include "../../decomp/lang/asm.h"
+#include "../../format/format.h"
+#include "../../glibext/delayed-int.h"
+
+
+
+/* ------------------------ 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
+{
+ GDelayedWork parent; /* A laisser en premier */
+
+ const GOpenidaBinary *binary; /* Destinataire final */
+ const GBinFormat *format; /* Format du binaire représenté*/
+
+ GBinPart **parts; /* Parties binaires à traiter */
+ size_t count; /* Nombre de ces parties */
+
+ GArchInstruction *instrs; /* Instructions résultantes */
+ GCodeBuffer *buffer; /* Tampon pour le rendu */
+
+} GDelayedDisassembly;
+
+/* Ensembles binaires à désassembler (classe) */
+typedef 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 *);
+
+/* Initialise une tâche de désassemblage différé. */
+static void g_delayed_disassembly_init(GDelayedDisassembly *);
+
+/* Crée une tâche de désassemblage différé. */
+static GDelayedDisassembly *g_delayed_disassembly_new(const GOpenidaBinary *, GBinPart **, size_t, GCodeBuffer *);
+
+/* Assure le désassemblage en différé. */
+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);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DESASSEMBLAGE DE BINAIRE DIFFERE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour les tâches de désassemblage différé. */
+G_DEFINE_TYPE(GDelayedDisassembly, g_delayed_disassembly, G_TYPE_DELAYED_WORK);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des tâches de désassemblage différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : disass = instance à initialiser. *
+* *
+* Description : Initialise une tâche de désassemblage différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
+{
+ G_DELAYED_WORK(disass)->run = (run_task_fc)g_delayed_disassembly_process;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = binaire chargé en attente des résultats. *
+* format = format du binaire représenté. *
+* parts = parties binaires à désassembler. *
+* count = nombre de parties à traiter. *
+* buffer = tampon de sortie pour les instructions. *
+* *
+* Description : Crée une tâche de désassemblage différé. *
+* *
+* Retour : Tâche créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDelayedDisassembly *g_delayed_disassembly_new(const GOpenidaBinary *binary, GBinPart **parts, size_t count, GCodeBuffer *buffer)
+{
+ GDelayedDisassembly *result; /* Tâche à retourner */
+
+ result = g_object_new(G_TYPE_DELAYED_DISASSEMBLY, NULL);
+
+ result->binary = binary;
+ result->format = G_BIN_FORMAT(g_openida_binary_get_format(binary));
+
+ result->parts = parts;
+ result->count = count;
+
+ result->buffer = buffer;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : disass = analyse à mener. *
+* statusbar = barre de statut à tenir informée. *
+* *
+* Description : Assure le désassemblage en différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtStatusBar *statusbar)
+{
+ GBinRoutine **routines; /* Liste des routines trouvées */
+ size_t routines_count; /* Nombre de ces routines */
+ guint id; /* Identifiant de statut */
+
+ routines = g_binary_format_get_routines(disass->format, &routines_count);
+ qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_rcompare);
+
+ /* Première étape */
+
+ id = gtk_extended_status_bar_push(statusbar, _("Disassembling..."), true);
+
+ disass->instrs = disassemble_binary_parts(disass->binary, disass->parts, disass->count,
+ statusbar, id);
+
+ gtk_extended_status_bar_remove(statusbar, id);
+
+ /* Seconde étape */
+
+ id = gtk_extended_status_bar_push(statusbar, _("Establishing links..."), true);
+
+ establish_links_between_lines(disass->instrs, routines, routines_count, statusbar, id);
+
+ gtk_extended_status_bar_remove(statusbar, id);
+#if 0
+ /* Troisième étape */
+
+ id = gtk_extended_status_bar_push(statusbar, _("Finding remaining limits..."), true);
+
+ limit_all_routines(disass->lines, routines, routines_count, statusbar, id);
+
+ gtk_extended_status_bar_remove(statusbar, id);
+#endif
+ /* Quatrième étape */
+
+ id = gtk_extended_status_bar_push(statusbar, _("Printing disassembled code..."), true);
+
+ print_disassembled_instructions(disass->buffer, disass->instrs, routines, routines_count);
+
+ gtk_extended_status_bar_remove(statusbar, id);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GESTION GLOBALE DE PROCEDURE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon de destination pour le texte. *
+* filename = nom du fichier ciblé à décompiler. *
+* data = données en mémoire pour l'empreinte. *
+* length = quantité de données à prendre en compte. *
+* *
+* Description : Construit la description d'introduction du désassemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, const uint8_t *data, off_t length)
+{
+ GLangOutput *output; /* Modèle de sortie adéquat */
+ GBufferLine *line; /* Ligne de destination */
+ size_t len; /* Taille du texte */
+ char *content; /* Contenu textuel d'une ligne */
+ GChecksum *checksum; /* Calcul de l'empreinte */
+ const gchar *hex; /* Valeur hexadécimale du SHA */
+
+ output = g_asm_output_new();
+
+ line = g_lang_output_start_comments(output, buffer);
+ if (line != NULL) g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ /* Introduction */
+
+ line = g_lang_output_continue_comments(output, buffer,
+ SL(_("Disassembly generated by OpenIDA")));
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ line = g_lang_output_continue_comments(output, buffer,
+ SL(_("OpenIDA is free software - © 2008-2010 Cyrille Bagard")));
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ line = g_lang_output_continue_comments(output, buffer, NULL, 0);
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ /* Fichier */
+
+ len = strlen(_("File: ")) + strlen(filename) + 1;
+ content = (char *)calloc(len, sizeof(char));
+
+ snprintf(content, len, "%s%s", _("File: "), filename);
+
+ line = g_lang_output_continue_comments(output, buffer, content, len - 1);
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ free(content);
+
+ /* Checksum SHA256 */
+
+ checksum = g_checksum_new(G_CHECKSUM_SHA256);
+
+ g_checksum_update(checksum, data, length);
+ hex = g_checksum_get_string(checksum);
+
+ len = strlen(_("Sha256: ")) + strlen(hex);
+ content = (char *)calloc(len + 1, sizeof(char));
+
+ snprintf(content, len + 1, "%s%s", _("Sha256: "), hex);
+
+ g_checksum_free(checksum);
+
+ line = g_lang_output_continue_comments(output, buffer, content, len - 1);
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ free(content);
+
+ /* Ligne de séparation */
+
+ line = g_lang_output_continue_comments(output, buffer, NULL, 0);
+ g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ /* Conclusion */
+
+ line = g_lang_output_end_comments(output, buffer);
+ if (line != NULL) g_buffer_line_start_merge_at(line, BLC_ADDRESS);
+
+ g_object_unref(G_OBJECT(output));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire chargé. *
+* parts = parties binaires à désassembler. *
+* count = nombre de parties à traiter. *
+* *
+* Description : Procède au désassemblage d'un contenu binaire donné. *
+* *
+* Retour : Tampon de code mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GCodeBuffer *disassemble_binary(const GOpenidaBinary *binary, GBinPart **parts, size_t parts_count)
+{
+ GCodeBuffer *result; /* Tampon constitué à renvoyer */
+ const uint8_t *data; /* Données binaires brutes */
+ off_t length; /* Quantité de ces données */
+ GDelayedDisassembly *disass; /* Désassemblage à mener */
+ GWorkQueue *queue; /* Gestionnaire de différés */
+
+ result = g_code_buffer_new();
+
+ data = g_openida_binary_get_data(binary, &length);
+ build_disass_prologue(result, g_openida_binary_get_filename(binary), data, length);
+
+ disass = g_delayed_disassembly_new(binary, parts, parts_count, result);
+
+ 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));
+
+ return result;
+
+}
diff --git a/src/analysis/disass/disassembler.h b/src/analysis/disass/disassembler.h
new file mode 100644
index 0000000..7cfdcc5
--- /dev/null
+++ b/src/analysis/disass/disassembler.h
@@ -0,0 +1,38 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * disassembler.h - prototypes pour l'encadrement des phases de désassemblage
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DISASS_DISASSEMBLER_H
+#define _ANALYSIS_DISASS_DISASSEMBLER_H
+
+
+#include "../binary.h"
+#include "../../format/part.h"
+
+
+
+/* Procède à la décompilation des routines d'un fichier donné. */
+GCodeBuffer *disassemble_binary(const GOpenidaBinary *, GBinPart **parts, size_t parts_count);
+
+
+
+#endif /* _ANALYSIS_DISASS_DISASSEMBLER_H */
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
new file mode 100644
index 0000000..575eb06
--- /dev/null
+++ b/src/analysis/disass/fetch.c
@@ -0,0 +1,109 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * fetch.c - récupération d'instructions à partir de binaire brut
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "fetch.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire chargé. *
+* parts = parties binaires à désassembler. *
+* count = nombre de parties à traiter. *
+* statusbar = barre de statut avec progression à mettre à jour.*
+* id = identifiant du message affiché à l'utilisateur. *
+* *
+* Description : Procède au désassemblage basique d'un contenu binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *disassemble_binary_parts(const GOpenidaBinary *binary, GBinPart **parts, size_t count, GtkExtStatusBar *statusbar, guint id)
+{
+ GArchInstruction *result; /* Liste d'instr. à renvoyer */
+ GArchProcessor *proc; /* Architecture du binaire */
+ off_t bin_length; /* Taille des données à lire */
+ bin_t *bin_data; /* Données binaires à lire */
+ size_t i; /* Boucle de parcours #1 */
+ off_t sum; /* Somme de toutes les tailles */
+ off_t done; /* Quantité déjà traitée */
+ off_t pos; /* Début d'une zone binaire */
+ off_t len; /* Taille de cette même zone */
+ vmpa_t base; /* Adresse de la zone binaire */
+ off_t start; /* Conservation du pt de départ*/
+ vmpa_t addr; /* Adresse d'une instruction */
+ GArchInstruction *instr; /* Instruction décodée */
+
+ result = NULL;
+
+ proc = get_arch_processor_from_format(g_openida_binary_get_format(binary));
+ bin_data = g_openida_binary_get_data(binary, &bin_length);
+
+ /* Préparation du suivi de la progression */
+
+ sum = 0;
+
+ for (i = 0; i < count; i++)
+ {
+ g_binary_part_get_values(parts[i], NULL, &len, NULL);
+ if (len > bin_length) continue;
+ sum += len;
+ }
+
+ done = 0;
+
+ for (i = 0; i < count; i++)
+ {
+ g_binary_part_get_values(parts[i], &pos, &len, &base);
+
+ if (len > bin_length) continue;
+
+ /* Décodage des instructions */
+
+ start = pos;
+ pos = 0;
+
+ while (pos < len)
+ {
+ addr = base + pos;
+
+ instr = g_arch_processor_decode_instruction(proc, &bin_data[start],
+ &pos, len, start, addr);
+ g_arch_instruction_add_to_list(&result, instr);
+
+ if (pos < len)
+ gtk_extended_status_bar_update_activity(statusbar, id, (done + pos) * 1.0 / sum);
+
+ }
+
+ done += len;
+ gtk_extended_status_bar_update_activity(statusbar, id, done * 1.0 / sum);
+
+ }
+
+ return result;
+
+}
diff --git a/src/analysis/disass/fetch.h b/src/analysis/disass/fetch.h
new file mode 100644
index 0000000..09bb584
--- /dev/null
+++ b/src/analysis/disass/fetch.h
@@ -0,0 +1,38 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * fetch.h - prototypes pour la récupération d'instructions à partir de binaire brut
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DISASS_INSTR_H
+#define _ANALYSIS_DISASS_INSTR_H
+
+
+#include "../binary.h"
+#include "../../format/part.h"
+#include "../../gtkext/gtkextstatusbar.h"
+
+
+/* Procède au désassemblage basique d'un contenu binaire. */
+GArchInstruction *disassemble_binary_parts(const GOpenidaBinary *, GBinPart **, size_t, GtkExtStatusBar *, guint);
+
+
+
+#endif /* _ANALYSIS_DISASS_INSTR_H */
diff --git a/src/analysis/disass/links.c b/src/analysis/disass/links.c
new file mode 100644
index 0000000..4d799fc
--- /dev/null
+++ b/src/analysis/disass/links.c
@@ -0,0 +1,115 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * links.c - résolution des liens entre différentes instructions
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "links.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : list = ensemble d'instructions à relier. *
+* routines = prototypes existants à insérer. *
+* count = quantité de ces prototypes. *
+* statusbar = barre de statut avec progression à mettre à jour.*
+* id = identifiant du message affiché à l'utilisateur. *
+* *
+* Description : Etablit les liens entres les différentes lignes de code. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void establish_links_between_lines(GArchInstruction *list, GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id)
+{
+ size_t i; /* Boucle de parcours */
+ vmpa_t start; /* Adresse de départ */
+ vmpa_t end; /* Adresse de fin */
+ GArchInstruction *iter; /* Boucle de parcours */
+ vmpa_t addr; /* Adresse référencée */
+ InstructionLinkType type; /* Type de référence */
+ GArchInstruction *target; /* Ligne visée par la référence*/
+
+ for (i = 0; i < count; i++)
+ {
+ start = g_binary_routine_get_address(routines[i]);
+ end = start + g_binary_routine_get_size(routines[i]);
+
+ for (iter = g_arch_instruction_find_by_address(list, start, true);
+ iter != NULL;
+ iter = g_arch_instruction_get_next_iter(list, iter, end))
+ {
+ type = g_arch_instruction_get_link(iter, &addr);
+
+ switch (type)
+ {
+ case ILT_NONE:
+ break;
+
+ case ILT_JUMP:
+
+ target = g_arch_instruction_find_by_address(list, addr, true);
+
+ if (target != NULL)
+ g_arch_instruction_link_with(iter, target, type);
+
+ break;
+
+ case ILT_JUMP_IF_FALSE:
+ break;
+
+ case ILT_JUMP_IF_TRUE:
+
+ target = g_arch_instruction_find_by_address(list, addr, true);
+
+ if (target != NULL)
+ {
+ g_arch_instruction_link_with(iter, target, type);
+
+ target = g_arch_instruction_get_next_iter(list, iter, end);
+ if (target != NULL)
+ g_arch_instruction_link_with(iter, target, ILT_JUMP_IF_FALSE);
+
+ }
+
+ break;
+
+ case ILT_CALL:
+
+ target = g_arch_instruction_find_by_address(list, addr, true);
+
+ if (target != NULL)
+ g_arch_instruction_link_with(iter, target, type);
+
+ break;
+
+ }
+
+ }
+
+ gtk_extended_status_bar_update_activity(statusbar, id, (i + 1) * 1.0 / count);
+
+ }
+
+}
diff --git a/src/analysis/disass/links.h b/src/analysis/disass/links.h
new file mode 100644
index 0000000..0ca7816
--- /dev/null
+++ b/src/analysis/disass/links.h
@@ -0,0 +1,37 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * links.h - prototypes pour la résolution des liens entre différentes instructions
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DISASS_LINKS_H
+#define _ANALYSIS_DISASS_LINKS_H
+
+
+#include "../routine.h"
+#include "../../gtkext/gtkextstatusbar.h"
+
+
+/* Etablit les liens entres les différentes lignes de code. */
+void establish_links_between_lines(GArchInstruction *, GBinRoutine **, size_t, GtkExtStatusBar *, guint);
+
+
+
+#endif /* _ANALYSIS_DISASS_LINKS_H */
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
new file mode 100644
index 0000000..9c4ba2f
--- /dev/null
+++ b/src/analysis/disass/output.c
@@ -0,0 +1,59 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * output.h - prototypes pour l'impression des instructions désassemblées
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "output.h"
+
+
+#include "../../decomp/lang/asm.h"
+
+
+
+/******************************************************************************
+* *
+* 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. *
+* *
+* Description : Transcrit du code désassemblé en texte humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void print_disassembled_instructions(GCodeBuffer *buffer, const GArchInstruction *instrs, const GBinRoutine **routines, size_t count)
+{
+
+ /*
+ for (iter = disass->instrs;
+ iter != NULL;
+ iter = g_arch_instruction_get_next_iter(disass->instrs, iter, VMPA_MAX))
+ {
+
+
+ }
+ */
+
+}
diff --git a/src/analysis/disass/output.h b/src/analysis/disass/output.h
new file mode 100644
index 0000000..f6c56f3
--- /dev/null
+++ b/src/analysis/disass/output.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * output.h - prototypes pour l'impression des instructions désassemblées
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DISASS_OUTPUT_H
+#define _ANALYSIS_DISASS_OUTPUT_H
+
+
+#include "../routine.h"
+#include "../../arch/instruction.h"
+#include "../../glibext/gcodebuffer.h"
+
+
+
+/* Transcrit du code désassemblé en texte humainement lisible. */
+void print_disassembled_instructions(GCodeBuffer *, const GArchInstruction *, const GBinRoutine **, size_t);
+
+
+
+#endif /* _ANALYSIS_DISASS_OUTPUT_H */