summaryrefslogtreecommitdiff
path: root/src/analysis/disass/fetch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/disass/fetch.c')
-rw-r--r--src/analysis/disass/fetch.c109
1 files changed, 109 insertions, 0 deletions
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;
+
+}