summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
Diffstat (limited to 'src/format')
-rw-r--r--src/format/Makefile.am19
-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/dwarf/Makefile.am15
-rw-r--r--src/format/dwarf/abbrev.c93
-rw-r--r--src/format/dwarf/abbrev.h41
-rw-r--r--src/format/dwarf/d_dwarf.c75
-rw-r--r--src/format/dwarf/d_dwarf.h48
-rw-r--r--src/format/dwarf/dwarf-int.h46
-rw-r--r--src/format/elf/Makefile.am4
-rw-r--r--src/format/elf/e_elf.c72
-rw-r--r--src/format/elf/e_elf.h (renamed from src/format/elf/format_elf.h)20
-rw-r--r--src/format/elf/elf-int.h55
-rw-r--r--src/format/elf/format_elf.c126
-rw-r--r--src/format/elf/section.c156
-rw-r--r--src/format/elf/section.h40
-rw-r--r--src/format/exe_format-int.h54
-rw-r--r--src/format/exe_format.c53
-rw-r--r--src/format/exe_format.h46
20 files changed, 1016 insertions, 134 deletions
diff --git a/src/format/Makefile.am b/src/format/Makefile.am
index 99afa2e..acc849b 100644
--- a/src/format/Makefile.am
+++ b/src/format/Makefile.am
@@ -1,2 +1,19 @@
-SUBDIRS = elf
+lib_LIBRARIES = libformat.a
+
+libformat_a_SOURCES = \
+ exe_format.h exe_format.c \
+ exe_format-int.h \
+ dbg_format.h dbg_format.c \
+ dbg_format-int.h
+
+libformat_a_CFLAGS = $(AM_CFLAGS)
+
+
+INCLUDES =
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS)
+
+SUBDIRS = dwarf elf
diff --git a/src/format/dbg_format-int.h b/src/format/dbg_format-int.h
new file mode 100644
index 0000000..2d79161
--- /dev/null
+++ b/src/format/dbg_format-int.h
@@ -0,0 +1,55 @@
+
+/* OpenIDA - 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 OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#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
new file mode 100644
index 0000000..fac216d
--- /dev/null
+++ b/src/format/dbg_format.c
@@ -0,0 +1,91 @@
+
+/* OpenIDA - 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 OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "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
new file mode 100644
index 0000000..e00a494
--- /dev/null
+++ b/src/format/dbg_format.h
@@ -0,0 +1,41 @@
+
+/* OpenIDA - 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 OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#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/dwarf/Makefile.am b/src/format/dwarf/Makefile.am
new file mode 100644
index 0000000..d9a3ca6
--- /dev/null
+++ b/src/format/dwarf/Makefile.am
@@ -0,0 +1,15 @@
+
+lib_LIBRARIES = libformatdwarf.a
+
+libformatdwarf_a_SOURCES = \
+ abbrev.h abbrev.c \
+ d_dwarf.h d_dwarf.c
+
+libformatdwarf_a_CFLAGS = $(AM_CFLAGS)
+
+
+INCLUDES =
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS)
diff --git a/src/format/dwarf/abbrev.c b/src/format/dwarf/abbrev.c
new file mode 100644
index 0000000..8cf5dcd
--- /dev/null
+++ b/src/format/dwarf/abbrev.c
@@ -0,0 +1,93 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * abbrev.c - manipulation des abréviation DWARF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "abbrev.h"
+
+
+#include <malloc.h>
+
+
+#include "dwarf-int.h"
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations de débogage à compléter. *
+* *
+* Description : Charge les abréviations trouvés pour un DWARF. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool load_dwarf_abbreviations(dwarf_format *format)
+{
+
+
+
+
+
+ off_t offset;
+ off_t size;
+
+ bool test;
+
+ int i;
+
+
+ printf("Searching...\n");
+
+
+ test = find_exe_section(DBG_FORMAT(format)->e_format, ".debug_abbrev", &offset, &size, NULL);
+
+
+
+
+ printf(" -> offset=%d size=%d\n", offset, size);
+
+
+ for (i = 0; i < size; i++)
+ {
+ if (i % 10 == 0) printf("\n");
+ printf("0x%02hhx ", DBG_FORMAT(format)->content[offset + i]);
+ }
+
+ printf("\n");
+
+
+
+
+
+
+
+
+}
+
diff --git a/src/format/dwarf/abbrev.h b/src/format/dwarf/abbrev.h
new file mode 100644
index 0000000..a949be9
--- /dev/null
+++ b/src/format/dwarf/abbrev.h
@@ -0,0 +1,41 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * abbrev.h - prototypes pour la manipulation des abréviation DWARF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_DWARF_ABBREV_H
+#define _FORMAT_DWARF_ABBREV_H
+
+
+#include <stdbool.h>
+
+
+#include "d_dwarf.h"
+
+
+
+/* Charge les abréviations trouvés pour un DWARF. */
+bool load_dwarf_abbreviations(dwarf_format *);
+
+
+
+
+#endif /* _FORMAT_DWARF_ABBREV_H */
diff --git a/src/format/dwarf/d_dwarf.c b/src/format/dwarf/d_dwarf.c
new file mode 100644
index 0000000..7537e34
--- /dev/null
+++ b/src/format/dwarf/d_dwarf.c
@@ -0,0 +1,75 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * d_dwarf.c - support du format DWARF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "d_dwarf.h"
+
+
+#include <malloc.h>
+
+
+#include "abbrev.h"
+#include "dwarf-int.h"
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* length = taille du contenu en question. *
+* e_format = gestionnaire global (partie exécutable). *
+* *
+* Description : Prend en charge un nouveau DWARF. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+dwarf_format *load_dwarf(const uint8_t *content, off_t length, exe_format *e_format)
+{
+ dwarf_format *result; /* Structure à retourner */
+ bool test; /* Bilan d'une initialisation */
+
+ result = (dwarf_format *)calloc(1, sizeof(dwarf_format));
+
+ DBG_FORMAT(result)->content = content;
+ DBG_FORMAT(result)->length = length;
+
+ DBG_FORMAT(result)->e_format = e_format;
+
+
+ test = load_dwarf_abbreviations(result);
+
+
+ return result;
+
+}
+
+
+
diff --git a/src/format/dwarf/d_dwarf.h b/src/format/dwarf/d_dwarf.h
new file mode 100644
index 0000000..d432d5a
--- /dev/null
+++ b/src/format/dwarf/d_dwarf.h
@@ -0,0 +1,48 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * d_dwarf.h - prototypes pour le support du format DWARF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_DWARF_DWARF_H
+#define _FORMAT_DWARF_DWARF_H
+
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+#include "../exe_format.h"
+
+
+
+/* Description du format DWARF */
+typedef struct _dwarf_format dwarf_format;
+
+
+
+/* Prend en charge un nouveau DWARF. */
+dwarf_format *load_dwarf(const uint8_t *, off_t, exe_format *);
+
+
+
+
+
+#endif /* _FORMAT_DWARF_DWARF_H */
diff --git a/src/format/dwarf/dwarf-int.h b/src/format/dwarf/dwarf-int.h
new file mode 100644
index 0000000..e3bb212
--- /dev/null
+++ b/src/format/dwarf/dwarf-int.h
@@ -0,0 +1,46 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dwarf-int.h - prototypes pour les structures internes du format DWARF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_DWARF_DWARF_INT_H
+#define _FORMAT_DWARF_DWARF_INT_H
+
+
+
+
+#include "../dbg_format-int.h"
+
+
+
+/* Description du format DWARF */
+struct _dwarf_format
+{
+ dbg_format dummy; /* A laisser en premier */
+
+
+
+};
+
+
+
+
+#endif /* _FORMAT_DWARF_DWARF_INT_H */
diff --git a/src/format/elf/Makefile.am b/src/format/elf/Makefile.am
index 3cf5f1c..cb5682d 100644
--- a/src/format/elf/Makefile.am
+++ b/src/format/elf/Makefile.am
@@ -2,7 +2,9 @@
lib_LIBRARIES = libformatelf.a
libformatelf_a_SOURCES = \
- format_elf.h format_elf.c
+ e_elf.h e_elf.c \
+ elf-int.h \
+ section.h section.c
libformatelf_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/format/elf/e_elf.c b/src/format/elf/e_elf.c
new file mode 100644
index 0000000..1c08cf3
--- /dev/null
+++ b/src/format/elf/e_elf.c
@@ -0,0 +1,72 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * e_elf.c - support du format ELF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "e_elf.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "elf-int.h"
+#include "section.h"
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* length = taille du contenu en question. *
+* *
+* Description : Prend en charge un nouvel ELF. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+elf_format *load_elf(const uint8_t *content, off_t length)
+{
+ elf_format *result; /* Structure à retourner */
+ bool test; /* Bilan d'une initialisation */
+
+ result = (elf_format *)calloc(1, sizeof(elf_format));
+
+ EXE_FORMAT(result)->content = content;
+ EXE_FORMAT(result)->length = length;
+
+ EXE_FORMAT(result)->find_section = (find_section_fc)find_elf_section;
+
+ memcpy(&result->header, content, sizeof(Elf32_Ehdr));
+
+
+ test = read_elf_section_names(result);
+
+ printf("ok ? %d\n", test);
+
+
+ return result;
+
+}
diff --git a/src/format/elf/format_elf.h b/src/format/elf/e_elf.h
index 742d036..fabee77 100644
--- a/src/format/elf/format_elf.h
+++ b/src/format/elf/e_elf.h
@@ -1,6 +1,6 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
- * format_elf.h - prototypes pour le support du format ELF
+ * e_elf.h - prototypes pour le support du format ELF
*
* Copyright (C) 2008 Cyrille Bagard
*
@@ -21,9 +21,8 @@
*/
-#ifndef _FORMAT_ELF_H
-#define _FORMAT_ELF_H
-
+#ifndef _FORMAT_ELF_ELF_H
+#define _FORMAT_ELF_ELF_H
#include <stdbool.h>
@@ -32,9 +31,18 @@
-bool find_text_data(const uint8_t *content, off_t *, off_t *, uint64_t *);
+/* Description du format ELF */
+typedef struct _elf_format elf_format;
+
+
+
+/* Prend en charge un nouvel ELF. */
+elf_format *load_elf(const uint8_t *, off_t);
+
+
+
-#endif /* _FORMAT_ELF_H */
+#endif /* _FORMAT_ELF_ELF_H */
diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h
new file mode 100644
index 0000000..0fd325f
--- /dev/null
+++ b/src/format/elf/elf-int.h
@@ -0,0 +1,55 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * elf-int.h - prototypes pour les structures internes du format ELF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_ELF_ELF_INT_H
+#define _FORMAT_ELF_ELF_INT_H
+
+
+
+#include <elf.h>
+#include <sys/types.h>
+
+
+#include "../exe_format-int.h"
+
+
+
+
+/* Description du format ELF */
+struct _elf_format
+{
+ exe_format dummy; /* A laisser en premier */
+
+ Elf32_Ehdr header; /* En-tête du format */
+
+ char *sec_names; /* Noms des sections */
+ size_t sec_size; /* Taille de ces définitions */
+
+
+};
+
+
+
+
+
+#endif /* _FORMAT_ELF_ELF_INT_H */
diff --git a/src/format/elf/format_elf.c b/src/format/elf/format_elf.c
deleted file mode 100644
index 9f929fb..0000000
--- a/src/format/elf/format_elf.c
+++ /dev/null
@@ -1,126 +0,0 @@
-
-/* OpenIDA - Outil d'analyse de fichiers binaires
- * format_elf.c - support du format ELF
- *
- * Copyright (C) 2008 Cyrille Bagard
- *
- * This file is part of OpenIDA.
- *
- * OpenIDA is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * OpenIDA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "elf.h"
-
-
-
-
-
-
-
-
-
-
-#include <ctype.h>
-#include <elf.h>
-#include <malloc.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-char *read_section_names(const uint8_t *content, Elf32_Off offset)
-{
- char *result;
- Elf32_Shdr section;
-
- result = NULL;
-
- memcpy(&section, &content[offset], sizeof(Elf32_Shdr));
-
- result = (char *)calloc(section.sh_size + 1, sizeof(char));
-
- memcpy(result, &content[section.sh_offset], section.sh_size);
-
- return result;
-
-}
-
-
-bool find_target_section(const uint8_t *content, const char *target, const char *names, Elf32_Off offset, Elf32_Shdr *data)
-{
- bool result;
- Elf32_Shdr section;
-
- result = false;
-
- memcpy(&section, &content[offset], sizeof(Elf32_Shdr));
-
- result = (strcmp(target, &names[section.sh_name]) == 0);
-
- if (result)
- {
- printf("section: %s (0x%08x)\n", &names[section.sh_name], section.sh_addr);
- *data = section;
- }
-
- return result;
-
-}
-
-
-
-bool find_text_data(const uint8_t *content, off_t *offset, off_t *size, uint64_t *voffset)
-{
- bool result;
- Elf32_Ehdr header;
- char *names;
- Elf32_Half i;
- Elf32_Shdr data;
-
- result = false;
-
- memcpy(&header, content, sizeof(Elf32_Ehdr));
-
- names = read_section_names(content, header.e_shoff + header.e_shentsize * header.e_shstrndx);
- if (names == NULL)
- {
- fprintf(stderr, "no section header string table\n");
- return NULL;
- }
-
- for (i = 0; i < header.e_shnum; i++)
- {
- if (i == header.e_shstrndx) continue;
-
- if (find_target_section(content, ".text", names, header.e_shoff + header.e_shentsize * i, &data))
- {
- printf("Find it !\n");
-
- *offset = data.sh_offset;
- *size = data.sh_size;
- *voffset = data.sh_addr;
-
- result = true;
-
- }
-
- }
-
- free(names);
-
- return result;
-
-}
diff --git a/src/format/elf/section.c b/src/format/elf/section.c
new file mode 100644
index 0000000..a055f47
--- /dev/null
+++ b/src/format/elf/section.c
@@ -0,0 +1,156 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * section.h - prototypes pour la gestion des sections d'un ELF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "section.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "elf-int.h"
+
+
+
+/* Teste si une section correspond à celle recherchée. */
+bool find_target_elf_section(const elf_format *, const char *, Elf32_Off, Elf32_Shdr *);
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à compléter. *
+* *
+* Description : Charge en mémoire la liste humaine des sections. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool read_elf_section_names(elf_format *format)
+{
+ off_t offset; /* Position des données */
+ Elf32_Shdr section; /* Section visée */
+
+ offset = format->header.e_shoff + format->header.e_shentsize * format->header.e_shstrndx;
+ if ((offset + sizeof(Elf32_Shdr)) >= EXE_FORMAT(format)->length) return false;
+
+ memcpy(&section, &EXE_FORMAT(format)->content[offset], sizeof(Elf32_Shdr));
+
+ if ((section.sh_offset + section.sh_size) >= EXE_FORMAT(format)->length) return false;
+
+ format->sec_names = (char *)calloc(section.sh_size + 1, sizeof(char));
+ format->sec_size = section.sh_size;
+
+ memcpy(format->sec_names, &EXE_FORMAT(format)->content[section.sh_offset], section.sh_size);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* target = nom de la section recherchée. *
+* offset = position de la section à tester. *
+* data = description de la section trouvée. [OUT] *
+* *
+* Description : Teste si une section correspond à celle recherchée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool find_target_elf_section(const elf_format *format, const char *target, Elf32_Off offset, Elf32_Shdr *data)
+{
+ bool result; /* Conclusion à retourner */
+ Elf32_Shdr section; /* Section à analyser */
+
+ result = false;
+
+ if ((offset + sizeof(Elf32_Shdr)) >= EXE_FORMAT(format)->length) return false;
+
+ memcpy(&section, &EXE_FORMAT(format)->content[offset], sizeof(Elf32_Shdr));
+
+ result = (strcmp(target, &format->sec_names[section.sh_name]) == 0);
+
+ if (result) *data = section;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* target = nom de la section recherchée. *
+* offset = position de la section trouvée. [OUT] *
+* size = taille de la section trouvée. [OUT] *
+* voffset = adresse virtuelle de la section trouvée. [OUT] *
+* *
+* Description : Recherche une section donnée au sein de binaire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool find_elf_section(const elf_format *format, const char *target, off_t *offset, off_t *size, uint64_t *voffset)
+{
+ bool result;
+ Elf32_Half i;
+ Elf32_Shdr data;
+
+ result = false;
+
+ for (i = 0; i < format->header.e_shnum; i++)
+ {
+ if (i == format->header.e_shstrndx) continue;
+
+ if (find_target_elf_section(format, target,
+ format->header.e_shoff + format->header.e_shentsize * i, &data))
+ {
+ *offset = data.sh_offset;
+ *size = data.sh_size;
+
+ if (voffset != NULL)
+ *voffset = data.sh_addr;
+
+ result = true;
+
+ }
+
+ }
+
+ return result;
+
+}
diff --git a/src/format/elf/section.h b/src/format/elf/section.h
new file mode 100644
index 0000000..b84fe76
--- /dev/null
+++ b/src/format/elf/section.h
@@ -0,0 +1,40 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * section.h - prototypes pour la gestion des sections d'un ELF
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_ELF_SECTION_H
+#define _FORMAT_ELF_SECTION_H
+
+
+#include "e_elf.h"
+
+
+
+/* Charge en mémoire la liste humaine des sections. */
+bool read_elf_section_names(elf_format *);
+
+/* Recherche une section donnée au sein de binaire. */
+bool find_elf_section(const elf_format *, const char *, off_t *, off_t *, uint64_t *);
+
+
+
+#endif /* _FORMAT_ELF_SECTION_H */
diff --git a/src/format/exe_format-int.h b/src/format/exe_format-int.h
new file mode 100644
index 0000000..a8333de
--- /dev/null
+++ b/src/format/exe_format-int.h
@@ -0,0 +1,54 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * exe_format-int.h - prototypes utiles aux formats d'exécutables
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_EXE_FORMAT_INT_H
+#define _FORMAT_EXE_FORMAT_INT_H
+
+
+#include "exe_format.h"
+
+
+
+/* Recherche une section donnée au sein de binaire. */
+typedef bool (* find_section_fc) (const exe_format *, const char *, off_t *, off_t *, uint64_t *);
+
+
+
+/* Support générique d'un format d'exécutable */
+struct _exe_format
+{
+ const uint8_t *content; /* Contenu binaire à étudier */
+ off_t length; /* Taille de ce contenu */
+
+ find_section_fc find_section; /* Recherche d'une section */
+
+};
+
+
+#define EXE_FORMAT(f) ((exe_format *)f)
+
+
+
+
+
+#endif /* _FORMAT_EXE_FORMAT_INT_H */
diff --git a/src/format/exe_format.c b/src/format/exe_format.c
new file mode 100644
index 0000000..48a4d4c
--- /dev/null
+++ b/src/format/exe_format.c
@@ -0,0 +1,53 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * exe_format.h - support des formats d'exécutables
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "exe_format.h"
+
+
+#include "exe_format-int.h"
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* target = nom de la section recherchée. *
+* offset = position de la section trouvée. [OUT] *
+* size = taille de la section trouvée. [OUT] *
+* voffset = adresse virtuelle de la section trouvée. [OUT] *
+* *
+* Description : Recherche une section donnée au sein de binaire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool find_exe_section(const exe_format *format, const char *target, off_t *offset, off_t *size, uint64_t *voffset)
+{
+ return format->find_section(format, target, offset, size, voffset);
+
+}
diff --git a/src/format/exe_format.h b/src/format/exe_format.h
new file mode 100644
index 0000000..0ec727b
--- /dev/null
+++ b/src/format/exe_format.h
@@ -0,0 +1,46 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * exe_format.h - prototypes pour le support des formats d'exécutables
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_EXE_FORMAT_H
+#define _FORMAT_EXE_FORMAT_H
+
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+
+
+/* Support générique d'un format d'exécutable */
+typedef struct _exe_format exe_format;
+
+
+
+
+/* Recherche une section donnée au sein de binaire. */
+bool find_exe_section(const exe_format *, const char *, off_t *, off_t *, uint64_t *);
+
+
+
+
+#endif /* _FORMAT_EXE_FORMAT_H */