summaryrefslogtreecommitdiff
path: root/src/arch/raw.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/arch/raw.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/arch/raw.c')
-rw-r--r--src/arch/raw.c132
1 files changed, 130 insertions, 2 deletions
diff --git a/src/arch/raw.c b/src/arch/raw.c
index 808d973..3338613 100644
--- a/src/arch/raw.c
+++ b/src/arch/raw.c
@@ -24,6 +24,8 @@
#include "raw.h"
+#include <assert.h>
+#include <ctype.h>
#include <string.h>
@@ -41,6 +43,7 @@ struct _GRawInstruction
GArchInstruction parent; /* A laisser en premier */
bool is_padding; /* Bourrage à représenter ? */
+ bool is_string; /* Chaîne de caractères ? */
};
@@ -370,16 +373,24 @@ static GBufferLine *g_raw_instruction_print(const GRawInstruction *instr, GCodeB
GArchInstruction *base; /* Autre version de l'instance */
const char *key; /* Mot clef principal */
size_t klen; /* Taille de ce mot clef */
+ char *string; /* Chaîne reconstituée */
+ size_t iter; /* Tête d'écriture */
+ bool first; /* Mémorise une énumération */
+ size_t i; /* Boucle de parcours */
+ char byte; /* Octet à afficher (ou pas) */
+ bool status; /* Bilan d'une récupération */
base = G_ARCH_INSTRUCTION(instr);
- if (!instr->is_padding)
+ if (!instr->is_padding && !instr->is_string)
result = G_ARCH_INSTRUCTION_CLASS(g_raw_instruction_parent_class)->print(base, buffer, msize, content, syntax);
else
{
result = g_code_buffer_append_new_line(buffer, &base->range);
+ g_buffer_line_add_flag(result, BLF_HAS_CODE);
+
g_buffer_line_fill_for_instr(result, msize/* TODO ! */, msize, content, base->length, true);
/* Instruction proprement dite */
@@ -389,7 +400,84 @@ static GBufferLine *g_raw_instruction_print(const GRawInstruction *instr, GCodeB
g_buffer_line_insert_text(result, BLC_ASSEMBLY_HEAD, key, klen, RTT_INSTRUCTION);
- g_buffer_line_insert_text(result, BLC_ASSEMBLY, "...", 3, RTT_RAW);
+ if (instr->is_padding)
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, "...", 3, RTT_RAW);
+
+ else /*if (instr->is_string)*/
+ {
+ string = (char *)calloc(base->operands_count + 3, sizeof(char));
+
+ strcpy(string, "\"");
+ iter = 1;
+
+ first = true;
+
+ for (i = 0; i < base->operands_count; i++)
+ {
+ status = g_imm_operand_get_value(G_IMM_OPERAND(base->operands[i]), MDS_8_BITS, &byte);
+ assert(status);
+
+ /* Si le caractère doit apparaître en hexadécimal... */
+ if (!isprint(byte))
+ {
+ /* Si une chaîne précède */
+ if (iter > 1)
+ {
+ if (!first)
+ {
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, " ", 1, RTT_RAW);
+ }
+ else
+ first = false;
+
+ string[iter++] = '"';
+
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, string, iter, RTT_STRING);
+
+ iter = 1;
+
+ }
+
+ /* Impression de l'octet */
+
+ if (!first)
+ {
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, " ", 1, RTT_RAW);
+ }
+ else
+ first = false;
+
+ g_arch_operand_print(base->operands[i], result, syntax);
+
+ }
+
+ else
+ string[iter++] = byte;
+
+ }
+
+ /* Si une chaîne reste encore */
+ if (iter > 1)
+ {
+ if (!first)
+ {
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, " ", 1, RTT_RAW);
+ }
+ else
+ first = false;
+
+ string[iter++] = '"';
+
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY, string, iter, RTT_STRING);
+
+ }
+
+ free(string);
+
+ }
}
@@ -465,3 +553,43 @@ bool g_raw_instruction_is_padding(const GRawInstruction *instr)
return instr->is_padding;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction à traiter. *
+* is_string = nouveau statut à associer au contenu. *
+* *
+* Description : Marque l'instruction comme contenant une chaîne de texte. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_raw_instruction_mark_as_string(GRawInstruction *instr, bool is_string)
+{
+ instr->is_string = is_string;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction à traiter. *
+* is_string = nouveau statut à associer au contenu. *
+* *
+* Description : Indique si le contenu de l'instruction est un texte. *
+* *
+* Retour : Statut du contenu de l'instruction. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_raw_instruction_is_string(const GRawInstruction *instr)
+{
+ return instr->is_string;
+
+}