summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-06-07 19:02:07 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-06-07 19:02:07 (GMT)
commitb2b00f3dedf496e4b22cdd8cdc14d9c8cb7cd7ac (patch)
tree8b9473b858ff37e50d2ac01ad5e3339c85b49238 /src/format
parent74063a8f0e00e1b53b45ddcbd47348d9acce3f67 (diff)
Introduced the flat file format.
Diffstat (limited to 'src/format')
-rw-r--r--src/format/Makefile.am2
-rw-r--r--src/format/executable.c15
-rw-r--r--src/format/flat-int.h54
-rw-r--r--src/format/flat.c385
-rw-r--r--src/format/flat.h65
-rw-r--r--src/format/format.c5
6 files changed, 523 insertions, 3 deletions
diff --git a/src/format/Makefile.am b/src/format/Makefile.am
index 1435695..504055d 100644
--- a/src/format/Makefile.am
+++ b/src/format/Makefile.am
@@ -6,6 +6,8 @@ libformat_la_SOURCES = \
debuggable.h debuggable.c \
executable-int.h executable-int.c \
executable.h executable.c \
+ flat-int.h \
+ flat.h flat.c \
format-int.h \
format.h format.c \
preload-int.h \
diff --git a/src/format/executable.c b/src/format/executable.c
index a2ee569..e70840b 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -302,6 +302,7 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat
GBinFormat *base; /* Version basique du format */
vmpa2t addr; /* Emplacement vide de sens */
phys_t length; /* Taille de portion globale */
+ GExeFormatClass *class; /* Classe de l'instance */
base = G_BIN_FORMAT(format);
@@ -314,7 +315,10 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat
format->portions = g_binary_portion_new(BPC_RAW, &addr, length);
- G_EXE_FORMAT_GET_CLASS(format)->refine_portions(format);
+ class = G_EXE_FORMAT_GET_CLASS(format);
+
+ if (class->refine_portions != NULL)
+ class->refine_portions(format);
}
@@ -518,8 +522,15 @@ bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, v
bool g_exe_format_get_section_range_by_name(const GExeFormat *format, const char *name, mrange_t *range)
{
bool result; /* Bilan à retourner */
+ GExeFormatClass *class; /* Classe de l'instance */
+
+ class = G_EXE_FORMAT_GET_CLASS(format);
- result = G_EXE_FORMAT_GET_CLASS(format)->get_range_by_name(format, name, range);
+ if (class->get_range_by_name == NULL)
+ result = false;
+
+ else
+ result = class->get_range_by_name(format, name, range);
return result;
diff --git a/src/format/flat-int.h b/src/format/flat-int.h
new file mode 100644
index 0000000..9a54e82
--- /dev/null
+++ b/src/format/flat-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * flat-int.h - prototypes de code utile aux formats d'exécutables à plat
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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.
+ *
+ * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_FLAT_INT_H
+#define _FORMAT_FLAT_INT_H
+
+
+#include "flat.h"
+
+
+#include "executable-int.h"
+
+
+
+/* Format d'exécutable à plat (instance) */
+struct _GFlatFormat
+{
+ GExeFormat parent; /* A laisser en premier */
+
+ SourceEndian endian; /* Boutisme imposé */
+ char *machine; /* Architecture imposée */
+
+};
+
+/* Format d'exécutable à plat (classe) */
+struct _GFlatFormatClass
+{
+ GExeFormatClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _FORMAT_FLAT_INT_H */
diff --git a/src/format/flat.c b/src/format/flat.c
new file mode 100644
index 0000000..b165c18
--- /dev/null
+++ b/src/format/flat.c
@@ -0,0 +1,385 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * flat.c - support des formats à plat
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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.
+ *
+ * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "flat.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include <i18n.h>
+
+
+#include "flat-int.h"
+
+
+
+/* Initialise la classe des formats d'exécutables à plat. */
+static void g_flat_format_class_init(GFlatFormatClass *);
+
+/* Initialise une instance de format d'exécutable à plat. */
+static void g_flat_format_init(GFlatFormat *);
+
+/* Supprime toutes les références externes. */
+static void g_flat_format_dispose(GFlatFormat *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_flat_format_finalize(GFlatFormat *);
+
+/* Indique la désignation interne du format. */
+static const char *g_flat_format_get_name(const GFlatFormat *);
+
+/* Fournit une description humaine du format. */
+static const char *g_flat_format_get_description(const GFlatFormat *);
+
+/* Assure l'interprétation d'un format en différé. */
+static bool g_flat_format_analyze(GFlatFormat *, wgroup_id_t, GtkStatusStack *);
+
+/* Informe quant au boutisme utilisé. */
+static SourceEndian g_flat_format_get_endianness(const GFlatFormat *);
+
+/* Indique le type d'architecture visée par le format. */
+static const char *g_flat_format_get_target_machine(const GFlatFormat *);
+
+/* Fournit l'adresse principale associée à un format à plat. */
+static bool g_flat_format_get_main_address(GFlatFormat *, vmpa2t *);
+
+
+
+/* Indique le type défini pour un format d'exécutable à plat. */
+G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXE_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats d'exécutables à plat. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flat_format_class_init(GFlatFormatClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GBinFormatClass *fmt; /* Version en format basique */
+ GExeFormatClass *exe; /* Version en exécutable */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_flat_format_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_flat_format_finalize;
+
+ fmt = G_BIN_FORMAT_CLASS(klass);
+
+ fmt->get_name = (format_get_name_fc)g_flat_format_get_name;
+ fmt->get_desc = (format_get_desc_fc)g_flat_format_get_description;
+ fmt->analyze = (format_analyze_fc)g_flat_format_analyze;
+ fmt->get_endian = (format_get_endian_fc)g_flat_format_get_endianness;
+
+ exe = G_EXE_FORMAT_CLASS(klass);
+
+ exe->get_machine = (get_target_machine_fc)g_flat_format_get_target_machine;
+ exe->get_main_addr = (get_main_addr_fc)g_flat_format_get_main_address;
+
+ exe->translate_phys = (translate_phys_fc)g_exe_format_without_virt_translate_offset_into_vmpa;
+ exe->translate_virt = (translate_virt_fc)g_exe_format_without_virt_translate_address_into_vmpa;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format d'exécutable à plat. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flat_format_init(GFlatFormat *format)
+{
+ format->endian = SRE_LITTLE;
+ format->machine = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flat_format_dispose(GFlatFormat *format)
+{
+ G_OBJECT_CLASS(g_flat_format_parent_class)->dispose(G_OBJECT(format));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_flat_format_finalize(GFlatFormat *format)
+{
+ G_OBJECT_CLASS(g_flat_format_parent_class)->finalize(G_OBJECT(format));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* *
+* Description : Prend en charge un nouveau format à plat. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GExeFormat *g_flat_format_new(GBinContent *content)
+{
+ GFlatFormat *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_FLAT_FORMAT, NULL);
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+ return G_EXE_FORMAT(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* *
+* Description : Indique la désignation interne du format. *
+* *
+* Retour : Description du format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_flat_format_get_name(const GFlatFormat *format)
+{
+ const char *result; /* Désignation à retourner */
+
+ result = "flat";
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* *
+* Description : Fournit une description humaine du format. *
+* *
+* Retour : Description du format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_flat_format_get_description(const GFlatFormat *format)
+{
+ const char *result; /* Désignation à retourner */
+
+ result = _("Flat executable format");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = format chargé dont l'analyse est lancée. *
+* gid = groupe de travail dédié. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Assure l'interprétation d'un format en différé. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatusStack *status)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ g_executable_format_setup_portions(G_EXE_FORMAT(format), status);
+
+ g_binary_format_register_code_point(G_BIN_FORMAT(format), 0, true);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* endian = boutisme à associer au format à plat. *
+* *
+* Description : Spécifie un boutisme à utiliser. *
+* *
+* Retour : Indicateur de boutisme. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flat_format_set_endianness(GFlatFormat *format, SourceEndian endian)
+{
+ format->endian = endian;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Informe quant au boutisme utilisé. *
+* *
+* Retour : Indicateur de boutisme. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format)
+{
+ return format->endian;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* machine = identifiant de l'architecture visée. *
+* *
+* Description : Indique le type d'architecture visée par le format. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_flat_format_set_target_machine(GFlatFormat *format, const char *machine)
+{
+ if (format->machine != NULL)
+ free(format->machine);
+
+ if (machine == NULL)
+ format->machine = NULL;
+
+ else
+ format->machine = strdup(machine);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Indique le type d'architecture visée par le format. *
+* *
+* Retour : Identifiant de l'architecture ciblée par le format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_flat_format_get_target_machine(const GFlatFormat *format)
+{
+ const char *result; /* Identifiant à retourner */
+
+ result = format->machine;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* addr = adresse principale trouvée si possible. [OUT] *
+* *
+* Description : Fournit l'adresse principale associée à un format à plat. *
+* *
+* Retour : Bilan des recherches. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_flat_format_get_main_address(GFlatFormat *format, vmpa2t *addr)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ init_vmpa(addr, 0, VMPA_NO_VIRTUAL);
+
+ return result;
+
+}
diff --git a/src/format/flat.h b/src/format/flat.h
new file mode 100644
index 0000000..1a08d25
--- /dev/null
+++ b/src/format/flat.h
@@ -0,0 +1,65 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * flat.h - prototypes pour le support des formats à plat
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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.
+ *
+ * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_FLAT_H
+#define _FORMAT_FLAT_H
+
+
+#include <glib-object.h>
+
+
+#include "executable.h"
+#include "../analysis/content.h"
+
+
+
+#define G_TYPE_FLAT_FORMAT g_flat_format_get_type()
+#define G_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FLAT_FORMAT, GFlatFormat))
+#define G_IS_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FLAT_FORMAT))
+#define G_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FLAT_FORMAT, GFlatFormatClass))
+#define G_IS_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FLAT_FORMAT))
+#define G_FLAT_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FLAT_FORMAT, GFlatFormatClass))
+
+
+/* Format d'exécutable à plat (instance) */
+typedef struct _GFlatFormat GFlatFormat;
+
+/* Format d'exécutable à plat (classe) */
+typedef struct _GFlatFormatClass GFlatFormatClass;
+
+
+/* Indique le type défini pour un format d'exécutable à plat. */
+GType g_flat_format_get_type(void);
+
+/* Prend en charge un nouveau format à plat. */
+GExeFormat *g_flat_format_new(GBinContent *);
+
+/* Spécifie un boutisme à utiliser. */
+void g_flat_format_set_endianness(GFlatFormat *, SourceEndian);
+
+/* Indique le type d'architecture visée par le format. */
+void g_flat_format_set_target_machine(GFlatFormat *, const char *);
+
+
+
+#endif /* _FORMAT_FLAT_H */
diff --git a/src/format/format.c b/src/format/format.c
index e6cefc8..fa11663 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -321,8 +321,11 @@ const char *g_binary_format_get_description(const GBinFormat *format)
bool g_binary_format_analyze(GBinFormat *format, wgroup_id_t gid, GtkStatusStack *status)
{
bool result; /* Bilan à retourner */
+ GBinFormatClass *class; /* Classe de l'instance */
+
+ class = G_BIN_FORMAT_GET_CLASS(format);
- result = G_BIN_FORMAT_GET_CLASS(format)->analyze(format, gid, status);
+ result = class->analyze(format, gid, status);
return result;