From 21a05df6423bdc13ca148ff2b96aec80bf7af2b2 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sat, 31 Jan 2015 00:55:26 +0000
Subject: Defined many entry points from many identified potential candidates.

git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@463 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
---
 ChangeLog                       |  50 +++++++
 src/analysis/disass/fetch.c     |  22 +--
 src/format/dex/dex.c            |  23 ----
 src/format/elf/Makefile.am      |   1 +
 src/format/elf/dynamic.c        | 109 +++++++++++++++
 src/format/elf/dynamic.h        |  41 ++++++
 src/format/elf/elf-int.c        |  39 ++++++
 src/format/elf/elf-int.h        |   3 +
 src/format/elf/elf.c            |  23 ----
 src/format/elf/elf_def.h        |  20 ++-
 src/format/elf/symbols.c        | 288 +++++++++++++++++++++++++++++++++++-----
 src/format/exe_format.c         |  19 ---
 src/format/exe_format.h         |   4 -
 src/format/executable-int.h     |   4 -
 src/format/executable.c         |  19 ---
 src/format/executable.h         |   3 -
 src/format/format-int.h         |   3 +-
 src/format/format.c             |  20 ++-
 src/format/format.h             |   5 +-
 src/format/java/java.c          |  23 ----
 src/format/pe/pe.c              |  23 ----
 src/format/symbol.h             |   1 +
 src/plugins/overjump/overjump.c |   2 +-
 23 files changed, 551 insertions(+), 194 deletions(-)
 create mode 100644 src/format/elf/dynamic.c
 create mode 100644 src/format/elf/dynamic.h

diff --git a/ChangeLog b/ChangeLog
index 5f5714e..b986ca4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,55 @@
 15-01-31  Cyrille Bagard <nocbos@gmail.com>
 
