/* Chrysalide - Outil d'analyse de fichiers binaires * flat.c - support des formats à plat * * Copyright (C) 2018 Cyrille Bagard * * This file is part of Chrysalide. * * Chrysalide 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. * * Chrysalide 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 Chrysalide. If not, see . */ #include "flat.h" #include #include #include #include "flat-int.h" /* Initialise la classe des formats d'exécutables à plat. */ static void g_flat_format_class_init(GFlatFormatClass *); /* Initialise une instance de format d'exécutable à plat. */ static void g_flat_format_init(GFlatFormat *); /* Supprime toutes les références externes. */ static void g_flat_format_dispose(GFlatFormat *); /* Procède à la libération totale de la mémoire. */ static void g_flat_format_finalize(GFlatFormat *); /* Indique la désignation interne du format. */ static const char *g_flat_format_get_name(const GFlatFormat *); /* Fournit une description humaine du format. */ static const char *g_flat_format_get_description(const GFlatFormat *); /* Assure l'interprétation d'un format en différé. */ static bool g_flat_format_analyze(GFlatFormat *, wgroup_id_t, GtkStatusStack *); /* Informe quant au boutisme utilisé. */ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *); /* Indique le type d'architecture visée par le format. */ static const char *g_flat_format_get_target_machine(const GFlatFormat *); /* Fournit l'adresse principale associée à un format à plat. */ static bool g_flat_format_get_main_address(GFlatFormat *, vmpa2t *); /* Indique le type défini pour un format d'exécutable à plat. */ G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXE_FORMAT); /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * * * * Description : Initialise la classe des formats d'exécutables à plat. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_flat_format_class_init(GFlatFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ GBinFormatClass *fmt; /* Version en format basique */ GExeFormatClass *exe; /* Version en exécutable */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_flat_format_dispose; object->finalize = (GObjectFinalizeFunc)g_flat_format_finalize; fmt = G_BIN_FORMAT_CLASS(klass); fmt->get_name = (format_get_name_fc)g_flat_format_get_name; fmt->get_desc = (format_get_desc_fc)g_flat_format_get_description; fmt->analyze = (format_analyze_fc)g_flat_format_analyze; fmt->get_endian = (format_get_endian_fc)g_flat_format_get_endianness; exe = G_EXE_FORMAT_CLASS(klass); exe->get_machine = (get_target_machine_fc)g_flat_format_get_target_machine; exe->get_main_addr = (get_main_addr_fc)g_flat_format_get_main_address; exe->translate_phys = (translate_phys_fc)g_exe_format_without_virt_translate_offset_into_vmpa; exe->translate_virt = (translate_virt_fc)g_exe_format_without_virt_translate_address_into_vmpa; } /****************************************************************************** * * * Paramètres : format = instance à initialiser. * * * * Description : Initialise une instance de format d'exécutable à plat. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_flat_format_init(GFlatFormat *format) { format->endian = SRE_LITTLE; format->machine = NULL; } /****************************************************************************** * * * Paramètres : format = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_flat_format_dispose(GFlatFormat *format) { G_OBJECT_CLASS(g_flat_format_parent_class)->dispose(G_OBJECT(format)); } /****************************************************************************** * * * Paramètres : format = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_flat_format_finalize(GFlatFormat *format) { G_OBJECT_CLASS(g_flat_format_parent_class)->finalize(G_OBJECT(format)); } /****************************************************************************** * * * Paramètres : content = contenu binaire à parcourir. * * * * Description : Prend en charge un nouveau format à plat. * * * * Retour : Adresse de la structure mise en place ou NULL en cas d'échec.* * * * Remarques : - * * * ******************************************************************************/ GExeFormat *g_flat_format_new(GBinContent *content) { GFlatFormat *result; /* Structure à retourner */ result = g_object_new(G_TYPE_FLAT_FORMAT, NULL); g_binary_format_set_content(G_BIN_FORMAT(result), content); return G_EXE_FORMAT(result); } /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * * * * Description : Indique la désignation interne du format. * * * * Retour : Description du format. * * * * Remarques : - * * * ******************************************************************************/ static const char *g_flat_format_get_name(const GFlatFormat *format) { const char *result; /* Désignation à retourner */ result = "flat"; return result; } /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * * * * Description : Fournit une description humaine du format. * * * * Retour : Description du format. * * * * Remarques : - * * * ******************************************************************************/ static const char *g_flat_format_get_description(const GFlatFormat *format) { const char *result; /* Désignation à retourner */ result = _("Flat executable format"); return result; } /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * * gid = groupe de travail dédié. * * status = barre de statut à tenir informée. * * * * Description : Assure l'interprétation d'un format en différé. * * * * Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatusStack *status) { bool result; /* Bilan à retourner */ result = true; g_executable_format_setup_portions(G_EXE_FORMAT(format), status); g_binary_format_register_code_point(G_BIN_FORMAT(format), 0, true); return result; } /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * * endian = boutisme à associer au format à plat. * * * * Description : Spécifie un boutisme à utiliser. * * * * Retour : Indicateur de boutisme. * * * * Remarques : - * * * ******************************************************************************/ void g_flat_format_set_endianness(GFlatFormat *format, SourceEndian endian) { format->endian = endian; } /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * * * * Description : Informe quant au boutisme utilisé. * * * * Retour : Indicateur de boutisme. * * * * Remarques : - * * * ******************************************************************************/ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format) { return format->endian; } /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * * machine = identifiant de l'architecture visée. * * * * Description : Indique le type d'architecture visée par le format. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ void g_flat_format_set_target_machine(GFlatFormat *format, const char *machine) { if (format->machine != NULL) free(format->machine); if (machine == NULL) format->machine = NULL; else format->machine = strdup(machine); } /****************************************************************************** * * * 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_flat_format_get_target_machine(const GFlatFormat *format) { const char *result; /* Identifiant à retourner */ result = format->machine; return result; } /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * * addr = adresse principale trouvée si possible. [OUT] * * * * Description : Fournit l'adresse principale associée à un format à plat. * * * * Retour : Bilan des recherches. * * * * Remarques : - * * * ******************************************************************************/ static bool g_flat_format_get_main_address(GFlatFormat *format, vmpa2t *addr) { bool result; /* Bilan à retourner */ result = true; init_vmpa(addr, 0, VMPA_NO_VIRTUAL); return result; }