summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-04-12 19:15:35 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-04-12 19:15:35 (GMT)
commit216a3d0121fabd678e50ea6b4fa2447ae9b921f0 (patch)
tree395fcd91b674ff5652e34b46207ba08cc9e7af68 /src/format
parentedac614a164d9cac345d914f4320d71bdb16ab79 (diff)
Created a debugging layout and introduced a heavier use of GLib.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@58 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format')
-rw-r--r--src/format/elf/strings.c25
-rw-r--r--src/format/exe_format.c30
-rw-r--r--src/format/exe_format.h4
3 files changed, 54 insertions, 5 deletions
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index 049f6d4..3178d69 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -59,6 +59,8 @@ bool find_all_elf_strings(elf_format *format)
Elf_Shdr *sections; /* Groupe de sections trouvées */
size_t count; /* Quantité de données */
size_t i; /* Boucle de parcours */
+ off_t offset; /* Position physique */
+ Elf_Phdr phdr; /* En-tête de programme ELF */
/* Données en lecture seule */
@@ -89,6 +91,23 @@ bool find_all_elf_strings(elf_format *format)
parse_elf_string_data(format, str_start, str_size, str_vaddr);
}
+ /* En désespoir de cause, on se rabbat sur les parties de programme directement */
+
+ if (format->str_count == 0 && format->header.e_shnum == 0 /* FIXME : cond. à garder ? */)
+ for (i = 0; i < format->header.e_phnum; i++)
+ {
+ offset = format->header.e_phoff + format->header.e_phentsize * i;
+ if ((offset + format->header.e_phentsize) >= EXE_FORMAT(format)->length) continue;
+
+ memcpy(&phdr, &EXE_FORMAT(format)->content[offset], format->header.e_phentsize);
+
+ if (ELF_PHDR(format, &phdr, p_flags) & PF_R && !(ELF_PHDR(format, &phdr, p_flags) & PF_X))
+ parse_elf_string_data(format, ELF_PHDR(format, &phdr, p_offset),
+ ELF_PHDR(format, &phdr, p_filesz),
+ ELF_PHDR(format, &phdr, p_vaddr));
+
+ }
+
return true;
}
@@ -121,11 +140,11 @@ bool parse_elf_string_data(elf_format *format, const off_t start, const off_t si
{
for (end = i + 1; end < (start + size); end++)
if (!isprint(EXE_FORMAT(format)->content[end])) break;
-
+
format->strings = (elf_string *)realloc(format->strings, ++format->str_count * sizeof(elf_string));
- format->strings[format->str_count - 1].value = (const char *)&EXE_FORMAT(format)->content[i];
- format->strings[format->str_count - 1].len = end - start;
+ format->strings[format->str_count - 1].value = strndup((const char *)&EXE_FORMAT(format)->content[i], end - i);
+ format->strings[format->str_count - 1].len = end - i;
format->strings[format->str_count - 1].vaddress = vaddress + i - start;
i = end;
diff --git a/src/format/exe_format.c b/src/format/exe_format.c
index 89b0b3b..2b8f893 100644
--- a/src/format/exe_format.c
+++ b/src/format/exe_format.c
@@ -29,6 +29,9 @@
#include "exe_format-int.h"
+#include "elf/e_elf.h"
+#include "java/e_java.h"
+#include "pe/e_pe.h"
#include "../panel/log.h"
@@ -57,6 +60,10 @@ static registered_exe_format *exe_formats = NULL;
static size_t exe_formats_count = 0;
+/* Enregistre la disponibilité d'un nouveau format exécutable. */
+void register_exe_format(const char *, exe_match_fc, exe_load_fc);
+
+
/* ---------------------------------------------------------------------------------- */
@@ -220,6 +227,29 @@ int compare_bin_parts(const bin_part **a, const bin_part **b)
/******************************************************************************
* *
+* Paramètres : - *
+* *
+* Description : Procède au chargement des formats d'exécutables reconnus. *
+* *
+* Retour : true pour indiquer un chargement réussi, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_all_exe_formats(void)
+{
+ register_exe_format(_("ELF"), elf_is_matching, load_elf);
+ register_exe_format(_("Java"), java_is_matching, load_java);
+ register_exe_format(_("Portable Executable"), pe_is_matching, load_pe);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : name = désignation humaine associée. *
* match = procédure de reconnaissance fournie. *
* load = fonction de chargement fournie. *
diff --git a/src/format/exe_format.h b/src/format/exe_format.h
index efacfe2..13a37ee 100644
--- a/src/format/exe_format.h
+++ b/src/format/exe_format.h
@@ -79,8 +79,8 @@ typedef bool (* exe_match_fc) (const uint8_t *, off_t);
typedef exe_format * (* exe_load_fc) (const uint8_t *, off_t);
-/* Enregistre la disponibilité d'un nouveau format exécutable. */
-void register_exe_format(const char *, exe_match_fc, exe_load_fc);
+/* Procède au chargement des formats d'exécutables reconnus. */
+bool init_all_exe_formats(void);
/* Charge si possible un nouvel exécutable binaire. */
exe_format *load_new_exe_format(const uint8_t *, off_t);