summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/processor-int.h4
-rw-r--r--src/arch/processor.c58
-rw-r--r--src/arch/x86/processor.c1
3 files changed, 63 insertions, 0 deletions
diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h
index 5dc12ff..6ceb7df 100644
--- a/src/arch/processor-int.h
+++ b/src/arch/processor-int.h
@@ -63,5 +63,9 @@ struct _asm_processor
+/* S'assure qu'une chaîne de caractère tient sur une ligne. */
+char *escape_crlf_bin_string(char *);
+
+
#endif /* _ARCH_PROCESSOR_INT_H */
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 1afb576..17f88b3 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -24,6 +24,10 @@
#include "processor.h"
+#include <regex.h>
+#include <string.h>
+
+
#include "instruction-int.h"
#include "processor-int.h"
@@ -84,6 +88,60 @@ asm_instr *decode_instruction(const asm_processor *proc, const uint8_t *data, of
/******************************************************************************
* *
+* Paramètres : input = chaîne de caractères à traiter. *
+* *
+* Description : S'assure qu'une chaîne de caractère tient sur une ligne. *
+* *
+* Retour : Adresse de la chaîne de caractères modifiée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *escape_crlf_bin_string(char *input)
+{
+ size_t inlen;
+ regex_t preg;
+ int ret;
+ size_t curpos;
+ regmatch_t pmatch[2];
+
+ inlen = strlen(input);
+
+ ret = regcomp(&preg, "(\t|\n|\r)", REG_EXTENDED | REG_ICASE);
+ /* TODO: ret */
+
+ for (curpos = 0; regexec(&preg, &input[curpos], 2, pmatch, 0) != REG_NOMATCH; )
+ {
+ inlen += 1 + 1;
+ input = (char *)realloc(input, inlen * sizeof(char *));
+
+ memmove(&input[curpos + pmatch[1].rm_eo + 1], &input[curpos + pmatch[1].rm_eo], inlen - 1 - curpos - pmatch[1].rm_eo);
+
+ switch (input[curpos + pmatch[1].rm_so])
+ {
+ case '\t':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\t", 2);
+ break;
+ case '\n':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\n", 2);
+ break;
+ case '\r':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\r", 2);
+ break;
+ }
+
+ curpos += pmatch[1].rm_eo + 1;
+
+ }
+
+ return input;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : proc = architecture visée par la procédure. *
* format = format du binaire manipulé. *
* instr = instruction à traiter. *
diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c
index 8cc3a72..8be503c 100644
--- a/src/arch/x86/processor.c
+++ b/src/arch/x86/processor.c
@@ -509,6 +509,7 @@ void x86_print_instruction(const asm_x86_processor *proc, const exe_format *form
break;
case STP_STRING:
+ label = escape_crlf_bin_string(label);
snprintf(&opbuffer[i][oplen], 256 - oplen, " \"%s\"", label);
break;