summaryrefslogtreecommitdiff
path: root/src/format/elf/strings.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-03-03 23:51:04 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-03-03 23:51:04 (GMT)
commitdc9e68505c4cc7ad208e63dbc7d0e0e8f582d0d9 (patch)
tree1e597f7d2ab5a8bb2f3c106a4a14b05f481c4efe /src/format/elf/strings.c
parent4724b73c5161140222cab3c61bb5b3d0c8dde360 (diff)
Loaded and displayed found strings in ELF.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@481 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf/strings.c')
-rw-r--r--src/format/elf/strings.c80
1 files changed, 64 insertions, 16 deletions
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index 09bd442..f2c5dd3 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -32,6 +32,7 @@
#include "elf-int.h"
#include "section.h"
+#include "../../arch/raw.h"
@@ -141,7 +142,7 @@ bool find_all_elf_strings(GElfFormat *format)
* *
* Description : Enregistre toutes les chaînes de caractères trouvées. *
* *
-* Retour : true si des chaînes ont été ajoutées, false sinon. *
+* Retour : true si des chaînes ont été ajoutées sans erreur, ou false. *
* *
* Remarques : - *
* *
@@ -150,36 +151,83 @@ bool find_all_elf_strings(GElfFormat *format)
bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t address)
{
bool result; /* Bilan à faire remonter */
- const bin_t *content; /* Contenu binaire à lire */
- off_t length; /* Taille totale du contenu */
+ GBinContent *content; /* Contenu binaire à lire */
+ char *data; /* Données copiées à traiter */
+ vmpa2t pos; /* Tête de lecture */
+ bool cut; /* Séparation nette ? */
off_t i; /* Boucle de parcours */
off_t end; /* Position de fin de chaîne */
- GBinSymbol *symbol; /* Nouveau symbole construit */
+ GArchInstruction *instr; /* Instruction décodée */
+ GBinSymbol *symbol; /* Symbole à intégrer */
+ char *label; /* Désignation de la chaîne */
if (address == 0) return false;
result = false;
- content = G_BIN_FORMAT(format)->content;
- length = G_BIN_FORMAT(format)->length;
+ /* Préparation des accès */
+
+ content = g_binary_format_get_conten_(G_BIN_FORMAT(format));
+
+ data = (char *)malloc(size * sizeof(char));
+
+ init_vmpa(&pos, start, address);
+
+ if (!g_binary_content_get_raw(content, &pos, size, (bin_t *)data))
+ goto pesd_error;
+
+ /* Boucle de parcours */
- length = MIN(length, start + size);
+ cut = true;
- for (i = start; i < length; i++)
- if (isprint(content[i]))
+ for (i = 0; i < size; i++)
+ if (isprint(data[i]))
{
- for (end = i + 1; end < length; end++)
- if (!isprint(content[end])) break;
-
- 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));
+ for (end = i + 1; end < size; end++)
+ if (!isprint(data[end])) break;
+
+ if (isspace(data[end]) && (end + 1) < size)
+ end++;
+
+ if (data[end] == '\0' && (end + 1) < size)
+ end++;
+
+ init_vmpa(&pos, start + i, address + i);
+
+ instr = g_raw_instruction_new_array(G_BIN_FORMAT(format)->conten_, MDS_8_BITS,
+ end - i, &pos, format->endian);
+
+ g_raw_instruction_mark_as_string(G_RAW_INSTRUCTION(instr), true);
- ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ ADD_STR_AS_SYM(format, symbol, instr);
- i = end;
+ /* Jointure avec la chaîne précédente ? */
+
+ if (cut)
+ {
+ init_vmpa(&pos, start + i, address + i);
+
+ label = create_string_label(G_BIN_FORMAT(format), &pos, &data[i], end - i);
+
+ g_binary_symbol_set_label(symbol, label);
+
+ free(label);
+
+ }
+
+ /* Conclusion */
+
+ cut = (data[end - 1] == '\0');
+
+ i = end - 1;
result = true;
}
+ else cut = true;
+
+ pesd_error:
+
+ free(data);
return result;