+	* src/analysis/disass/fetch.c:
+	Removed all fixed entry points.
+
+	* src/format/dex/dex.c:
+	Update code.
+
+	* src/format/elf/dynamic.c:
+	* src/format/elf/dynamic.h:
+	New entries: manage the DYNAMIC program header and its content.
+
+	* src/format/elf/elf.c:
+	Update code.
+
+	* src/format/elf/elf_def.h:
+	Define some extra tags for dynamic entries types.
+
+	* src/format/elf/elf-int.c:
+	* src/format/elf/elf-int.h:
+	Provide a function to load a dynamic entry.
+
+	* src/format/elf/Makefile.am:
+	Add the new 'dynamic.[ch]' files to libformatelf_la_SOURCES.
+
+	* src/format/elf/symbols.c:
+	Define many entry points from many identified potential candidates.
+
+	* src/format/executable.c:
+	* src/format/executable.h:
+	* src/format/executable-int.h:
+	* src/format/exe_format.c:
+	* src/format/exe_format.h:
+	Update code.
+
+	* src/format/format.c:
+	* src/format/format.h:
+	* src/format/format-int.h:
+	Store and provide many found entry points when asked.
+
+	* src/format/java/java.c:
+	* src/format/pe/pe.c:
+	Update code.
+
+	* src/format/symbol.h:
+	Define a new type for symbols: STP_ENTRY_POINT.
+
+	* src/plugins/overjump/overjump.c:
+	Update code.
+
+15-01-31  Cyrille Bagard <nocbos@gmail.com>
+
 	* src/analysis/disass/area.c:
 	* src/analysis/disass/area.h:
 	* src/analysis/disass/fetch.c:
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
index c3ba2c2..b912ff2 100644
--- a/src/analysis/disass/fetch.c
+++ b/src/analysis/disass/fetch.c
@@ -67,7 +67,8 @@ static void follow_execution_flow(const GLoadedBinary *binary, GProcContext *ctx
 
     printf("-- follow 0x%08x\n", (unsigned int)virt);
 
-    g_proc_context_push_drop_point(ctx, virt);
+    if (virt == VMPA_NO_VIRTUAL)
+        g_proc_context_push_drop_point(ctx, virt);
 
     while (g_proc_context_has_drop_points(ctx))
     {
@@ -142,7 +143,7 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt
 {
     GArchInstruction *result;               /* Instruction désassemblées   */
     GBinFormat *format;                     /* Format du fichier binaire   */
-    GArchProcessor *proc;                   /* Architecture du binaire     */
+    //GArchProcessor *proc;                   /* Architecture du binaire     */
     GProcContext *ctx;                      /* Contexte de désassemblage   */
     off_t length;                           /* Taille des données à lire   */
     mem_area *areas;                        /* Zone de productions         */
@@ -157,9 +158,15 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt
     double done;                            /* Portion de travail accompli */
 
     format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
+
+    /*
     proc = get_arch_processor_from_format(G_EXE_FORMAT(format));
 
     ctx = g_arch_processor_get_context(proc);
+    */
+
+    ctx = g_binary_format_get_disassembling_context(format);
+
 
     /* Définition à la découpe des parties à traiter */
 
@@ -174,16 +181,9 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt
                                   _("Disassembling following the execution flow..."),
                                   0, length);
 
-    /* Insertion du point de départ */
-
-    virt = g_binary_format_get_entry_point(format);
-
-    follow_execution_flow(binary, ctx, &areas, &count, info, 0x84d0);
-
-    follow_execution_flow(binary, ctx, &areas, &count, info, 0x84c5);
-    follow_execution_flow(binary, ctx, &areas, &count, info, 0x8a65);
+    /* Insertion des points de départ */
 
-    follow_execution_flow(binary, ctx, &areas, &count, info, virt);
+    follow_execution_flow(binary, ctx, &areas, &count, info, VMPA_NO_VIRTUAL);
 
     /* Symboles exécutables présents et passés à travers les mailles */
 
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
index 579abde..94ec34a 100755
--- a/src/format/dex/dex.c
+++ b/src/format/dex/dex.c
@@ -54,9 +54,6 @@ static void g_dex_format_decompile(const GDexFormat *, GCodeBuffer *, const char
 /* Indique le type d'architecture visée par le format. */
 static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-static vmpa_t g_dex_format_get_entry_point(const GDexFormat *);
-
 /* Fournit les références aux zones binaires à analyser. */
 static GBinPart **g_dex_format_get_parts(const GDexFormat *, size_t *);
 
@@ -142,7 +139,6 @@ static void g_dex_format_init(GDexFormat *format)
     exe_format = G_EXE_FORMAT(format);
 
     exe_format->get_machine = (get_target_machine_fc)g_dex_format_get_target_machine;
-    exe_format->get_entry_point = (get_entry_point_fc)g_dex_format_get_entry_point;
     exe_format->get_parts = (get_parts_fc)g_dex_format_get_parts;
 
     exe_format->translate_addr = (translate_addr_fc)g_dex_format_translate_address_into_offset;
@@ -357,25 +353,6 @@ static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *for
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static vmpa_t g_dex_format_get_entry_point(const GDexFormat *format)
-{
-    return 0;//(format->is_32b ? format->header.e_entry.addr32 : format->header.e_entry.addr64);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
 *                count  = quantité de zones listées. [OUT]                    *
 *                                                                             *
 *  Description : Fournit les références aux zones binaires à analyser.        *
diff --git a/src/format/elf/Makefile.am b/src/format/elf/Makefile.am
index 67fe148..4317e1d 100644
--- a/src/format/elf/Makefile.am
+++ b/src/format/elf/Makefile.am
@@ -5,6 +5,7 @@ libformatelf_la_SOURCES =				\
 	elf-int.h elf-int.c					\
 	elf.h elf.c							\
 	elf_def.h							\
+	dynamic.h dynamic.c					\
 	helper_arm.h helper_arm.c			\
 	helper_x86.h helper_x86.c			\
 	program.h program.c					\
diff --git a/src/format/elf/dynamic.c b/src/format/elf/dynamic.c
new file mode 100644
index 0000000..e1f50b0
--- /dev/null
+++ b/src/format/elf/dynamic.c
@@ -0,0 +1,109 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * program.c - gestion des en-têtes de programme d'un ELF
+ *
+ * Copyright (C) 2010-2013 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 "dynamic.h"
+
+
+#include "elf-int.h"
+#include "program.h"
+
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : format  = description de l'exécutable à consulter.           *
+*                index   = indice de la section recherchée.                   *
+*                dynamic = ensemble d'informations à faire remonter. [OUT]    *
+*                                                                             *
+*  Description : Recherche un en-tête de programme DYNAMIC au sein de binaire.*
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+bool find_elf_dynamic_program_header(const GElfFormat *format, elf_phdr *dynamic)
+{
+    bool result;                            /* Bilan d'opération à renvoyer*/
+    uint16_t max;                           /* Nombre d'en-têtes présents  */
+    uint16_t i;                             /* Boucle de parcours          */
+
+    result = false;
+
+    max = ELF_HDR(format, format->header, e_phnum);
+
+    for (i = 0; i < max && !result; i++)
+    {
+        if (!find_elf_program_by_index(format, i, dynamic))
+            break;
+
+        result = (ELF_PHDR(format, *dynamic, p_type) == PT_DYNAMIC);
+
+    }
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : format  = informations chargées à consulter.                 *
+*                dynamic = programme de type PT_DYNAMIC.                      *
+*                type    = sorte d'élément recherché.                         *
+*                item    = élément retrouvé dans la section. [OUT]            *
+*                                                                             *
+*  Description : Retrouve un élément donné dans la section dynamique.         *
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr *dynamic, int64_t type, elf_dyn *item)
+{
+    bool result;                            /* Bilan à retourner           */
+    off_t max;                              /* Nombre d'entités présentes  */
+    off_t i;                                /* Boucle de parcours          */
+    off_t pos;                              /* Position de lecture         */
+
+    result = false;
+
+    max = ELF_PHDR(format, *dynamic, p_filesz) / ELF_SIZEOF_DYN(format);
+
+    for (i = 0; i < max && !result; i++)
+    {
+        pos = ELF_PHDR(format, *dynamic, p_offset) + i * ELF_SIZEOF_DYN(format);
+
+        if (!read_elf_dynamic_entry(format, &pos, item))
+            break;
+
+        result = (ELF_DYN(format, *item, d_tag) == type);
+
+    }
+
+    return result;
+
+}
diff --git a/src/format/elf/dynamic.h b/src/format/elf/dynamic.h
new file mode 100644
index 0000000..1de8ee1
--- /dev/null
+++ b/src/format/elf/dynamic.h
@@ -0,0 +1,41 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * dynamic.h - prototypes pour la manipulation de l'en-ête de programme 'DYNAMIC'
+ *
+ * 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_ELF_DYNAMIC_H
+#define _FORMAT_ELF_DYNAMIC_H
+
+
+#include "elf.h"
+#include "elf_def.h"
+
+
+
+/* Recherche un en-tête de programme DYNAMIC au sein de binaire. */
+bool find_elf_dynamic_program_header(const GElfFormat *, elf_phdr *);
+
+/* Retrouve un élément donné dans la section dynamique. */
+bool find_elf_dynamic_item_from_pheader(const GElfFormat *, const elf_phdr *, int64_t, elf_dyn *);
+
+
+
+#endif  /* _FORMAT_ELF_DYNAMIC_H */
diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c
index 677a9ef..a2ef9b2 100644
--- a/src/format/elf/elf-int.c
+++ b/src/format/elf/elf-int.c
@@ -251,6 +251,45 @@ bool read_elf_section_header(const GElfFormat *format, off_t pos, elf_shdr *sect
 *                                                                             *
 *  Paramètres  : format = informations chargées à consulter.                  *
 *                pos    = position de début de lecture. [OUT]                 *
+*                dyn    = structure lue à retourner. [OUT]                    *
+*                                                                             *
+*  Description : Procède à la lecture d'une entrée de type 'DYNAMIC' ELF.     *
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+bool read_elf_dynamic_entry(const GElfFormat *format, off_t *pos, elf_dyn *dyn)
+{
+    bool result;                            /* Bilan à retourner           */
+    const bin_t *content;                   /* Contenu binaire à lire      */
+    off_t length;                           /* Taille totale du contenu    */
+
+    content = G_BIN_FORMAT(format)->content;
+    length = G_BIN_FORMAT(format)->length;
+
+    if (format->is_32b)
+    {
+        result = read_s32(&dyn->dyn32.d_tag, content, pos, length, format->endian);
+        result &= read_u32(&dyn->dyn32.d_un.d_val, content, pos, length, format->endian);
+    }
+    else
+    {
+        result = read_s64(&dyn->dyn64.d_tag, content, pos, length, format->endian);
+        result &= read_u64(&dyn->dyn64.d_un.d_val, content, pos, length, format->endian);
+    }
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : format = informations chargées à consulter.                  *
+*                pos    = position de début de lecture. [OUT]                 *
 *                sym    = structure lue à retourner. [OUT]                    *
 *                                                                             *
 *  Description : Procède à la lecture d'un symbole ELF.                       *
diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h
index 783d27e..34b6cc9 100644
--- a/src/format/elf/elf-int.h
+++ b/src/format/elf/elf-int.h
@@ -61,6 +61,9 @@ bool read_elf_program_header(const GElfFormat *, off_t *, elf_phdr *);
 /* Procède à la lecture d'une en-tête de section ELF. */
 bool read_elf_section_header(const GElfFormat *, off_t, elf_shdr *);
 
+/* Procède à la lecture d'une entrée de type 'DYNAMIC' ELF. */
+bool read_elf_dynamic_entry(const GElfFormat *, off_t *, elf_dyn *);
+
 /* Procède à la lecture d'un symbole ELF. */
 bool read_elf_symbol(const GElfFormat *, off_t *, elf_sym *);
 
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index 6d2138a..00af26d 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -59,9 +59,6 @@ static void g_elf_format_init(GElfFormat *);
 /* Indique le type d'architecture visée par le format. */
 static FormatTargetMachine g_elf_format_get_target_machine(const GElfFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-static vmpa_t g_elf_format_get_entry_point(const GElfFormat *);
-
 /* Etend la définition des portions au sein d'un binaire. */
 static void g_elf_format_refine_portions(const GElfFormat *, GBinPortion *);
 
@@ -145,7 +142,6 @@ static void g_elf_format_init(GElfFormat *format)
     exe_format = G_EXE_FORMAT(format);
 
     exe_format->get_machine = (get_target_machine_fc)g_elf_format_get_target_machine;
-    exe_format->get_entry_point = (get_entry_point_fc)g_elf_format_get_entry_point;
     exe_format->refine_portions = (refine_portions_fc)g_elf_format_refine_portions;
     exe_format->get_parts = (get_parts_fc)g_elf_format_get_parts;
 
@@ -280,25 +276,6 @@ static FormatTargetMachine g_elf_format_get_target_machine(const GElfFormat *for
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static vmpa_t g_elf_format_get_entry_point(const GElfFormat *format)
-{
-    return ELF_HDR(format, format->header, e_entry);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
 *                raw    = portion de binaire brut à raffiner.                 *
 *                                                                             *
 *  Description : Etend la définition des portions au sein d'un binaire.       *
diff --git a/src/format/elf/elf_def.h b/src/format/elf/elf_def.h
index b02469a..a43b417 100644
--- a/src/format/elf/elf_def.h
+++ b/src/format/elf/elf_def.h
@@ -278,7 +278,7 @@ typedef union _elf_phdr
 } elf_phdr;
 
 
-#define ELF_PHDR(fmt, hdr, fld) (fmt->is_32b ? hdr.phdr32.fld : hdr.phdr64.fld)
+#define ELF_PHDR(fmt, hdr, fld) (fmt->is_32b ? (hdr).phdr32.fld : (hdr).phdr64.fld)
 
 #define ELF_SIZEOF_PHDR(fmt) (fmt->is_32b ? sizeof(elf32_phdr) : sizeof(elf64_phdr))
 
@@ -481,6 +481,20 @@ typedef union _elf_dyn
 #define DT_JMPREL       23                  /* Relocalisations PLT         */
 
 
+#define DT_PLTGOT       3               /* Processor defined value */
+
+#define DT_INIT         12              /* Address of init function */
+#define DT_FINI         13              /* Address of termination function */
+
+#define DT_INIT_ARRAY   25              /* Array with addresses of init fct */
+#define DT_FINI_ARRAY   26              /* Array with addresses of fini fct */
+#define DT_INIT_ARRAYSZ 27              /* Size in bytes of DT_INIT_ARRAY */
+#define DT_FINI_ARRAYSZ 28              /* Size in bytes of DT_FINI_ARRAY */
+
+#define DT_PREINIT_ARRAY 32             /* Array with addresses of preinit fct*/
+#define DT_PREINIT_ARRAYSZ 33           /* size in bytes of DT_PREINIT_ARRAY */
+
+
 
 /* ---------------------------- SYMBOLES DE BINAIRES ELF ---------------------------- */
 
@@ -517,7 +531,7 @@ typedef union _elf_sym
 } elf_sym;
 
 
-#define ELF_SYM(fmt, sb, fld) (fmt->is_32b ? sb.sym32.fld : sb.sym64.fld)
+#define ELF_SYM(fmt, sb, fld) (fmt->is_32b ? (sb).sym32.fld : (sb).sym64.fld)
 
 #define ELF_ST_BIND(fmt, sym) (fmt->is_32b ? ELF32_ST_BIND(sym.sym32.st_info) : ELF64_ST_BIND(sym.sym64.st_info))
 #define ELF_ST_TYPE(fmt, sym) (fmt->is_32b ? ELF32_ST_TYPE(sym.sym32.st_info) : ELF64_ST_TYPE(sym.sym64.st_info))
@@ -568,7 +582,7 @@ typedef union _elf_rel
 } elf_rel;
 
 
-#define ELF_REL(fmt, rl, fld) (fmt->is_32b ? rl.rel32.fld : rl.rel64.fld)
+#define ELF_REL(fmt, rl, fld) (fmt->is_32b ? (rl).rel32.fld : (rl).rel64.fld)
 
 #define ELF_REL_SYM(fmt, rl) (fmt->is_32b ? ELF32_R_SYM(rl.rel32.r_info) : ELF64_R_SYM(rl.rel64.r_info))
 #define ELF_REL_TYPE(fmt, rl) (fmt->is_32b ? ELF32_R_TYPE(rl.rel32.r_info) : ELF64_R_TYPE(rl.rel64.r_info))
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index d69e41a..2d8057e 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -24,6 +24,7 @@
 #include "symbols.h"
 
 
+#include <assert.h>
 #include <malloc.h>
 #include <string.h>
 
@@ -31,9 +32,11 @@
 #include <i18n.h>
 
 
+#include "dynamic.h"
 #include "elf-int.h"
 #include "helper_arm.h"
 #include "helper_x86.h"
+#include "program.h"
 #include "section.h"
 #include "../mangling/demangler.h"
 #include "../../arch/raw.h"
@@ -44,6 +47,12 @@
 
 
 
+/* Enregistre un point d'entrée au sein d'un binaire ELF. */
+static void register_elf_entry_point(GElfFormat *, virt_t, phys_t, GBinRoutine *);
+
+/* Enumère tous les points d'entrée principaux d'un binaire ELF. */
+static bool load_all_elf_basic_entry_points(GElfFormat *);
+
 
 
 
@@ -115,18 +124,17 @@ bool load_elf_symbols(GElfFormat *format)
 {
     bool result;                            /* Bilan à retourner           */
 
-	virt_t entry_point;
-        vmpa2t addr;                        /* Localisation d'une routine  */
-        mrange_t range;                     /* Couverture mémoire associée */
-        GBinRoutine *routine;               /* Nouvelle routine trouvée    */
-        GBinSymbol *symbol;                 /* Nouveau symbole construit   */
-
     elf_shdr *sections;                     /* Groupe de sections trouvées */
     size_t count;                           /* Quantité de données         */
 
     result = true;
 
 
+
+    result &= load_all_elf_basic_entry_points(format);
+
+
+
 #if 1
     annotate_elf_header(format);
 
@@ -143,31 +151,6 @@ bool load_elf_symbols(GElfFormat *format)
 
 
 
-    entry_point = ELF_HDR(format, format->header, e_entry);
-
-    G_BIN_FORMAT(format)->entry_point = entry_point;
-
-
-
-    printf("E_ENTRY : 0x%08lx\n", (unsigned long)entry_point);
-
-	if (ELF_HDR(format, format->header, e_machine) == EM_ARM)
-		entry_point &= ~0x1;
-
-
-	init_vmpa(&addr, VMPA_NO_PHYSICAL, entry_point);
-
-	init_mrange(&range, &addr, 0);
-
-	routine = try_to_demangle_routine("entry_point");
-
-	g_binary_routine_set_range(routine, &range);
-
-	symbol = g_binary_symbol_new(STP_ROUTINE, "entry_point", ~0);
-	g_binary_symbol_attach_routine(symbol, routine);
-	g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
-
-
     /* Symboles externes */
 #if 1
     if (find_elf_sections_by_type(format, SHT_DYNAMIC, &sections, &count))
@@ -222,6 +205,249 @@ bool load_elf_symbols(GElfFormat *format)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : format  = description de l'exécutable à compléter.           *
+*                vaddr   = adresse virtuelle du symbole à insérer.            *
+*                len     = taille de la routine à ajouter.                    *
+*                routine = représentation de la fonction repérée.             *
+*                                                                             *
+*  Description : Enregistre un point d'entrée au sein d'un binaire ELF.       *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t len, GBinRoutine *routine)
+{
+    GBinFormat *base;                   /* Version basique de l'instance   */
+    vmpa2t addr;                        /* Localisation d'une routine  */
+    mrange_t range;                     /* Couverture mémoire associée */
+    GBinSymbol *symbol;                 /* Nouveau symbole construit   */
+
+    base = G_BIN_FORMAT(format);
+
+    /* Comptabilisation pour le désassemblage brut */
+
+    base->entry_points = (virt_t *)realloc(base->entry_points, ++base->ep_count * sizeof(virt_t));
+
+    base->entry_points[base->ep_count - 1] = vaddr;
+
+    /* Comptabilisation en tant que symbole */
+
+	if (ELF_HDR(format, format->header, e_machine) == EM_ARM)
+		vaddr &= ~0x1;
+
+	init_vmpa(&addr, VMPA_NO_PHYSICAL, vaddr);
+
+	init_mrange(&range, &addr, len);
+
+	g_binary_routine_set_range(routine, &range);
+
+	symbol = g_binary_symbol_new(STP_ROUTINE, "XXX", ~0);
+	g_binary_symbol_attach_routine(symbol, routine);
+	g_binary_format_add_symbol(base, symbol);
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : format = description de l'exécutable à consulter.            *
+*                                                                             *
+*  Description : Enumère tous les points d'entrée principaux d'un binaire ELF.*
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static bool load_all_elf_basic_entry_points(GElfFormat *format)
+{
+    virt_t ep;                              /* Point d'entrée détecté      */
+    GBinRoutine *routine;                   /* Routine à associer à un pt. */
+    elf_phdr dynamic;                       /* En-tête de programme DYNAMIC*/
+    elf_dyn item_a;                         /* Premier élément DYNAMIC     */
+    elf_dyn item_b;                         /* Second élément DYNAMIC      */
+    const bin_t *content;                   /* Contenu binaire à lire      */
+    off_t length;                           /* Taille totale du contenu    */
+    off_t pos;                              /* Tête de lecture courante    */
+    uint32_t virt_32;                       /* Adresse virtuelle sur 32b   */
+    uint64_t virt_64;                       /* Adresse virtuelle sur 64b   */
+    bool status;                            /* Bilan d'une opération       */
+
+    /* Point d'entrée principal éventuel */
+
+    ep = ELF_HDR(format, format->header, e_entry);
+
+    if (ep != 0x0)
+    {
+        routine = try_to_demangle_routine("entry_point");
+        register_elf_entry_point(format, ep, 0, routine);
+    }
+
+    /* Chargemet de l'en-tête de programme DYNAMIC */
+
+    if (!find_elf_dynamic_program_header(format, &dynamic))
+        goto laebep_exit;
+
+    /* Détection des constructeurs & destructeurs */
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_INIT, &item_a))
+    {
+        ep = ELF_DYN(format, item_a, d_un.d_ptr);
+
+        if (ep != 0x0)
+        {
+            routine = try_to_demangle_routine("init_function");
+            register_elf_entry_point(format, ep, 0, routine);
+        }
+
+    }
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_FINI, &item_a))
+    {
+        ep = ELF_DYN(format, item_a, d_un.d_ptr);
+
+        if (ep != 0x0)
+        {
+            routine = try_to_demangle_routine("termination_function");
+            register_elf_entry_point(format, ep, 0, routine);
+        }
+
+    }
+
+    void load_entry_points_from_array(GElfFormat *fmt, const elf_dyn *ar, const elf_dyn *sz, const char *prefix)
+    {
+        unsigned int i;                     /* Boucle de parcours          */
+        char fullname[64];                  /* Désignation humaine         */
+
+        assert(sizeof(fullname) >= (strlen(prefix) + sizeof(XSTR(UINT64_MAX) + 1)));
+
+        content = G_BIN_FORMAT(fmt)->content;
+        length = G_BIN_FORMAT(fmt)->length;
+
+        if (!translate_address_into_offset_using_elf_programs(fmt, ELF_DYN(fmt, *ar, d_un.d_val), &pos))
+            return;
+
+        if ((pos + ELF_DYN(fmt, *sz, d_un.d_val)) < length)
+            length = pos + ELF_DYN(fmt, *sz, d_un.d_val);
+
+        for (i = 0; pos < length; i++)
+        {
+            if (fmt->is_32b)
+            {
+                status = read_u32(&virt_32, content, &pos, length, fmt->endian);
+                ep = virt_32;
+            }
+            else
+            {
+                status = read_u64(&virt_64, content, &pos, length, fmt->endian);
+                ep = virt_64;
+            }
+
+            if (!status) break;
+
+            if (ep != 0x0)
+            {
+                snprintf(fullname, sizeof(fullname), "%s%u", prefix, i);
+
+                routine = try_to_demangle_routine(fullname);
+                register_elf_entry_point(fmt, ep, 0, routine);
+
+            }
+
+        }
+
+    }
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_INIT_ARRAY, &item_a))
+    {
+        if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_INIT_ARRAYSZ, &item_b))
+        {
+            load_entry_points_from_array(format, &item_a, &item_b, "init_array_function_");
+        }
+
+    }
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_FINI_ARRAY, &item_a))
+    {
+        if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_FINI_ARRAYSZ, &item_b))
+        {
+            load_entry_points_from_array(format, &item_a, &item_b, "fini_array_function_");
+        }
+
+    }
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PREINIT_ARRAY, &item_a))
+    {
+        if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PREINIT_ARRAYSZ, &item_b))
+        {
+            load_entry_points_from_array(format, &item_a, &item_b, "preinit_array_function_");
+        }
+
+    }
+
+    /* Identification de l'entrée de la PLT */
+
+    if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PLTGOT, &item_a))
+    {
+        if (translate_address_into_offset_using_elf_programs(format, ELF_DYN(format, item_a, d_un.d_val), &pos))
+        {
+            content = G_BIN_FORMAT(format)->content;
+            length = G_BIN_FORMAT(format)->length;
+
+            /* On saute le premier élément... */
+            if (format->is_32b)
+                status = read_u32(&virt_32, content, &pos, length, format->endian);
+            else
+                status = read_u64(&virt_64, content, &pos, length, format->endian);
+
+            while (1)
+            {
+                if (format->is_32b)
+                {
+                    status = read_u32(&virt_32, content, &pos, length, format->endian);
+                    ep = virt_32;
+                }
+                else
+                {
+                    status = read_u64(&virt_64, content, &pos, length, format->endian);
+                    ep = virt_64;
+                }
+
+                if (!status) break;
+
+                if (ep != 0x0)
+                {
+                    routine = try_to_demangle_routine("plt_entry");
+                    register_elf_entry_point(format, ep, 0, routine);
+                    break;
+                }
+
+            }
+
+        }
+
+    }
+
+ laebep_exit:
+
+    return true;
+
+}
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : format = description de l'exécutable à consulter.            *
 *                sym    = section comprenant les symboles à venir lire.       *
 *                index  = indice de l'entrée à venir lire.                    *
