summaryrefslogtreecommitdiff
path: root/plugins/mobicore/mclf.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-02-16 07:07:15 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-02-16 07:07:15 (GMT)
commit635640a32fecbb9b8a5ddf239b819c022c4b9977 (patch)
treef8fc69a2c2db411000996146536ca5cc4f54d417 /plugins/mobicore/mclf.c
parentbf879f2562545ab7de23f9d38364b7bd4b43fb2c (diff)
Added a basic support for Mobicore truslets.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@472 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/mobicore/mclf.c')
-rw-r--r--plugins/mobicore/mclf.c258
1 files changed, 258 insertions, 0 deletions
diff --git a/plugins/mobicore/mclf.c b/plugins/mobicore/mclf.c
new file mode 100644
index 0000000..3fc9e21
--- /dev/null
+++ b/plugins/mobicore/mclf.c
@@ -0,0 +1,258 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * mclf.c - prise en compte du format binaire 'MCLF'
+ *
+ * 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 "mclf.h"
+
+
+#include <i18n.h>
+
+
+#include "annotations.h"
+#include "mclf-int.h"
+
+
+
+/* Taille maximale d'une description */
+#define MAX_PORTION_DESC 256
+
+
+
+/* Initialise la classe des formats d'exécutables MCLF. */
+static void g_mclf_format_class_init(GMCLFFormatClass *);
+
+/* Initialise une instance de format d'exécutable MCLF. */
+static void g_mclf_format_init(GMCLFFormat *);
+
+/* Indique le type d'architecture visée par le format. */
+static const char *g_mclf_format_get_target_machine(const GMCLFFormat *);
+
+/* Etend la définition des portions au sein d'un binaire. */
+static void g_mclf_format_refine_portions(const GMCLFFormat *, GBinPortion *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* *
+* Description : Indique si le format peut être pris en charge ici. *
+* *
+* Retour : true si la réponse est positive, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool mclf_is_matching(GBinContent *content)
+{
+ bool result; /* Bilan à faire connaître */
+ vmpa2t addr; /* Tête de lecture initiale */
+ char magic[4]; /* Idenfiant standard */
+
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
+
+ result = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+
+ result &= (memcmp(magic, MC_SERVICE_HEADER_MAGIC_STR, 4) == 0);
+
+ return result;
+
+}
+
+
+/* Indique le type défini pour un format d'exécutable MCLF. */
+G_DEFINE_TYPE(GMCLFFormat, g_mclf_format, G_TYPE_EXE_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats d'exécutables MCLF. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_mclf_format_class_init(GMCLFFormatClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format d'exécutable MCLF. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_mclf_format_init(GMCLFFormat *format)
+{
+ GExeFormat *exe_format; /* Format parent à constituer */
+
+ exe_format = G_EXE_FORMAT(format);
+
+ exe_format->get_machine = (get_target_machine_fc)g_mclf_format_get_target_machine;
+ exe_format->refine_portions = (refine_portions_fc)g_mclf_format_refine_portions;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* *
+* Description : Prend en charge un nouveau format MCLF. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinFormat *g_mclf_format_new(GBinContent *content)
+{
+ GMCLFFormat *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_MCLF_FORMAT, NULL);
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+
+
+ if (!read_mclf_header(result, &result->header, result->endian))
+ {
+ /* TODO */
+ return NULL;
+ }
+
+
+
+ if (!load_mclf_symbols(result))
+ {
+ /* TODO */
+ return NULL;
+ }
+
+
+ if (!annotate_mclf_binary(result))
+ printf("ERRR\n");
+
+ return G_BIN_FORMAT(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Indique le type d'architecture visée par le format. *
+* *
+* Retour : Identifiant de l'architecture ciblée par le format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_mclf_format_get_target_machine(const GMCLFFormat *format)
+{
+ const char *result; /* Identifiant à retourner */
+
+ result = "armv7";
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* raw = portion de binaire brut à raffiner. *
+* *
+* Description : Etend la définition des portions au sein d'un binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_mclf_format_refine_portions(const GMCLFFormat *format, GBinPortion *raw)
+{
+ GBinPortion *new; /* Nouvelle portion définie */
+ char desc[MAX_PORTION_DESC]; /* Description d'une portion */
+ vmpa2t addr; /* Emplacement dans le binaire */
+
+ /* Segment de code */
+
+ new = g_binary_portion_new(BPC_CODE);
+
+ sprintf(desc, "%s \"%s\"", _("Segment"), "text");
+ g_binary_portion_set_desc(new, desc);
+
+ init_vmpa(&addr, 0, format->header.v1.text.start);
+ g_binary_portion_set_values(new, &addr, format->header.v1.text.len);
+
+ g_binary_portion_set_rights(new, PAC_WRITE | PAC_EXEC);
+
+ g_binary_portion_include(raw, new);
+
+ /* Segment de données */
+
+ new = g_binary_portion_new(BPC_DATA);
+
+ sprintf(desc, "%s \"%s\"", _("Segment"), "data");
+ g_binary_portion_set_desc(new, desc);
+
+ init_vmpa(&addr, format->header.v1.text.len, format->header.v1.data.start);
+ g_binary_portion_set_values(new, &addr, format->header.v1.data.len);
+
+ g_binary_portion_set_rights(new, PAC_READ | PAC_WRITE);
+
+ g_binary_portion_include(raw, new);
+
+ /* Signature finale */
+
+ new = g_binary_portion_new(BPC_DATA);
+
+ sprintf(desc, "%s \"%s\"", _("Segment"), "sig");
+ g_binary_portion_set_desc(new, desc);
+
+ init_vmpa(&addr, G_BIN_FORMAT(format)->length - 521, VMPA_NO_VIRTUAL); /* FIXME */
+ g_binary_portion_set_values(new, &addr, 521);
+
+ g_binary_portion_set_rights(new, PAC_READ | PAC_WRITE);
+
+ g_binary_portion_include(raw, new);
+
+}