summaryrefslogtreecommitdiff
path: root/tools/d2c/qckcall.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-01-24 11:19:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-01-24 11:19:32 (GMT)
commit141d2f0fbb2ce3b4ddf85383c55b891fd59dc598 (patch)
tree085fa1a20d77f86825e1a6f4215b1ffd8fd961e8 /tools/d2c/qckcall.c
parent3df9f6dc8548b0562312036abfbfcf9850a81041 (diff)
Introduced conditional calls in instruction definition rules.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@459 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'tools/d2c/qckcall.c')
-rw-r--r--tools/d2c/qckcall.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/tools/d2c/qckcall.c b/tools/d2c/qckcall.c
new file mode 100644
index 0000000..ce9a0b2
--- /dev/null
+++ b/tools/d2c/qckcall.c
@@ -0,0 +1,110 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * qckcall.c - appel rapide et facilité à une fonction C de Chrysalide
+ *
+ * Copyright (C) 2015 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "qckcall.h"
+
+
+#include <malloc.h>
+#include <regex.h>
+#include <string.h>
+#include <sys/param.h>
+
+
+#include "helpers.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : callee = fonction appelée à nomer. *
+* args = précise si la conversion est la dernière. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* bits = gestionnaire des bits d'encodage. *
+* list = liste de l'ensemble des fonctions de conversion. *
+* pp = pré-processeur pour les échanges de chaînes. *
+* *
+* Description : Réalise un appel à une fonction liée à une instruction. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool call_instr_func(const char *callee, const arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
+{
+ bool result; /* Bilan à remonter */
+ regex_t preg; /* Expression régulière */
+ int ret; /* Bilan d'une manipulation */
+ regmatch_t pmatch[3]; /* Correspondances de chaînes */
+ size_t cmplen; /* Taille de comparaison */
+ char *cast; /* Macro de transtypage */
+
+ ret = regcomp(&preg, "(g_([a-z0-9]*)_instruction)", REG_EXTENDED);
+ if (ret != 0)
+ {
+ fprintf(stderr, "Internal error: bad regular expression.\n");
+ return false;
+ }
+
+ ret = regexec(&preg, callee, sizeof(pmatch) / sizeof(regmatch_t), pmatch, 0);
+ if (ret == REG_NOMATCH)
+ {
+ fprintf(stderr, "Internal error: bad function for dealing wih instruction: '%s'.\n", callee);
+ result = false;
+ goto cif_exit;
+ }
+
+ /**
+ * La variable de résultat est de type 'GArchInstruction',
+ * donc toute fonction différente de g_arch_instruction_*() attend un transtypage...
+ */
+
+ cmplen = MAX(strlen("arch"), pmatch[2].rm_eo - pmatch[2].rm_so);
+
+ if (strncmp("arch", &callee[pmatch[2].rm_so], cmplen) == 0)
+ dprintf(fd, "\t\tif (!%s(instr, ", callee);
+
+ else
+ {
+ cast = strndup(&callee[pmatch[1].rm_so], pmatch[1].rm_eo - pmatch[1].rm_so);
+
+ cast = make_string_upper(cast);
+
+ dprintf(fd, "\t\tif (!%s(%s(instr), ", callee, cast);
+
+ free(cast);
+
+ }
+
+ result = define_arg_list(args, fd, bits, list);
+
+ dprintf(fd, "))\n");
+
+ cif_exit:
+
+ regfree(&preg);
+
+ return result;
+
+}