summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-08-12 19:05:31 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-08-12 19:05:31 (GMT)
commit4b2f65ed2125cd7b6ef598cf02738f6c839d8935 (patch)
treede62e9daaafe63248c45202004758e91b7341cc5 /src/format
parentb5c6bcea25b1b840fd6c8e89a4a3c9fbd83ba84b (diff)
Extended the loading process of binary formats to prepare the DWARF support.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@568 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format')
-rw-r--r--src/format/Makefile.am25
-rw-r--r--src/format/dbg_format-int.h55
-rw-r--r--src/format/dbg_format.c91
-rw-r--r--src/format/dbg_format.h41
-rw-r--r--src/format/debuggable-int.h51
-rw-r--r--src/format/debuggable.c88
-rw-r--r--src/format/debuggable.h52
-rw-r--r--src/format/dwarf/Makefile.am10
-rw-r--r--src/format/dwarf/dwarf-int.c75
-rw-r--r--src/format/dwarf/dwarf-int.h80
-rw-r--r--src/format/dwarf/dwarf.c212
-rw-r--r--src/format/dwarf/dwarf.h23
-rw-r--r--src/format/dwarf/v2/Makefile.am12
-rw-r--r--src/format/dwarf/v2/dwarf.c171
-rw-r--r--src/format/dwarf/v2/dwarf.h59
-rw-r--r--src/format/dwarf/v3/Makefile.am12
-rw-r--r--src/format/dwarf/v3/dwarf.c171
-rw-r--r--src/format/dwarf/v3/dwarf.h59
-rw-r--r--src/format/dwarf/v4/Makefile.am12
-rw-r--r--src/format/dwarf/v4/dwarf.c171
-rw-r--r--src/format/dwarf/v4/dwarf.h59
-rw-r--r--src/format/elf/elf.c57
-rw-r--r--src/format/elf/elf.h5
-rw-r--r--src/format/executable-int.h5
-rw-r--r--src/format/executable.c25
-rw-r--r--src/format/executable.h4
26 files changed, 1386 insertions, 239 deletions
diff --git a/src/format/Makefile.am b/src/format/Makefile.am
index b0fda82..a3402ee 100644
--- a/src/format/Makefile.am
+++ b/src/format/Makefile.am
@@ -2,38 +2,22 @@
noinst_LTLIBRARIES = libformat.la
libformat_la_SOURCES = \
+ debuggable-int.h \
+ debuggable.h debuggable.c \
executable-int.h \
executable.h executable.c \
format-int.h \
format.h format.c \
symbol.h symbol.c
-# libformat_la_SOURCES = \
-# exe_format.h exe_format.c \
-# exe_format-int.h \
-# executable-int.h \
-# executable.h executable.c \
-# format-int.h \
-# format.h format.c \
-# dbg_format.h dbg_format.c \
-# dbg_format-int.h \
-# part.h part.c
-
libformat_la_LIBADD = \
dex/libformatdex.la \
+ dwarf/libformatdwarf.la \
elf/libformatelf.la \
java/libformatjava.la \
mangling/libformatmangling.la \
pe/libformatpe.la
-# libformat_la_LIBADD = \
-# dex/libformatdex.la \
-# dwarf/libformatdwarf.la \
-# elf/libformatelf.la \
-# java/libformatjava.la \
-# mangling/libformatmangling.la \
-# pe/libformatpe.la
-
libformat_la_LDFLAGS =
@@ -41,5 +25,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = dex elf java mangling pe
-#SUBDIRS = dex dwarf elf java mangling pe
+SUBDIRS = dex dwarf elf java mangling pe
diff --git a/src/format/dbg_format-int.h b/src/format/dbg_format-int.h
index 2767654..e69de29 100644
--- a/src/format/dbg_format-int.h
+++ b/src/format/dbg_format-int.h
@@ -1,55 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * dbg_format-int.h - prototypes utiles aux formats de débogage
- *
- * Copyright (C) 2008 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * 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 _FORMAT_DBG_FORMAT_INT_H
-#define _FORMAT_DBG_FORMAT_INT_H
-
-
-#include <stdint.h>
-#include <sys/types.h>
-
-
-#include "../dbg_format.h"
-#include "../exe_format.h"
-
-
-
-
-
-/* Structure minimale d'un format de débogage */
-struct _dbg_format{
-
- const uint8_t *content; /* Contenu binaire à étudier */
- off_t length; /* Taille de ce contenu */
-
- exe_format *e_format; /* Gestionnaire d'exécutable */
-
-
-};
-
-
-#define DBG_FORMAT(f) ((dbg_format *)f)
-
-
-
-#endif /* _FORMAT_DBG_FORMAT_INT_H */
diff --git a/src/format/dbg_format.c b/src/format/dbg_format.c
index 3a36049..e69de29 100644
--- a/src/format/dbg_format.c
+++ b/src/format/dbg_format.c
@@ -1,91 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * dbg_format.c - support des formats de débogage
- *
- * Copyright (C) 2008 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * 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 "dbg_format.h"
-
-
-#include <malloc.h>
-
-
-
-/* liste de tous les formats de débogage enregistrés */
-typedef struct _dbg_formats
-{
- dbg_format **list; /* Série d'éléments */
- size_t count; /* Nombre de ces éléments */
-
-} dbg_formats;
-
-
-/* Fournit la liste des formats de débogage enregistrés. */
-dbg_formats *get_debug_formats(void);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Fournit la liste des formats de débogage enregistrés. *
-* *
-* Retour : Liste des formats enregistrés. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-dbg_formats *get_debug_formats(void)
-{
- static dbg_formats *result = NULL; /* Liste à retourner */
-
- if (result == NULL)
- result = (dbg_formats *)calloc(1, sizeof(dbg_formats));
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : format = nouvel élément à inscrire dans l'ensemble. *
-* *
-* Description : Ajoute un nouveau format de débogage à la liste supportée. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void register_debug_format(dbg_format *format)
-{
- dbg_formats *formats; /* Liste à compléter */
-
- formats = get_debug_formats();
-
- formats->list = (dbg_format **)realloc(formats->list, ++formats->count * sizeof(dbg_format *));
- formats->list[formats->count - 1] = format;
-
-}
-
diff --git a/src/format/dbg_format.h b/src/format/dbg_format.h
index bde76e4..e69de29 100644
--- a/src/format/dbg_format.h
+++ b/src/format/dbg_format.h
@@ -1,41 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * dbg_format.h - prototypes pour le support des formats de débogage
- *
- * Copyright (C) 2008 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * 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 _FORMAT_DBG_FORMAT_H
-#define _FORMAT_DBG_FORMAT_H
-
-
-/* Structure minimale d'un format de débogage */
-typedef struct _dbg_format dbg_format;
-
-
-
-/* Ajoute un nouveau format de débogage à la liste supportée. */
-void register_debug_format(dbg_format *);
-
-
-
-
-
-
-#endif /* _FORMAT_DBG_FORMAT_H */
diff --git a/src/format/debuggable-int.h b/src/format/debuggable-int.h
new file mode 100644
index 0000000..855a7bf
--- /dev/null
+++ b/src/format/debuggable-int.h
@@ -0,0 +1,51 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * debuggable-int.h - prototypes utiles aux formats d'exécutables
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _FORMAT_DEBUGGABLE_INT_H
+#define _FORMAT_DEBUGGABLE_INT_H
+
+
+#include "debuggable.h"
+
+
+#include "format-int.h"
+
+
+
+/* Format de débogage générique (instance) */
+struct _GDbgFormat
+{
+ GBinFormat parent; /* A laisser en premier */
+
+};
+
+/* Format de débogage générique (classe) */
+struct _GDbgFormatClass
+{
+ GBinFormatClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _FORMAT_DEBUGGABLE_INT_H */
diff --git a/src/format/debuggable.c b/src/format/debuggable.c
new file mode 100644
index 0000000..f66ab96
--- /dev/null
+++ b/src/format/debuggable.c
@@ -0,0 +1,88 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * debuggable.c - support des formats d'exécutables
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "debuggable.h"
+
+
+#include <malloc.h>
+#include <stdlib.h>
+
+
+#include "debuggable-int.h"
+#include "format.h"
+
+
+
+/* Initialise la classe des formats d'exécutables génériques. */
+static void g_debuggable_format_class_init(GDbgFormatClass *);
+
+/* Initialise une instance de format d'exécutable générique. */
+static void g_debuggable_format_init(GDbgFormat *);
+
+
+
+/* Indique le type défini pour un format de débogage générique. */
+G_DEFINE_TYPE(GDbgFormat, g_debuggable_format, G_TYPE_BIN_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats d'exécutables génériques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_debuggable_format_class_init(GDbgFormatClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format d'exécutable générique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_debuggable_format_init(GDbgFormat *format)
+{
+
+}
+
+
+
+
+
+
+
diff --git a/src/format/debuggable.h b/src/format/debuggable.h
new file mode 100644
index 0000000..35ab386
--- /dev/null
+++ b/src/format/debuggable.h
@@ -0,0 +1,52 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * debuggable.h - prototypes pour le support des formats de débogage
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _FORMAT_DEBUGGABLE_H
+#define _FORMAT_DEBUGGABLE_H
+
+
+#include <glib-object.h>
+
+
+
+#define G_TYPE_DBG_FORMAT g_debuggable_format_get_type()
+#define G_DBG_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_debuggable_format_get_type(), GDbgFormat))
+#define G_IS_DBG_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_debuggable_format_get_type()))
+#define G_DBG_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DBG_FORMAT, GDbgFormatClass))
+#define G_IS_DBG_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DBG_FORMAT))
+#define G_DBG_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DBG_FORMAT, GDbgFormatClass))
+
+
+/* Format de débogage générique (instance) */
+typedef struct _GDbgFormat GDbgFormat;
+
+/* Format de débogage générique (classe) */
+typedef struct _GDbgFormatClass GDbgFormatClass;
+
+
+/* Indique le type défini pour un format de débogage générique. */
+GType g_debuggable_format_get_type(void);
+
+
+
+#endif /* _FORMAT_DEBUGGABLE_H */
diff --git a/src/format/dwarf/Makefile.am b/src/format/dwarf/Makefile.am
index 5c92107..e3889c4 100644
--- a/src/format/dwarf/Makefile.am
+++ b/src/format/dwarf/Makefile.am
@@ -2,7 +2,8 @@
noinst_LTLIBRARIES = libformatdwarf.la
libformatdwarf_la_SOURCES = \
- dwarf.h dwarf.c
+ dwarf.h dwarf.c \
+ dwarf-int.h dwarf-int.c
# libformatdwarf_la_SOURCES = \
# abbrev.h abbrev.c \
@@ -12,9 +13,16 @@ libformatdwarf_la_SOURCES = \
# info.h info.c \
# utils.h utils.c
+libformatdwarf_la_LIBADD = \
+ v2/libformatdwarfv2.la \
+ v3/libformatdwarfv3.la \
+ v4/libformatdwarfv4.la
+
libformatdwarf_la_LDFLAGS = $(LIBGTK_LIBS)
AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS = v2 v3 v4
diff --git a/src/format/dwarf/dwarf-int.c b/src/format/dwarf/dwarf-int.c
new file mode 100644
index 0000000..310f926
--- /dev/null
+++ b/src/format/dwarf/dwarf-int.c
@@ -0,0 +1,75 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf-int.c - structures internes du format DWARF
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "dwarf-int.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* pos = position de début de lecture. [OUT] *
+* endian = boutisme reconnu dans le format. *
+* header = en-tête à déterminer. [OUT] *
+* *
+* Description : Procède à la lecture de l'en-tête d'un contenu binaire ELF. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool read_dwarf_section_header(GBinContent *content, vmpa2t *pos, SourceEndian endian, dw_section_header *header)
+{
+ bool result; /* Bilan à retourner */
+ uint32_t first; /* Premier paquet d'octets */
+ bool status; /* Bilan d'opération */
+
+ result = false;
+
+ status = g_binary_content_read_u32(content, pos, endian, &first);
+ if (!status) goto rdsh_exit;
+
+ if (first >= 0xfffffff0 && first != 0xffffffff)
+ goto rdsh_exit;
+
+ if (first == 0xffffffff)
+ {
+ result = g_binary_content_read_u64(content, pos, endian, &header->unit_length);
+ header->is_32b = false;
+ }
+ else
+ {
+ result = true;
+ header->unit_length = first;
+ header->is_32b = true;
+ }
+
+ result &= g_binary_content_read_u16(content, pos, endian, &header->version);
+
+ rdsh_exit:
+
+ return result;
+
+}
diff --git a/src/format/dwarf/dwarf-int.h b/src/format/dwarf/dwarf-int.h
index 7999d3a..d3bf14a 100644
--- a/src/format/dwarf/dwarf-int.h
+++ b/src/format/dwarf/dwarf-int.h
@@ -25,15 +25,89 @@
#define _FORMAT_DWARF_DWARF_INT_H
+#include "dwarf.h"
-#include "../dbg_format-int.h"
+#include <stdint.h>
+
+
+
+
+#include "../debuggable-int.h"
#include "dwarf_def.h"
+
+
+
+/* En-tête présente dans certaines sections */
+typedef struct _dw_section_header
+{
+ uint64_t unit_length; /* Taille totale sans le champ */
+ bool is_32b; /* Le format est-il sur 32b ? */
+
+ uint16_t version; /* Version de la section */
+
+} dw_section_header;
+
+
+
+
+
+
+/* Procède à la lecture de l'en-tête d'un contenu binaire ELF. */
+bool read_dwarf_section_header(GBinContent *, vmpa2t *, SourceEndian, dw_section_header *);
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* Format de débogage DWARF (instance) */
+struct _GDwarfFormat
+{
+ GDbgFormat parent; /* A laisser en premier */
+
+};
+
+/* Format de débogage DWARF (classe) */
+struct _GDwarfFormatClass
+{
+ GDbgFormatClass parent; /* A laisser en premier */
+
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/* Format du DWARF */
typedef enum _DwarfFormat
{
@@ -81,7 +155,7 @@ typedef struct _dw_dbg_function
} dw_dbg_function;
-
+#if 0
/* Description du format DWARF */
struct _dwarf_format
{
@@ -96,7 +170,7 @@ struct _dwarf_format
size_t dbg_fc_count; /* Nombre de ces fonctions */
};
-
+#endif
diff --git a/src/format/dwarf/dwarf.c b/src/format/dwarf/dwarf.c
index c7b1c23..db8335b 100644
--- a/src/format/dwarf/dwarf.c
+++ b/src/format/dwarf/dwarf.c
@@ -24,63 +24,245 @@
#include "dwarf.h"
+#include "dwarf-int.h"
+#include "../../common/cpp.h"
+/* Initialise la classe des formats de débogage DWARF. */
+static void g_dwarf_format_class_init(GDwarfFormatClass *);
+/* Initialise une instance de format de débogage DWARF. */
+static void g_dwarf_format_init(GDwarfFormat *);
+/* Supprime toutes les références externes. */
+static void g_dwarf_format_dispose(GDwarfFormat *);
+/* Procède à la libération totale de la mémoire. */
+static void g_dwarf_format_finalize(GDwarfFormat *);
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
+* *
+* Description : Indique si le format peut être pris en charge ici. *
+* *
+* Retour : Désignation du format reconnu ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *dwarf_is_matching(GBinContent *content, GExeFormat *parent)
+{
+ const char *result; /* Format détecté à renvoyer */
+ size_t i; /* Boucle de parcours */
+ mrange_t range; /* Couverture d'une section */
+ dw_section_header header; /* En-tête DWARF de section */
+ bool found; /* Bilan d'une comparaison */
+
+ static const char *section_names[] = {
+ ".debug_aranges",
+ ".debug_frame",
+ ".debug_info",
+ ".debug_line",
+ ".debug_pubnames",
+ ".debug_pubtypes",
+ ".debug_types"
+ };
+
+ static const uint16_t dwarf_v2_versions[] = {
+ 2, /* .debug_aranges */
+ 1, /* .debug_frame */
+ 2, /* .debug_info */
+ 2, /* .debug_line */
+ 2, /* .debug_pubnames */
+ 0, /* .debug_pubtypes */
+ 0 /* .debug_types */
+ };
+
+ static const uint16_t dwarf_v3_versions[] = {
+ 2, /* .debug_aranges */
+ 3, /* .debug_frame */
+ 3, /* .debug_info */
+ 3, /* .debug_line */
+ 2, /* .debug_pubnames */
+ 2, /* .debug_pubtypes */
+ 0 /* .debug_types */
+ };
+
+ static const uint16_t dwarf_v4_versions[] = {
+ 2, /* .debug_aranges */
+ 4, /* .debug_frame */
+ 4, /* .debug_info */
+ 4, /* .debug_line */
+ 2, /* .debug_pubnames */
+ 2, /* .debug_pubtypes */
+ 4 /* .debug_types */
+ };
+
+ uint16_t current_versions[] = {
+ 0, /* .debug_aranges */
+ 0, /* .debug_frame */
+ 0, /* .debug_info */
+ 0, /* .debug_line */
+ 0, /* .debug_pubnames */
+ 0, /* .debug_pubtypes */
+ 0 /* .debug_types */
+ };
+
+ result = NULL;
+
+ if (parent == NULL)
+ return NULL;
+
+ /* Lecture des indices présents */
+
+ for (i = 0; i < ARRAY_SIZE(section_names); i++)
+ {
+ if (!g_exe_format_get_section_range_by_name(parent, section_names[i], &range))
+ continue;
+
+ if (!read_dwarf_section_header(content, get_mrange_addr(&range), SRE_LITTLE /* FIXME */, &header))
+ continue;
+
+ current_versions[i] = header.version;
+
+ }
+
+ /* Détermination d'une version bien identifiée */
+
+ bool check_dwarf_version(const uint16_t *ref, const uint16_t *cur, size_t count)
+ {
+ bool equal;
+ size_t k;
+
+ equal = true;
+
+ for (k = 0; k < count && equal; k++)
+ equal = (cur[k] == 0) || (ref[k] == cur[k]);
+
+ return equal;
+
+ }
+
+ /**
+ * Un fichier DWARF sans section sera vu comme un fichier DWARF de
+ * dernière génération.
+ * Ce qui n'est pas très grave car rien ne sera chargé par la suite,
+ * du fait de l'absence de section, donc il n'y aura pas d'incompatibilité.
+ */
+
+ found = check_dwarf_version(dwarf_v4_versions, current_versions, ARRAY_SIZE(section_names));
+
+ if (found)
+ result = "dwarf_v4";
+
+ if (result == NULL)
+ {
+ found = check_dwarf_version(dwarf_v3_versions, current_versions, ARRAY_SIZE(section_names));
+
+ if (found)
+ result = "dwarf_v3";
+ }
+
+ if (result == NULL)
+ {
+ found = check_dwarf_version(dwarf_v2_versions, current_versions, ARRAY_SIZE(section_names));
+
+ if (found)
+ result = "dwarf_v2";
+
+ }
+
+ return result;
+
+}
+
+
+/* Indique le type défini pour un format de débogage générique. */
+G_DEFINE_TYPE(GDwarfFormat, g_dwarf_format, G_TYPE_DBG_FORMAT);
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : klass = classe à initialiser. *
* *
-* Description : Indique si le format peut être pris en charge ici. *
+* Description : Initialise la classe des formats de débogage DWARF. *
* *
-* Retour : true si la réponse est positive, false sinon. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-bool dwarf_is_matching(GBinContent *)
+static void g_dwarf_format_class_init(GDwarfFormatClass *klass)
{
- bool result; /* Bilan à faire connaître */
+ GObjectClass *object; /* Autre version de la classe */
- result = false;
+ object = G_OBJECT_CLASS(klass);
- return result;
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_dwarf_format_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_dwarf_format_finalize;
}
/******************************************************************************
* *
-* Paramètres : content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : format = instance à initialiser. *
* *
-* Description : Prend en charge un nouveau format Dwarf. *
+* Description : Initialise une instance de format de débogage DWARF. *
* *
-* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-GBinFormat *g_dwarf_format_new(const bin_t *content, off_t length)
+static void g_dwarf_format_init(GDwarfFormat *format)
{
+}
- return NULL;
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static void g_dwarf_format_dispose(GDwarfFormat *format)
+{
+ G_OBJECT_CLASS(g_dwarf_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_dwarf_format_finalize(GDwarfFormat *format)
+{
+ G_OBJECT_CLASS(g_dwarf_format_parent_class)->finalize(G_OBJECT(format));
}
diff --git a/src/format/dwarf/dwarf.h b/src/format/dwarf/dwarf.h
index 2e32c8e..a5e988b 100644
--- a/src/format/dwarf/dwarf.h
+++ b/src/format/dwarf/dwarf.h
@@ -25,15 +25,30 @@
#define _FORMAT_DWARF_DWARF_H
-#include "../format.h"
+#include "../executable.h"
+#define G_TYPE_DWARF_FORMAT g_dwarf_format_get_type()
+#define G_DWARF_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dwarf_format_get_type(), GDwarfFormat))
+#define G_IS_DWARF_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dwarf_format_get_type()))
+#define G_DWARF_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DWARF_FORMAT, GDwarfFormatClass))
+#define G_IS_DWARF_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DWARF_FORMAT))
+#define G_DWARF_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DWARF_FORMAT, GDwarfFormatClass))
+
+
+/* Format de débogage DWARF (instance) */
+typedef struct _GDwarfFormat GDwarfFormat;
+
+/* Format de débogage DWARF (classe) */
+typedef struct _GDwarfFormatClass GDwarfFormatClass;
+
+
/* Indique si le format peut être pris en charge ici. */
-bool dwarf_is_matching(GBinContent *);
+const char *dwarf_is_matching(GBinContent *, GExeFormat *);
-/* Prend en charge un nouveau format Dwarf. */
-GBinFormat *g_dwarf_format_new(const bin_t *, off_t);
+/* Indique le type défini pour un format de débogage DWARF. */
+GType g_dwarf_format_get_type(void);
diff --git a/src/format/dwarf/v2/Makefile.am b/src/format/dwarf/v2/Makefile.am
new file mode 100644
index 0000000..54e7719
--- /dev/null
+++ b/src/format/dwarf/v2/Makefile.am
@@ -0,0 +1,12 @@
+
+noinst_LTLIBRARIES = libformatdwarfv2.la
+
+libformatdwarfv2_la_SOURCES = \
+ dwarf.h dwarf.c
+
+libformatdwarfv2_la_LDFLAGS = $(LIBGTK_LIBS)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/format/dwarf/v2/dwarf.c b/src/format/dwarf/v2/dwarf.c
new file mode 100644
index 0000000..73e4e04
--- /dev/null
+++ b/src/format/dwarf/v2/dwarf.c
@@ -0,0 +1,171 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.c - support du format DWARF v2
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "dwarf.h"
+
+
+#include "../dwarf-int.h"
+
+
+
+/* Format de débogage DWARF v2 (instance) */
+struct _GDwarfV2Format
+{
+ GDwarfFormat parent; /* A laisser en premier */
+
+};
+
+/* Format de débogage DWARF v2 (classe) */
+struct _GDwarfV2FormatClass
+{
+ GDwarfFormatClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des formats de débogage DWARF v2. */
+static void g_dwarfv2_format_class_init(GDwarfV2FormatClass *);
+
+/* Initialise une instance de format de débogage DWARF v2. */
+static void g_dwarfv2_format_init(GDwarfV2Format *);
+
+/* Supprime toutes les références externes. */
+static void g_dwarfv2_format_dispose(GDwarfV2Format *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_dwarfv2_format_finalize(GDwarfV2Format *);
+
+
+
+/* Indique le type défini pour un format de débogage DWARF v2. */
+G_DEFINE_TYPE(GDwarfV2Format, g_dwarfv2_format, G_TYPE_DWARF_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats de débogage DWARF v2. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv2_format_class_init(GDwarfV2FormatClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_dwarfv2_format_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_dwarfv2_format_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format de débogage DWARF v2. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv2_format_init(GDwarfV2Format *format)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv2_format_dispose(GDwarfV2Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv2_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_dwarfv2_format_finalize(GDwarfV2Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv2_format_parent_class)->finalize(G_OBJECT(format));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
+* *
+* Description : Prend en charge un nouveau format DWARF (v2). *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinFormat *g_dwarfv2_format_new(GBinContent *content, GExeFormat *parent)
+{
+ GDwarfV2Format *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DWARFV2_FORMAT, NULL);
+
+
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+
+
+ return G_BIN_FORMAT(result);
+
+}
diff --git a/src/format/dwarf/v2/dwarf.h b/src/format/dwarf/v2/dwarf.h
new file mode 100644
index 0000000..360a2e6
--- /dev/null
+++ b/src/format/dwarf/v2/dwarf.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.h - prototypes pour le support du format DWARF v2
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _FORMAT_DWARF_V2_DWARF_H
+#define _FORMAT_DWARF_V2_DWARF_H
+
+
+#include <glib-object.h>
+
+
+#include "../../executable.h"
+#include "../../format.h"
+
+
+
+#define G_TYPE_DWARFV2_FORMAT g_dwarfv2_format_get_type()
+#define G_DWARFV2_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dwarfv2_format_get_type(), GDwarfV2Format))
+#define G_IS_DWARFV2_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dwarfv2_format_get_type()))
+#define G_DWARFV2_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DWARFV2_FORMAT, GDwarfV2FormatClass))
+#define G_IS_DWARFV2_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DWARFV2_FORMAT))
+#define G_DWARFV2_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DWARFV2_FORMAT, GDwarfV2FormatClass))
+
+
+/* Format de débogage DWARF v2 (instance) */
+typedef struct _GDwarfV2Format GDwarfV2Format;
+
+/* Format de débogage DWARF v2 (classe) */
+typedef struct _GDwarfV2FormatClass GDwarfV2FormatClass;
+
+
+/* Indique le type défini pour un format de débogage DWARF v2. */
+GType g_dwarfv2_format_get_type(void);
+
+/* Prend en charge un nouveau format DWARF (v2). */
+GBinFormat *g_dwarfv2_format_new(GBinContent *, GExeFormat *);
+
+
+
+#endif /* _FORMAT_DWARF_V2_DWARF_H */
diff --git a/src/format/dwarf/v3/Makefile.am b/src/format/dwarf/v3/Makefile.am
new file mode 100644
index 0000000..dd6e9cd
--- /dev/null
+++ b/src/format/dwarf/v3/Makefile.am
@@ -0,0 +1,12 @@
+
+noinst_LTLIBRARIES = libformatdwarfv3.la
+
+libformatdwarfv3_la_SOURCES = \
+ dwarf.h dwarf.c
+
+libformatdwarfv3_la_LDFLAGS = $(LIBGTK_LIBS)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/format/dwarf/v3/dwarf.c b/src/format/dwarf/v3/dwarf.c
new file mode 100644
index 0000000..d6198f7
--- /dev/null
+++ b/src/format/dwarf/v3/dwarf.c
@@ -0,0 +1,171 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.c - support du format DWARF v3
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "dwarf.h"
+
+
+#include "../dwarf-int.h"
+
+
+
+/* Format de débogage DWARF v3 (instance) */
+struct _GDwarfV3Format
+{
+ GDwarfFormat parent; /* A laisser en premier */
+
+};
+
+/* Format de débogage DWARF v3 (classe) */
+struct _GDwarfV3FormatClass
+{
+ GDwarfFormatClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des formats de débogage DWARF v3. */
+static void g_dwarfv3_format_class_init(GDwarfV3FormatClass *);
+
+/* Initialise une instance de format de débogage DWARF v3. */
+static void g_dwarfv3_format_init(GDwarfV3Format *);
+
+/* Supprime toutes les références externes. */
+static void g_dwarfv3_format_dispose(GDwarfV3Format *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_dwarfv3_format_finalize(GDwarfV3Format *);
+
+
+
+/* Indique le type défini pour un format de débogage DWARF v3. */
+G_DEFINE_TYPE(GDwarfV3Format, g_dwarfv3_format, G_TYPE_DWARF_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats de débogage DWARF v3. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv3_format_class_init(GDwarfV3FormatClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_dwarfv3_format_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_dwarfv3_format_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format de débogage DWARF v3. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv3_format_init(GDwarfV3Format *format)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv3_format_dispose(GDwarfV3Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv3_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_dwarfv3_format_finalize(GDwarfV3Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv3_format_parent_class)->finalize(G_OBJECT(format));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
+* *
+* Description : Prend en charge un nouveau format DWARF (v3). *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinFormat *g_dwarfv3_format_new(GBinContent *content, GExeFormat *parent)
+{
+ GDwarfV3Format *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DWARFV3_FORMAT, NULL);
+
+
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+
+
+ return G_BIN_FORMAT(result);
+
+}
diff --git a/src/format/dwarf/v3/dwarf.h b/src/format/dwarf/v3/dwarf.h
new file mode 100644
index 0000000..2aaf891
--- /dev/null
+++ b/src/format/dwarf/v3/dwarf.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.h - prototypes pour le support du format DWARF v3
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _FORMAT_DWARF_V3_DWARF_H
+#define _FORMAT_DWARF_V3_DWARF_H
+
+
+#include <glib-object.h>
+
+
+#include "../../executable.h"
+#include "../../format.h"
+
+
+
+#define G_TYPE_DWARFV3_FORMAT g_dwarfv3_format_get_type()
+#define G_DWARFV3_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dwarfv3_format_get_type(), GDwarfV3Format))
+#define G_IS_DWARFV3_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dwarfv3_format_get_type()))
+#define G_DWARFV3_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DWARFV3_FORMAT, GDwarfV3FormatClass))
+#define G_IS_DWARFV3_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DWARFV3_FORMAT))
+#define G_DWARFV3_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DWARFV3_FORMAT, GDwarfV3FormatClass))
+
+
+/* Format de débogage DWARF v3 (instance) */
+typedef struct _GDwarfV3Format GDwarfV3Format;
+
+/* Format de débogage DWARF v3 (classe) */
+typedef struct _GDwarfV3FormatClass GDwarfV3FormatClass;
+
+
+/* Indique le type défini pour un format de débogage DWARF v3. */
+GType g_dwarfv3_format_get_type(void);
+
+/* Prend en charge un nouveau format DWARF (v3). */
+GBinFormat *g_dwarfv3_format_new(GBinContent *, GExeFormat *);
+
+
+
+#endif /* _FORMAT_DWARF_V3_DWARF_H */
diff --git a/src/format/dwarf/v4/Makefile.am b/src/format/dwarf/v4/Makefile.am
new file mode 100644
index 0000000..fb3bc43
--- /dev/null
+++ b/src/format/dwarf/v4/Makefile.am
@@ -0,0 +1,12 @@
+
+noinst_LTLIBRARIES = libformatdwarfv4.la
+
+libformatdwarfv4_la_SOURCES = \
+ dwarf.h dwarf.c
+
+libformatdwarfv4_la_LDFLAGS = $(LIBGTK_LIBS)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/format/dwarf/v4/dwarf.c b/src/format/dwarf/v4/dwarf.c
new file mode 100644
index 0000000..164d321
--- /dev/null
+++ b/src/format/dwarf/v4/dwarf.c
@@ -0,0 +1,171 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.c - support du format DWARF v4
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "dwarf.h"
+
+
+#include "../dwarf-int.h"
+
+
+
+/* Format de débogage DWARF v4 (instance) */
+struct _GDwarfV4Format
+{
+ GDwarfFormat parent; /* A laisser en premier */
+
+};
+
+/* Format de débogage DWARF v4 (classe) */
+struct _GDwarfV4FormatClass
+{
+ GDwarfFormatClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des formats de débogage DWARF v4. */
+static void g_dwarfv4_format_class_init(GDwarfV4FormatClass *);
+
+/* Initialise une instance de format de débogage DWARF v4. */
+static void g_dwarfv4_format_init(GDwarfV4Format *);
+
+/* Supprime toutes les références externes. */
+static void g_dwarfv4_format_dispose(GDwarfV4Format *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_dwarfv4_format_finalize(GDwarfV4Format *);
+
+
+
+/* Indique le type défini pour un format de débogage DWARF v4. */
+G_DEFINE_TYPE(GDwarfV4Format, g_dwarfv4_format, G_TYPE_DWARF_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats de débogage DWARF v4. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv4_format_class_init(GDwarfV4FormatClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_dwarfv4_format_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_dwarfv4_format_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format de débogage DWARF v4. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv4_format_init(GDwarfV4Format *format)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dwarfv4_format_dispose(GDwarfV4Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv4_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_dwarfv4_format_finalize(GDwarfV4Format *format)
+{
+ G_OBJECT_CLASS(g_dwarfv4_format_parent_class)->finalize(G_OBJECT(format));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
+* *
+* Description : Prend en charge un nouveau format DWARF (v4). *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinFormat *g_dwarfv4_format_new(GBinContent *content, GExeFormat *parent)
+{
+ GDwarfV4Format *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DWARFV4_FORMAT, NULL);
+
+
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+
+
+ return G_BIN_FORMAT(result);
+
+}
diff --git a/src/format/dwarf/v4/dwarf.h b/src/format/dwarf/v4/dwarf.h
new file mode 100644
index 0000000..af3c2c4
--- /dev/null
+++ b/src/format/dwarf/v4/dwarf.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dwarf.h - prototypes pour le support du format DWARF v4
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _FORMAT_DWARF_V4_DWARF_H
+#define _FORMAT_DWARF_V4_DWARF_H
+
+
+#include <glib-object.h>
+
+
+#include "../../executable.h"
+#include "../../format.h"
+
+
+
+#define G_TYPE_DWARFV4_FORMAT g_dwarfv4_format_get_type()
+#define G_DWARFV4_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dwarfv4_format_get_type(), GDwarfV4Format))
+#define G_IS_DWARFV4_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dwarfv4_format_get_type()))
+#define G_DWARFV4_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DWARFV4_FORMAT, GDwarfV4FormatClass))
+#define G_IS_DWARFV4_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DWARFV4_FORMAT))
+#define G_DWARFV4_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DWARFV4_FORMAT, GDwarfV4FormatClass))
+
+
+/* Format de débogage DWARF v4 (instance) */
+typedef struct _GDwarfV4Format GDwarfV4Format;
+
+/* Format de débogage DWARF v4 (classe) */
+typedef struct _GDwarfV4FormatClass GDwarfV4FormatClass;
+
+
+/* Indique le type défini pour un format de débogage DWARF v4. */
+GType g_dwarfv4_format_get_type(void);
+
+/* Prend en charge un nouveau format DWARF (v4). */
+GBinFormat *g_dwarfv4_format_new(GBinContent *, GExeFormat *);
+
+
+
+#endif /* _FORMAT_DWARF_V4_DWARF_H */
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index bf5a7a2..7f3af9f 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -75,31 +75,38 @@ static bool g_elf_format_translate_offset_into_vmpa(const GElfFormat *, phys_t,
/* Fournit l'emplacement correspondant à une position physique. */
static bool g_elf_format_translate_address_into_vmpa(const GElfFormat *, virt_t, vmpa2t *);
+/* Fournit l'emplacement d'une section donnée. */
+bool g_elf_format_get_section_range_by_name(const GElfFormat *, const char *, mrange_t *);
+
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
-* Retour : true si la réponse est positive, false sinon. *
+* Retour : Désignation du format reconnu ou NULL si aucun. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool elf_is_matching(GBinContent *content)
+const char *elf_is_matching(GBinContent *content, GExeFormat *parent)
{
- bool result; /* Bilan à faire connaître */
+ const char *result; /* Format détecté à renvoyer */
vmpa2t addr; /* Tête de lecture initiale */
+ bool status; /* Bilan des accès mémoire */
char magic[4]; /* Idenfiant standard */
init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
- result = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+ status = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+
+ status &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
- result &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
+ result = status ? "elf" : NULL;
return result;
@@ -137,6 +144,8 @@ static void g_elf_format_class_init(GElfFormatClass *klass)
exe->translate_phys = (translate_phys_fc)g_elf_format_translate_offset_into_vmpa;
exe->translate_virt = (translate_virt_fc)g_elf_format_translate_address_into_vmpa;
+ exe->get_range_by_name = (get_range_by_name_fc)g_elf_format_get_section_range_by_name;
+
}
@@ -205,6 +214,7 @@ static void g_elf_format_finalize(GElfFormat *format)
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
* *
* Description : Prend en charge un nouveau format ELF. *
* *
@@ -214,7 +224,7 @@ static void g_elf_format_finalize(GElfFormat *format)
* *
******************************************************************************/
-GBinFormat *g_elf_format_new(GBinContent *content)
+GBinFormat *g_elf_format_new(GBinContent *content, GExeFormat *parent)
{
GElfFormat *result; /* Structure à retourner */
@@ -502,6 +512,41 @@ static bool g_elf_format_translate_address_into_vmpa(const GElfFormat *format, v
/******************************************************************************
* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* name = nom de la section recherchée. *
+* range = emplacement en mémoire à renseigner. [OUT] *
+* *
+* Description : Fournit l'emplacement d'une section donnée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_elf_format_get_section_range_by_name(const GElfFormat *format, const char *name, mrange_t *range)
+{
+ bool result; /* Bilan à retourner */
+ phys_t offset; /* Position physique de section*/
+ phys_t size; /* Taille de la section trouvée*/
+ virt_t address; /* Adresse virtuelle de section*/
+ vmpa2t tmp; /* Adresse à initialiser */
+
+ result = find_elf_section_content_by_name(format, name, &offset, &size, &address);
+
+ if (result)
+ {
+ init_vmpa(&tmp, offset, address);
+ init_mrange(range, &tmp, size);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : format = informations chargées à consulter. *
* *
* Description : Présente l'en-tête ELF du format chargé. *
diff --git a/src/format/elf/elf.h b/src/format/elf/elf.h
index 484cda8..8e9a2cc 100644
--- a/src/format/elf/elf.h
+++ b/src/format/elf/elf.h
@@ -31,6 +31,7 @@
#include "elf_def.h"
+#include "../executable.h"
#include "../format.h"
@@ -50,13 +51,13 @@ typedef struct _GElfFormatClass GElfFormatClass;
/* Indique si le format peut être pris en charge ici. */
-bool elf_is_matching(GBinContent *);
+const char *elf_is_matching(GBinContent *, GExeFormat *);
/* Indique le type défini pour un format d'exécutable ELF. */
GType g_elf_format_get_type(void);
/* Prend en charge un nouveau format ELF. */
-GBinFormat *g_elf_format_new(GBinContent *);
+GBinFormat *g_elf_format_new(GBinContent *, GExeFormat *);
/* Présente l'en-tête ELF du format chargé. */
const elf_header *g_elf_format_get_header(const GElfFormat *);
diff --git a/src/format/executable-int.h b/src/format/executable-int.h
index bb46248..704466e 100644
--- a/src/format/executable-int.h
+++ b/src/format/executable-int.h
@@ -52,6 +52,9 @@ typedef bool (* translate_phys_fc) (const GExeFormat *, phys_t, vmpa2t *);
/* Fournit l'emplacement correspondant à une adresse virtuelle. */
typedef bool (* translate_virt_fc) (const GExeFormat *, virt_t, vmpa2t *);
+/* Fournit l'emplacement d'une section donnée. */
+typedef bool (* get_range_by_name_fc) (const GExeFormat *, const char *, mrange_t *);
+
/* Format d'exécutable générique (instance) */
@@ -77,6 +80,8 @@ struct _GExeFormatClass
translate_phys_fc translate_phys; /* Correspondance phys -> vmpa */
translate_virt_fc translate_virt; /* Correspondance virt -> vmpa */
+ get_range_by_name_fc get_range_by_name; /* Emplacement de sections */
+
};
diff --git a/src/format/executable.c b/src/format/executable.c
index ab5543a..aae182a 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -305,3 +305,28 @@ bool g_exe_format_translate_address_into_vmpa(const GExeFormat *format, virt_t a
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* name = nom de la section recherchée. *
+* range = emplacement en mémoire à renseigner. [OUT] *
+* *
+* Description : Fournit l'emplacement d'une section donnée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_exe_format_get_section_range_by_name(const GExeFormat *format, const char *name, mrange_t *range)
+{
+ bool result; /* Bilan à retourner */
+
+ result = G_EXE_FORMAT_GET_CLASS(format)->get_range_by_name(format, name, range);
+
+ return result;
+
+}
diff --git a/src/format/executable.h b/src/format/executable.h
index 8b52ed6..45c736b 100644
--- a/src/format/executable.h
+++ b/src/format/executable.h
@@ -92,5 +92,9 @@ bool g_exe_format_translate_address_into_vmpa(const GExeFormat *, virt_t, vmpa2t
})
+/* Fournit l'emplacement d'une section donnée. */
+bool g_exe_format_get_section_range_by_name(const GExeFormat *, const char *, mrange_t *);
+
+
#endif /* _FORMAT_EXECUTABLE_H */