summaryrefslogtreecommitdiff
path: root/src/format/elf
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-08-19 20:25:20 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-08-19 20:25:20 (GMT)
commit2425953ed7330c8f92ec7d04a5f248db1ed98a9d (patch)
treef389f040f6bcc9f88d837e0e2f37cbd49758f610 /src/format/elf
parenta0a7b6c1e05c78ae433f353d15e3366107b67d03 (diff)
Added a demo symbol when loading an ELF header.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@390 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf')
-rw-r--r--src/format/elf/elf-int.c56
-rw-r--r--src/format/elf/elf-int.h2
-rw-r--r--src/format/elf/elf.c2
-rw-r--r--src/format/elf/helper_x86.c4
-rw-r--r--src/format/elf/strings.c2
-rw-r--r--src/format/elf/symbols.c4
6 files changed, 60 insertions, 10 deletions
diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c
index 353ae05..17aeaf2 100644
--- a/src/format/elf/elf-int.c
+++ b/src/format/elf/elf-int.c
@@ -27,11 +27,13 @@
#include <string.h>
+#include "../../arch/raw.h"
+
+
/******************************************************************************
* *
-* Paramètres : content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : format = informations chargées à consulter. *
* header = en-tête à déterminer. [OUT] *
* is_32b = indique si le format est en 32 ou 64 bits. [OUT] *
* endian = boutisme reconnu dans le format. [OUT] *
@@ -44,10 +46,27 @@
* *
******************************************************************************/
-bool read_elf_header(const bin_t *content, off_t length, elf_header *header, bool *is_32b, SourceEndian *endian)
+bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, SourceEndian *endian)
{
bool result; /* Bilan à retourner */
+ const bin_t *content; /* Contenu binaire à lire */
+ off_t length; /* Taille totale du contenu */
off_t pos; /* Position de lecture */
+ GArchInstruction *instr; /* Instruction décodée */
+
+
+ vmpa2t *pos2;
+
+
+ GBinSymbol *symbol;
+
+ size_t i; /* Boucle de parcours */
+ GArchOperand *operand; /* Opérande à venir modifier */
+
+
+
+ content = G_BIN_FORMAT(format)->content;
+ length = G_BIN_FORMAT(format)->length;
result = (length >= EI_NIDENT);
@@ -89,6 +108,37 @@ bool read_elf_header(const bin_t *content, off_t length, elf_header *header, boo
break;
}
+
+ pos2 = make_vmpa(0, 0x123);
+
+
+
+ instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, pos2, 4, *endian);
+
+
+ for (i = 1; i < 4; i++)
+ {
+ operand = g_arch_instruction_get_operand(instr, i);
+ g_imm_operand_set_display(G_IMM_OPERAND(operand), IOD_CHAR);
+ }
+
+
+
+
+ symbol = g_binary_symbol_new(STP_OBJECT, "toto", 0);
+
+ printf("TOTO\n");
+
+ g_binary_symbol_attach_instruction(symbol, instr);
+ g_binary_format_add_symbol(format, symbol);
+
+
+
+
+
+
+
+
if (*is_32b)
{
result &= read_u16(&header->hdr32.e_type, content, &pos, length, *endian);
diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h
index 77548da..783d27e 100644
--- a/src/format/elf/elf-int.h
+++ b/src/format/elf/elf-int.h
@@ -53,7 +53,7 @@ struct _GElfFormatClass
/* Procède à la lecture de l'en-tête d'un contenu binaire ELF. */
-bool read_elf_header(const bin_t *, off_t, elf_header *, bool *, SourceEndian *);
+bool read_elf_header(GElfFormat *, elf_header *, bool *, SourceEndian *);
/* Procède à la lecture d'une en-tête de programme ELF. */
bool read_elf_program_header(const GElfFormat *, off_t *, elf_phdr *);
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index e618658..4a56c52 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -176,7 +176,7 @@ GBinFormat *g_elf_format_new(const bin_t *content, off_t length)
g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
- if (!read_elf_header(content, length, &result->header, &result->is_32b, &result->endian))
+ if (!read_elf_header(result, &result->header, &result->is_32b, &result->endian))
{
/* TODO */
return NULL;
diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c
index 7d85311..d921592 100644
--- a/src/format/elf/helper_x86.c
+++ b/src/format/elf/helper_x86.c
@@ -295,7 +295,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
g_binary_routine_set_address(routine, address);
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
@@ -403,7 +403,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru
g_binary_routine_set_address(routine, address);
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index b75c014..09bd442 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -174,7 +174,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a
symbol = g_binary_symbol_new(STP_STRING, NULL, address + i - start);
g_binary_symbol_set_alt_name(symbol, strndup((const char *)&content[i], end - i));
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
i = end;
result = true;
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 02197a0..c480c51 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -223,7 +223,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
g_binary_routine_set_address(routine, ELF_SYM(format, sym, st_value));
g_binary_routine_set_size(routine, ELF_SYM(format, sym, st_size));
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
@@ -231,7 +231,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
g_binary_symbol_attach_routine(symbol, routine);
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
}