diff --git a/src/format/exe_format.c b/src/format/exe_format.c
index fe8450c..14f1541 100644
--- a/src/format/exe_format.c
+++ b/src/format/exe_format.c
@@ -370,25 +370,6 @@ FormatTargetMachine get_exe_target_machine(const exe_format *format)
 
 
 
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-uint64_t get_exe_entry_point(const exe_format *format)
-{
-    return format->get_entry_point(format);
-
-}
-
-
 
 
 
diff --git a/src/format/exe_format.h b/src/format/exe_format.h
index 9c29675..b4cecb3 100644
--- a/src/format/exe_format.h
+++ b/src/format/exe_format.h
@@ -126,10 +126,6 @@ typedef enum _ResolvedType
 const uint8_t *get_exe_content(const exe_format *, off_t *);
 
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-uint64_t get_exe_entry_point(const exe_format *);
-
-
 
 /* Indique le type d'architecture visée par le format. */
 FormatTargetMachine get_exe_target_machine(const exe_format *);
diff --git a/src/format/executable-int.h b/src/format/executable-int.h
index a421ce3..51a2625 100644
--- a/src/format/executable-int.h
+++ b/src/format/executable-int.h
@@ -35,9 +35,6 @@
 /* Indique le type d'architecture visée par le format. */
 typedef FormatTargetMachine (* get_target_machine_fc) (const GExeFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-typedef vmpa_t (* get_entry_point_fc) (const GExeFormat *);
-
 /* Etend la définition des portions au sein d'un binaire. */
 typedef void (* refine_portions_fc) (const GExeFormat *, GBinPortion *);
 
@@ -59,7 +56,6 @@ struct _GExeFormat
     GBinFormat parent;                      /* A laisser en premier        */
 
     get_target_machine_fc get_machine;      /* Architecture ciblée         */
-    get_entry_point_fc get_entry_point;     /* Obtention du point d'entrée */
     refine_portions_fc refine_portions;     /* Décrit les portions binaires*/
     get_parts_fc get_parts;                 /* Liste des parties binaires  */
 
diff --git a/src/format/executable.c b/src/format/executable.c
index 0ae6934..db846e2 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -110,25 +110,6 @@ FormatTargetMachine g_exe_format_get_target_machine(const GExeFormat *format)
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-vmpa_t g_exe_format_get_entry_point(const GExeFormat *format)
-{
-    return format->get_entry_point(format);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
 *  Paramètres  : format = description de l'exécutable à consulter.            *
 *                                                                             *
 *  Description : Décrit les différentes portions qui composent le binaire.    *
diff --git a/src/format/executable.h b/src/format/executable.h
index 28ac201..1a3febf 100644
--- a/src/format/executable.h
+++ b/src/format/executable.h
@@ -72,9 +72,6 @@ GType g_executable_format_get_type(void);
 /* Indique le type d'architecture visée par le format. */
 FormatTargetMachine g_exe_format_get_target_machine(const GExeFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-vmpa_t g_exe_format_get_entry_point(const GExeFormat *);
-
 /* Décrit les différentes portions qui composent le binaire. */
 GBinPortion *g_exe_format_get_portions(GExeFormat *);
 
diff --git a/src/format/format-int.h b/src/format/format-int.h
index 21a97b3..85244b6 100644
--- a/src/format/format-int.h
+++ b/src/format/format-int.h
@@ -44,7 +44,8 @@ struct _GBinFormat
     const bin_t *content;                   /* Contenu binaire à étudier   */
     off_t length;                           /* Taille de ce contenu        */
 
-    virt_t entry_point;                     /* Point d'entrée dans le code */
+    virt_t *entry_points;                   /* Points d'entrée du code     */
+    size_t ep_count;                        /* Nombre de ces points        */
 
     GBinSymbol **symbols;                   /* Liste des symboles trouvés  */
     size_t symbols_count;                   /* Quantité de ces symboles    */
diff --git a/src/format/format.c b/src/format/format.c
index ab5b372..73e6794 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -33,6 +33,7 @@
 #include "elf/elf.h"
 #include "java/java.h"
 #include "pe/pe.h"
+#include "../arch/processor.h"
 #include "../decomp/expr/block.h"
 #include "../gui/panels/log.h"
 #include "../plugins/pglist.h"
@@ -182,17 +183,28 @@ const bin_t *g_binary_format_get_content(const GBinFormat *format, off_t *length
 *                                                                             *
 *  Paramètres  : format = description de l'exécutable à consulter.            *
 *                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée d'un binaire.    *
+*  Description : Fournit un contexte initialisé pour un désassemblage.        *
 *                                                                             *
-*  Retour      : Adresse de mémoire virtuelle, voire VMPA_NO_VIRTUAL.         *
+*  Retour      : Nouveau contexte pour désassemblage prêt à emploi.           *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
 ******************************************************************************/
 
-virt_t g_binary_format_get_entry_point(const GBinFormat *format)
+GProcContext *g_binary_format_get_disassembling_context(const GBinFormat *format)
 {
-    return format->entry_point;
+    GProcContext *result;                   /* Contexte à retourner        */
+    GArchProcessor *proc;                   /* Architecture du binaire     */
+    size_t i;                               /* Boucle de parcours          */
+
+    proc = get_arch_processor_from_format(G_EXE_FORMAT(format));
+
+    result = g_arch_processor_get_context(proc);
+
+    for (i = 0; i < format->ep_count; i++)
+        g_proc_context_push_drop_point(result, format->entry_points[i]);
+
+    return result;
 
 }
 
diff --git a/src/format/format.h b/src/format/format.h
index 9b2e0f6..d2034ef 100644
--- a/src/format/format.h
+++ b/src/format/format.h
@@ -32,6 +32,7 @@
 
 #include "symbol.h"
 #include "../analysis/routine.h"
+#include "../arch/context.h"
 
 
 
@@ -58,8 +59,8 @@ GType g_binary_format_get_type(void);
 /* Fournit une référence vers le contenu binaire analysé. */
 const bin_t *g_binary_format_get_content(const GBinFormat *, off_t *);
 
-/* Fournit l'adresse mémoire du point d'entrée d'un binaire. */
-virt_t g_binary_format_get_entry_point(const GBinFormat *);
+/* Fournit un contexte initialisé pour un désassemblage. */
+GProcContext *g_binary_format_get_disassembling_context(const GBinFormat *);
 
 /* Ajoute un symbole à la collection du format binaire. */
 void g_binary_format_add_symbol(GBinFormat *, GBinSymbol *);
diff --git a/src/format/java/java.c b/src/format/java/java.c
index 78cf717..3235711 100755
--- a/src/format/java/java.c
+++ b/src/format/java/java.c
@@ -48,9 +48,6 @@ static void g_java_format_init(GJavaFormat *);
 /* Indique le type d'architecture visée par le format. */
 static FormatTargetMachine g_java_format_get_target_machine(const GJavaFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-static vmpa_t g_java_format_get_entry_point(const GJavaFormat *);
-
 /* Fournit les références aux zones binaires à analyser. */
 static GBinPart **g_java_format_get_parts(const GJavaFormat *, size_t *);
 
@@ -131,7 +128,6 @@ static void g_java_format_init(GJavaFormat *format)
     exe_format = G_EXE_FORMAT(format);
 
     exe_format->get_machine = (get_target_machine_fc)g_java_format_get_target_machine;
-    exe_format->get_entry_point = (get_entry_point_fc)g_java_format_get_entry_point;
     exe_format->get_parts = (get_parts_fc)g_java_format_get_parts;
 
     exe_format->translate_addr = (translate_addr_fc)g_java_format_translate_address_into_offset;
@@ -222,25 +218,6 @@ static FormatTargetMachine g_java_format_get_target_machine(const GJavaFormat *f
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static vmpa_t g_java_format_get_entry_point(const GJavaFormat *format)
-{
-    return 0;//(format->is_32b ? format->header.e_entry.addr32 : format->header.e_entry.addr64);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
 *                count  = quantité de zones listées. [OUT]                    *
 *                                                                             *
 *  Description : Fournit les références aux zones binaires à analyser.        *
diff --git a/src/format/pe/pe.c b/src/format/pe/pe.c
index 54defeb..2692560 100644
--- a/src/format/pe/pe.c
+++ b/src/format/pe/pe.c
@@ -42,9 +42,6 @@ static void g_pe_format_init(GPeFormat *);
 /* Indique le type d'architecture visée par le format. */
 static FormatTargetMachine g_pe_format_get_target_machine(const GPeFormat *);
 
-/* Fournit l'adresse mémoire du point d'entrée du programme. */
-static vmpa_t g_pe_format_get_entry_point(const GPeFormat *);
-
 /* Fournit les références aux zones binaires à analyser. */
 static GBinPart **g_pe_format_get_parts(const GPeFormat *, size_t *);
 
@@ -140,7 +137,6 @@ static void g_pe_format_init(GPeFormat *format)
     exe_format = G_EXE_FORMAT(format);
 
     exe_format->get_machine = (get_target_machine_fc)g_pe_format_get_target_machine;
-    exe_format->get_entry_point = (get_entry_point_fc)g_pe_format_get_entry_point;
     exe_format->get_parts = (get_parts_fc)g_pe_format_get_parts;
 
     exe_format->translate_addr = (translate_addr_fc)g_pe_format_translate_address_into_offset;
@@ -258,25 +254,6 @@ static FormatTargetMachine g_pe_format_get_target_machine(const GPeFormat *forma
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : format = informations chargées à consulter.                  *
-*                                                                             *
-*  Description : Fournit l'adresse mémoire du point d'entrée du programme.    *
-*                                                                             *
-*  Retour      : Adresse de mémoire.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static vmpa_t g_pe_format_get_entry_point(const GPeFormat *format)
-{
-    return 0;//(format->is_32b ? format->header.e_entry.addr32 : format->header.e_entry.addr64);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : format = informations chargées à consulter.                  *
 *                count  = quantité de zones listées. [OUT]                    *
 *                                                                             *
 *  Description : Fournit les références aux zones binaires à analyser.        *
diff --git a/src/format/symbol.h b/src/format/symbol.h
index c5bf750..e123898 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -41,6 +41,7 @@ typedef enum _SymbolType
     STP_ROUTINE,                            /* Simple morceau de code      */
     STP_OBJECT,                             /* Objet quelconque            */
     STP_FUNCTION,                           /* Simple morceau de code      */
+    STP_ENTRY_POINT,                        /* Morceau de code en entrée   */
     STP_STRING                              /* Chaîne de caractères        */
 
 } SymbolType;
diff --git a/src/plugins/overjump/overjump.c b/src/plugins/overjump/overjump.c
index dbd5f1e..8e0fb69 100644
--- a/src/plugins/overjump/overjump.c
+++ b/src/plugins/overjump/overjump.c
@@ -275,7 +275,7 @@ G_MODULE_EXPORT GRenderingLine *disassemble_binary_parts(openida_binary *binary)
     instance = create_overjump_instance(binary);
 
 
-    result = disassemble_address(instance, get_exe_entry_point(instance->format), true);
+    result = disassemble_address(instance, 0/*get_exe_entry_point(instance->format)*/, true);
 
 
 
-- 
cgit v0.11.2-87-g4458