summaryrefslogtreecommitdiff
path: root/src/format/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/format.c')
-rw-r--r--src/format/format.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/format/format.c b/src/format/format.c
index 6b63556..2808b67 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -24,6 +24,8 @@
#include "format.h"
+#include <assert.h>
+#include <ctype.h>
#include <malloc.h>
#include <string.h>
@@ -224,6 +226,88 @@ GBinSymbol **g_binary_format_get_symbols(const GBinFormat *format, size_t *count
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
+* addr = adresse liée à la chaîne à traiter. *
+* base = contenu complet et original d'une chaîne. *
+* length = taille de la chaîne à représenter. *
+* *
+* Description : Construit une désignation pour chaîne de caractères. *
+* *
+* Retour : Chaîne de caractères à libérer de la mémoire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *create_string_label(GBinFormat *format, const vmpa2t *addr, const char *base, size_t length)
+{
+ char *result; /* Nouvelle chaîne à retourner */
+ unsigned int wc; /* Nombre de mots rencontrés */
+ size_t iter; /* Tête d'écriture de recopie */
+ size_t i; /* Boucle de parcours */
+ bool empty; /* Base de l'étiquette vide ? */
+ GBinSymbol *found; /* Symbole similaire trouvé */
+ VMPA_BUFFER(last_sfx); /* Dernier suffixe à intégrer */
+
+ result = (char *)calloc(length + 5 + VMPA_MAX_LEN + 1, sizeof(char));
+
+ wc = 0;
+
+ iter = 0;
+
+ for (i = 0; i < length; i++)
+ {
+ if (isalnum(base[i])) result[iter++] = tolower(base[i]);
+
+ else if (iter > 0)
+ {
+ if (result[iter - 1] != '_') wc++;
+
+ if (wc == 3) break;
+
+ if (result[iter - 1] != '_') result[iter++] = '_';
+
+ }
+
+ }
+
+ /* Détermination du suffixe suffisant */
+
+ empty = (iter == 0);
+
+ if (iter > 0 && result[iter - 1] != '_') result[iter++] = '_';
+
+ strcpy(&result[iter], "str");
+ iter += 3;
+
+ found = NULL;
+
+ if (empty || g_binary_format_find_symbol_by_label(format, result, &found))
+ {
+ if (found != NULL)
+ g_object_unref(G_OBJECT(found));
+
+ if (iter > 0 && result[iter - 1] != '_') result[iter++] = '_';
+
+ assert(has_phys_addr(addr) || has_virt_addr(addr));
+
+ /* TODO : use_phy_instead_of_virt */
+ if (has_virt_addr(addr))
+ vmpa2_virt_to_string(addr, MDS_UNDEFINED, last_sfx, NULL);
+ else
+ vmpa2_phys_to_string(addr, MDS_UNDEFINED, last_sfx, NULL);
+
+ strcpy(&result[iter], last_sfx);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
* label = étiquette à retrouver lors des recherches. *
* symbol = éventuel symbole trouvé à déréfenrencer. [OUT] *
* *