summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c728
1 files changed, 156 insertions, 572 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 73070b1..fe8188b 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -24,118 +24,56 @@
#include "binary.h"
-#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
#include <sys/types.h>
#include <i18n.h>
-#include "line_code.h" /* TODO : supprimer ? */
-#include "line_comment.h" /* TODO : supprimer ? */
-#include "line_prologue.h"
+#include "binary-int.h"
#include "routine.h"
+#include "binaries/file.h"
#include "decomp/decompiler.h"
#include "disass/disassembler.h"
-#include "../common/cpp.h"
#include "../common/extstr.h"
-#include "../debug/break.h"
-#include "../format/format.h"
-#include "../gui/panels/log.h"
-#include "../plugins/pglist.h" /* TODO : supprimer ? */
-
-
-#include "../format/dbg_format.h"
-
-
/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */
-/* Description de fichier binaire (instance) */
-struct _GOpenidaBinary
-{
- GObject parent; /* A laisser en premier */
-
- char *filename; /* Fichier chargé en mémoire */
-
- off_t bin_length; /* Taille des données brutes */
- bin_t *bin_data; /* Données binaires brutes */
-
- GExeFormat *format; /* Format du binaire */
- GArchProcessor *proc; /* Architecture du binaire */
-
- BinaryPartModel model; /* Modèle de sélection */
- GBinPart **parts[BPM_COUNT]; /* Parties binaires à analyser */
- size_t parts_count[BPM_COUNT]; /* Quantité de ces parties */
-
- GRenderingLine *lines; /* Lignes de rendu en place */
- GRenderingOptions *options; /* Options de désassemblage */
-
- GArchInstruction *instrs; /* Instructions d'assemblage */
- 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 */
-
- bool text_display[2]; /* Position et code binaire #1 */
- bool lines_display; /* Affichage des lignes */
-
- GBreakGroup **brk_groups; /* Groupes de points d'arrêt */
- size_t brk_count; /* Taille de cette liste */
- GBreakGroup *brk_default; /* Groupe par défaut */
-
-};
-
-/* Description de fichier binaire (classe) */
-struct _GOpenidaBinaryClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- /* Signaux */
-
- void (* disassembly_done) (GOpenidaBinary *);
-
-};
-
/* Initialise la classe des descriptions de fichier binaire. */
-static void g_openida_binary_class_init(GOpenidaBinaryClass *);
+static void g_loaded_binary_class_init(GLoadedBinaryClass *);
/* Initialise une description de fichier binaire. */
-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 *);
-
-/* Acquitte la fin d'un désasemblage différé et complet. */
-void ack_completed_disassembly(void/*GDelayedDisassembly*/ *, GOpenidaBinary *);
+static void g_loaded_binary_init(GLoadedBinary *);
+/* Supprime toutes les références externes. */
+static void g_loaded_binary_dispose(GLoadedBinary *);
+/* Procède à la libération totale de la mémoire. */
+static void g_loaded_binary_finalize(GLoadedBinary *);
+/* Charge les parties intéressantes du binaire à partir d'XML. */
+static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *, xmlXPathContextPtr, const char *);
+/* Ecrit les parties de valeur du binaire dans un fichier XML. */
+static bool g_loaded_binary_save_parts(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
-/* ------------------------------ ELEMENTS DE DEBOGAGE ------------------------------ */
+/* Acquitte la fin d'un désasemblage différé et complet. */
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *, GLoadedBinary *);
-/* Réagit à une nouvelle création de point d'arrêt. */
-static void g_openida_binary_breakpoint_added(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
-/* Réagit à une suppression de point d'arrêt. */
-static void g_openida_binary_breakpoint_removed(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
/* Indique le type défini pour une description de fichier binaire. */
-G_DEFINE_TYPE(GOpenidaBinary, g_openida_binary, G_TYPE_OBJECT);
+G_DEFINE_TYPE(GLoadedBinary, g_loaded_binary, G_TYPE_OBJECT);
/******************************************************************************
@@ -150,12 +88,19 @@ G_DEFINE_TYPE(GOpenidaBinary, g_openida_binary, G_TYPE_OBJECT);
* *
******************************************************************************/
-static void g_openida_binary_class_init(GOpenidaBinaryClass *klass)
+static void g_loaded_binary_class_init(GLoadedBinaryClass *klass)
{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_loaded_binary_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_loaded_binary_finalize;
+
g_signal_new("disassembly-done",
- G_TYPE_OPENIDA_BINARY,
+ G_TYPE_LOADED_BINARY,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(GOpenidaBinaryClass, disassembly_done),
+ G_STRUCT_OFFSET(GLoadedBinaryClass, disassembly_done),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -175,133 +120,143 @@ static void g_openida_binary_class_init(GOpenidaBinaryClass *klass)
* *
******************************************************************************/
-static void g_openida_binary_init(GOpenidaBinary *binary)
+static void g_loaded_binary_init(GLoadedBinary *binary)
{
binary->text_display[0] = true;
binary->text_display[1] = true;
binary->lines_display = true;
- /* FIXME : à replacer ailleurs */
- g_openida_binary_add_break_group(binary, _("default"));
-
}
/******************************************************************************
* *
-* Paramètres : filename = nom du fichier à charger. *
+* Paramètres : binary = instance d'objet GLib à traiter. *
* *
-* Description : Charge en mémoire le contenu d'un fichier. *
+* Description : Supprime toutes les références externes. *
* *
-* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
+static void g_loaded_binary_dispose(GLoadedBinary *binary)
{
- GOpenidaBinary *result; /* Adresse à retourner */
- GPluginModule **pglist; /* Liste de greffons */
- size_t pgcount; /* Taille de cette liste */
- size_t i; /* Boucle de parcours */
-
+ gpointer obj_class; /* Classe parente */
- char *file = strdup(filename);
+ g_object_unref(G_OBJECT(binary->format));
+ g_object_unref(G_OBJECT(binary->proc));
- result = g_object_new(G_TYPE_OPENIDA_BINARY, NULL);
+ /* TODO... */
+ /* On passe le relai */
+ obj_class = g_type_class_peek_parent(G_FILE_BINARY_GET_CLASS(binary));
+ G_OBJECT_CLASS(obj_class)->dispose(G_OBJECT(binary));
- printf("%s\n", filename);
+}
+/******************************************************************************
+* *
+* Paramètres : binary = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- pglist = get_all_plugins_for_action(PGA_FORMAT_MATCHER, &pgcount);
+static void g_loaded_binary_finalize(GLoadedBinary *binary)
+{
+ gpointer obj_class; /* Classe parente */
- if (pgcount > 0)
- {
- printf("===>>>> FOUND :: %d\n", pgcount);
+ /* TODO */
+ /* On passe le relai */
- /*
- for (i = 0; i < pgcount; i++)
- g_plugin_module_execute_action_on_binary(pglist[i], binary, PGA_CODE_PROCESS);
- */
- free(pglist);
+ obj_class = g_type_class_peek_parent(G_FILE_BINARY_GET_CLASS(binary));
- }
+ G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(binary));
+}
+/******************************************************************************
+* *
+* Paramètres : context = contexte pour les recherches XPath. *
+* path = chemin d'accès au noeud XML à lire. *
+* *
+* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
+* *
+* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
+{
+ GLoadedBinary *result; /* Adresse à retourner */
+ char *type; /* Tupe de binaire à charger */
+ result = NULL;
+ type = get_node_prop_value(context, path, "type");
+ if (strcmp(type, "file") == 0)
+ result = g_loaded_binary_new_from_xml(context, path);
+ free(type);
- log_variadic_message(LMT_PROCESS, _("Opening '%s' file..."), filename);
+ if (result == NULL)
+ return NULL;
- result->filename = strdup(filename);
+ if (!g_loaded_binary_load_parts_from_xml(result, context, path))
+ goto glbnfx_error;
- /*
- result->bin_data = map_binary_file(filename, &result->bin_length);
- if (result->bin_data == NULL) goto lbf_error;
- */
+ return result;
- result->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, file,
- &result->bin_data, &result->bin_length));
- if (result->format == NULL)
- {
- log_simple_message(LMT_INFO, _("Unknown binary format"));
- goto lbf_error;
- }
+ glbnfx_error:
- /* FIXME : à déplacer dans arch/... */
- switch (g_exe_format_get_target_machine(result->format))
- {
- case FTM_ARM:
- log_simple_message(LMT_INFO, _("Detected architecture: ARM"));
- break;
- case FTM_DALVIK:
- log_simple_message(LMT_INFO, _("Detected architecture: Dalvik Virtual Machine"));
- break;
- case FTM_JVM:
- log_simple_message(LMT_INFO, _("Detected architecture: Java Virtual Machine"));
- break;
- case FTM_MIPS:
- log_simple_message(LMT_INFO, _("Detected architecture: Microprocessor without Interlocked Pipeline Stages"));
- break;
- case FTM_386:
- log_simple_message(LMT_INFO, _("Detected architecture: i386"));
- break;
- default:
- log_simple_message(LMT_INFO, _("Unknown architecture"));
- goto lbf_error;
- break;
- }
+ g_object_unref(G_OBJECT(result));
- result->lines = NULL;
+ return NULL;
- result->proc = get_arch_processor_from_format(result->format);
+}
- result->options = g_rendering_options_new(result->format);
- g_rendering_options_show_address(result->options, MRD_BLOCK, true);
- g_rendering_options_show_code(result->options, MRD_BLOCK, true);
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à traiter. *
+* xdoc = structure XML en cours d'édition. *
+* context = contexte à utiliser pour les recherches. *
+* path = chemin d'accès réservé au binaire. *
+* *
+* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- g_rendering_options_show_address(result->options, MRD_GRAPH, true);
- g_rendering_options_show_code(result->options, MRD_GRAPH, false);
+bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
- return result;
+ result = binary->save(binary, xdoc, context, path);
- lbf_error:
+ /* Parties à désassembler */
- //unload_binary_file(result);
+ result = g_loaded_binary_save_parts(binary, xdoc, context, path);
- return NULL;
+ return result;
}
@@ -311,21 +266,18 @@ GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
* Paramètres : context = contexte pour les recherches XPath. *
* path = chemin d'accès au noeud XML à lire. *
* *
-* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
+* Description : Charge les parties intéressantes du binaire à partir d'XML. *
* *
-* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
+static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *binary, xmlXPathContextPtr context, const char *path)
{
- GOpenidaBinary *result; /* Adresse à retourner */
- char *type; /* Tupe de binaire à charger */
- size_t access_len; /* Taille d'un chemin interne */
+ bool result; /* Bilan à retourner */
char *access; /* Chemin pour une sous-config.*/
- char *filename; /* Chemin du binaire à charger */
xmlXPathObjectPtr xobjects; /* Cible d'une recherche */
int i; /* Boucle de parcours */
GBinPart *part; /* Partie binaire à traiter */
@@ -334,33 +286,6 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
result = NULL;
- /* Type */
-
- type = get_node_prop_value(context, path, "type");
-
- printf("###type### %s\n", type);
-
- free(type);
-
- /* Chemin du fichier à retrouver */
-
- access = strdup(path);
- access = stradd(access, "/Filename");
-
- filename = get_node_text_value(context, access);
-
- free(access);
-
- /* Chargement */
-
- if (filename != NULL)
- {
- result = g_openida_binary_new_from_file(filename);
- free(filename);
- }
-
- if (result == NULL) return NULL;
-
/* Parties à désassembler : default */
access = strdup(path);
@@ -376,29 +301,29 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
- result->parts_count[BPM_DEFAULT]++;
- result->parts[BPM_DEFAULT] = (GBinPart **)realloc(result->parts[BPM_DEFAULT],
- result->parts_count[BPM_DEFAULT] * sizeof(GBinPart *));
+ binary->parts_count[BPM_DEFAULT]++;
+ binary->parts[BPM_DEFAULT] = (GBinPart **)realloc(binary->parts[BPM_DEFAULT],
+ binary->parts_count[BPM_DEFAULT] * sizeof(GBinPart *));
- result->parts[BPM_DEFAULT][result->parts_count[BPM_DEFAULT] - 1] = part;
+ binary->parts[BPM_DEFAULT][binary->parts_count[BPM_DEFAULT] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_DEFAULT], result->parts_count[BPM_DEFAULT],
- sizeof(GBinPart *), g_binary_part_compare);
+ qsort(binary->parts[BPM_DEFAULT], binary->parts_count[BPM_DEFAULT],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
/* Parties à désassembler : routines */
@@ -415,30 +340,30 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
else g_binary_part_set_address(part, addr);
- result->parts_count[BPM_ROUTINES]++;
- result->parts[BPM_ROUTINES] = (GBinPart **)realloc(result->parts[BPM_ROUTINES],
- result->parts_count[BPM_ROUTINES] * sizeof(GBinPart *));
+ binary->parts_count[BPM_ROUTINES]++;
+ binary->parts[BPM_ROUTINES] = (GBinPart **)realloc(binary->parts[BPM_ROUTINES],
+ binary->parts_count[BPM_ROUTINES] * sizeof(GBinPart *));
- result->parts[BPM_ROUTINES][result->parts_count[BPM_ROUTINES] - 1] = part;
+ binary->parts[BPM_ROUTINES][binary->parts_count[BPM_ROUTINES] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_ROUTINES], result->parts_count[BPM_ROUTINES],
- sizeof(GBinPart *), g_binary_part_compare);
+ qsort(binary->parts[BPM_ROUTINES], binary->parts_count[BPM_ROUTINES],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
/* Parties à désassembler : utilisateur */
@@ -455,34 +380,29 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
- result->parts_count[BPM_USER]++;
- result->parts[BPM_USER] = (GBinPart **)realloc(result->parts[BPM_USER],
- result->parts_count[BPM_USER] * sizeof(GBinPart *));
+ binary->parts_count[BPM_USER]++;
+ binary->parts[BPM_USER] = (GBinPart **)realloc(binary->parts[BPM_USER],
+ binary->parts_count[BPM_USER] * sizeof(GBinPart *));
- result->parts[BPM_USER][result->parts_count[BPM_USER] - 1] = part;
+ binary->parts[BPM_USER][binary->parts_count[BPM_USER] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_USER], result->parts_count[BPM_USER],
- sizeof(GBinPart *), g_binary_part_compare);
-
-
-
-
-
+ qsort(binary->parts[BPM_USER], binary->parts_count[BPM_USER],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
return result;
@@ -496,7 +416,7 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
* context = contexte à utiliser pour les recherches. *
* path = chemin d'accès réservé au binaire. *
* *
-* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* Description : Ecrit les parties de valeur du binaire dans un fichier XML. *
* *
* Retour : true si l'opération a bien tourné, false sinon. *
* *
@@ -504,7 +424,7 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
* *
******************************************************************************/
-bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+static bool g_loaded_binary_save_parts(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
{
bool result; /* Bilan à faire remonter */
char *access; /* Chemin d'accès à un élément */
@@ -513,21 +433,6 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
result = true;
- /* Type */
-
- result &= add_string_attribute_to_node(xdoc, context, path, "type", "file");
-
- /* Nom du fichier associé */
-
- access = strdup(path);
- access = stradd(access, "/Filename");
-
- result &= add_content_to_node(xdoc, context, access, binary->filename);
-
- free(access);
-
- /* Parties à désassembler */
-
if (binary->parts_count[BPM_DEFAULT] > 0)
{
access = strdup(path);
@@ -590,9 +495,9 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
* *
******************************************************************************/
-void g_openida_binary_set_parts(GOpenidaBinary *binary, BinaryPartModel model, GBinPart **parts, size_t count)
+void g_loaded_binary_set_parts(GLoadedBinary *binary, BinaryPartModel model, GBinPart **parts, size_t count)
{
- qsort(parts, count, sizeof(GBinPart *), g_binary_part_compare);
+ qsort(parts, count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
binary->parts[model] = parts;
binary->parts_count[model] = count;
@@ -614,7 +519,7 @@ void g_openida_binary_set_parts(GOpenidaBinary *binary, BinaryPartModel model, G
* *
******************************************************************************/
-GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *binary, BinaryPartModel *model, size_t **count)
+GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *binary, BinaryPartModel *model, size_t **count)
{
*model = binary->model;
*count = binary->parts_count;
@@ -636,7 +541,7 @@ GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *binary, BinaryPartM
* *
******************************************************************************/
-void g_openida_binary_analyse(GOpenidaBinary *binary)
+void g_loaded_binary_analyse(GLoadedBinary *binary)
{
GBinPart **parts; /* Parties d'élément binaire */
size_t parts_count; /* Nombre de ces parties */
@@ -660,7 +565,7 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
else
{
parts = g_exe_format_get_parts(binary->format, &parts_count);
- qsort(parts, parts_count, sizeof(GBinPart *), g_binary_part_compare);
+ qsort(parts, parts_count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
}
}
@@ -676,25 +581,7 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
/******************************************************************************
* *
* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Fournit une description humaine d'un élément binaire. *
-* *
-* Retour : Chaîne de caractères humainenement lisible de représentation.*
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-const char *g_openida_binary_to_string(const GOpenidaBinary *binary)
-{
- return binary->filename;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
+* full = précise s'il s'agit d'une version longue ou non. *
* *
* Description : Fournit le fichier correspondant à l'élément binaire. *
* *
@@ -704,9 +591,9 @@ const char *g_openida_binary_to_string(const GOpenidaBinary *binary)
* *
******************************************************************************/
-const char *g_openida_binary_get_filename(const GOpenidaBinary *binary)
+const char *g_loaded_binary_get_filename(const GLoadedBinary *binary, bool full)
{
- return binary->filename;
+ return binary->get_filename(binary, full);
}
@@ -724,7 +611,7 @@ const char *g_openida_binary_get_filename(const GOpenidaBinary *binary)
* *
******************************************************************************/
-bin_t *g_openida_binary_get_data(const GOpenidaBinary *binary, off_t *length)
+bin_t *g_loaded_binary_get_data(const GLoadedBinary *binary, off_t *length)
{
if (length != NULL)
*length = binary->bin_length;
@@ -746,7 +633,7 @@ bin_t *g_openida_binary_get_data(const GOpenidaBinary *binary, off_t *length)
* *
******************************************************************************/
-GExeFormat *g_openida_binary_get_format(const GOpenidaBinary *binary)
+GExeFormat *g_loaded_binary_get_format(const GLoadedBinary *binary)
{
return binary->format;
@@ -757,63 +644,6 @@ GExeFormat *g_openida_binary_get_format(const GOpenidaBinary *binary)
* *
* Paramètres : binary = élément binaire à consulter. *
* *
-* Description : Fournit les options d'affichage définies pour le binaire. *
-* *
-* Retour : Adresse des options d'affichage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingOptions *g_openida_binary_get_options(const GOpenidaBinary *binary)
-{
- return binary->options;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Donne la racine des lignes de rendu issues du désassemblage. *
-* *
-* Retour : Lieu d'enregistrement des lignes issues du désassemblage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingLine **g_openida_binary_get_lines_root(const GOpenidaBinary *binary)
-{
- return &binary->lines;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Fournit les lignes de rendu issues du désassemblage. *
-* *
-* Retour : Lignes issues du désassemblage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *binary)
-{
- return binary->lines;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
* Description : Fournit les instructions issues du désassemblage. *
* *
* Retour : Instructions issues du désassemblage. *
@@ -822,7 +652,7 @@ GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *binary)
* *
******************************************************************************/
-GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *binary)
+GArchInstruction *g_loaded_binary_get_instructions(const GLoadedBinary *binary)
{
return binary->instrs;
@@ -841,7 +671,7 @@ GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *binary
* *
******************************************************************************/
-GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *binary)
+GCodeBuffer *g_loaded_binary_get_disassembled_buffer(const GLoadedBinary *binary)
{
return binary->disass_buffer;
@@ -860,7 +690,7 @@ GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *bina
* *
******************************************************************************/
-bool *g_openida_binary_display_addresses_in_text(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_addresses_in_text(GLoadedBinary *binary)
{
return &binary->text_display[0];
@@ -879,7 +709,7 @@ bool *g_openida_binary_display_addresses_in_text(const GOpenidaBinary *binary)
* *
******************************************************************************/
-bool *g_openida_binary_display_code_in_text(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_code_in_text(GLoadedBinary *binary)
{
return &binary->text_display[1];
@@ -899,7 +729,7 @@ bool *g_openida_binary_display_code_in_text(const GOpenidaBinary *binary)
* *
******************************************************************************/
-GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *binary, size_t index)
+GCodeBuffer *g_loaded_binary_get_decompiled_buffer(const GLoadedBinary *binary, size_t index)
{
GCodeBuffer *result; /* Tampon à retourner */
@@ -926,7 +756,7 @@ GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *binary
* *
******************************************************************************/
-bool *g_openida_binary_display_decomp_lines(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_decomp_lines(GLoadedBinary *binary)
{
return &binary->lines_display;
@@ -935,59 +765,6 @@ bool *g_openida_binary_display_decomp_lines(const GOpenidaBinary *binary)
/******************************************************************************
* *
-* Paramètres : filename = nom du fichier à charger. *
-* length = taille des données mises en mémoire. [OUT] *
-* *
-* Description : Charge en mémoire le contenu d'un fichier. *
-* *
-* Retour : Adresse du contenu binaire ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bin_t *map_binary_file(const char *filename, off_t *length)
-{
- uint8_t *result; /* Données à retourner */
- int fd; /* Fichier ouvert en lecture */
- struct stat info; /* Informations sur le fichier */
- int ret; /* Bilan d'un appel */
-
- fd = open(filename, 0, O_RDONLY);
- if (fd == -1)
- {
- perror("open()");
- return NULL;
- }
-
- ret = fstat(fd, &info);
- if (ret == -1)
- {
- perror("fstat()");
- close(fd);
- return NULL;
- }
-
- *length = info.st_size;
-
- result = (uint8_t *)mmap(NULL, *length, PROT_READ, MAP_PRIVATE, fd, 0);
- if (result == MAP_FAILED)
- {
- perror("mmap()");
- result = NULL;
- }
-
- ret = close(fd);
- if (ret == -1)
- perror("close()");
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : disass = travail de désassemblage mené à bien. *
* binary = représentation de binaire à l'origine de l'opérat°. *
* *
@@ -999,9 +776,9 @@ bin_t *map_binary_file(const char *filename, off_t *length)
* *
******************************************************************************/
-void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GOpenidaBinary *binary)
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GLoadedBinary *binary)
{
- GRenderingLine *line; /* "Première" ligne de rendu */
+ //GRenderingLine *line; /* "Première" ligne de rendu */
size_t i; /* Boucle de parcours */
@@ -1040,196 +817,3 @@ void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GOpenidaBina
g_signal_emit_by_name(binary, "disassembly-done");
}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* ELEMENTS DE DEBOGAGE */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à modifier. *
-* name = éventuel nom à associer au groupe. *
-* *
-* Description : Ajoute un nouveau groupe de points d'arrêt au binaire. *
-* *
-* Retour : true si l'opération s'est bien effectuée, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_openida_binary_add_break_group(GOpenidaBinary *binary, const char *name)
-{
- bool result; /* Bilan à faire remonter */
- const char *used; /* Désignation à utiliser */
- size_t tmp_len; /* Longeur maximale à gérer */
- char *tmp; /* Construction temporaire */
- size_t i; /* Boucle de parcours */
- const char *test; /* Nom existant à tester */
-
- result = true;
-
- /* Préparation du nom de scène */
-
- if (name != NULL) used = name;
- else
- {
- tmp_len = strlen(_("Group")) + 1 + SIZE_T_MAXLEN + 1;
- tmp = (char *)calloc(tmp_len, sizeof(char));
-
- snprintf(tmp, tmp_len, "%s %lu", _("Group"), binary->brk_count);
-
- used = tmp;
-
- }
-
- /* Vérification d'unicité */
-
- for (i = 0; i < binary->brk_count && result; i++)
- {
- test = g_break_group_get_name(binary->brk_groups[i]);
-
- if (test != NULL)
- result = (strcmp(used, test) != 0);
-
- }
-
- /* Mise en place finale */
-
- if (result)
- {
- binary->brk_count++;
- binary->brk_groups = (GBreakGroup **)realloc(binary->brk_groups,
- binary->brk_count * sizeof(GBreakGroup *));
-
- binary->brk_groups[i] = g_break_group_new();
-
- g_break_group_set_name(binary->brk_groups[i], used);
-
- if (binary->brk_default == NULL)
- binary->brk_default = binary->brk_groups[i];
-
- g_signal_connect(binary->brk_groups[i], "added",
- G_CALLBACK(g_openida_binary_breakpoint_added), binary);
-
- g_signal_connect(binary->brk_groups[i], "removed",
- G_CALLBACK(g_openida_binary_breakpoint_removed), binary);
-
- }
-
- if (name == NULL) free(tmp);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : group = ensemble de points d'arrêt intervenant. *
-* point = point d'arrêt à l'origine de la procédure. *
-* binary = représentation de binaire à modifier. *
-* *
-* Description : Réagit à une nouvelle création de point d'arrêt. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_openida_binary_breakpoint_added(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
-{
- GRenderingLine *line; /* Ligne à retrouver */
-
- line = g_rendering_line_find_by_address(binary->lines, NULL,
- g_break_point_get_address(point));
-
- if (line != NULL)
- g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : group = ensemble de points d'arrêt intervenant. *
-* point = point d'arrêt à l'origine de la procédure. *
-* binary = représentation de binaire à modifier. *
-* *
-* Description : Réagit à une suppression de point d'arrêt. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_openida_binary_breakpoint_removed(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
-{
- GRenderingLine *line; /* Ligne à retrouver */
-
- line = g_rendering_line_find_by_address(binary->lines, NULL,
- g_break_point_get_address(point));
-
- if (line != NULL)
- g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à mettre à jour. *
-* addr = adresse mémoire à faire basculer. *
-* *
-* Description : Ajoute ou supprime un point d'arrêt dans un binaire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_openida_binary_toggle_breakpoint(GOpenidaBinary *binary, vmpa_t addr)
-{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < binary->brk_count; i++)
- if (g_break_group_has_address(binary->brk_groups[i], addr))
- {
- g_break_group_toggle_breakpoint(binary->brk_groups[i], addr);
- break;
- }
-
- if (i == binary->brk_count)
- g_break_group_toggle_breakpoint(binary->brk_default, addr);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à parcourir. *
-* func = fonction à appeler à chaque point trouvé. *
-* data = éventuelle donnée de l'utilisateur à joindre. *
-* *
-* Description : Parcourt l'ensemble des groupes de points d'arrêt du binaire.*
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_openida_binary_for_each_bp_group(GOpenidaBinary *binary, GExtFunc func, gpointer data)
-{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < binary->brk_count; i++)
- func(binary, binary->brk_groups[i], data);
-
-}