diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-08-19 20:25:20 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-08-19 20:25:20 (GMT) |
commit | 2425953ed7330c8f92ec7d04a5f248db1ed98a9d (patch) | |
tree | f389f040f6bcc9f88d837e0e2f37cbd49758f610 /src/arch/raw.c | |
parent | a0a7b6c1e05c78ae433f353d15e3366107b67d03 (diff) |
Added a demo symbol when loading an ELF header.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@390 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/raw.c')
-rw-r--r-- | src/arch/raw.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/src/arch/raw.c b/src/arch/raw.c new file mode 100644 index 0000000..0d6ae4a --- /dev/null +++ b/src/arch/raw.c @@ -0,0 +1,246 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * artificial.c - instructions pures vues de l'esprit + * + * Copyright (C) 2009-2012 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 "raw.h" + + +#include "immediate.h" +#include "instruction-int.h" + + + +/* ------------------------- INSTRUCTION INCONNUE / DONNEES ------------------------- */ + + +/* Définition générique d'une instruction d'architecture inconnue (instance) */ +struct _GRawInstruction +{ + GArchInstruction parent; /* A laisser en premier */ + +}; + +/* Définition générique d'une instruction d'architecture inconnue (classe) */ +struct _GRawInstructionClass +{ + GArchInstructionClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe générique des opérandes. */ +static void g_raw_instruction_class_init(GRawInstructionClass *); + +/* Initialise une instance d'opérande d'architecture. */ +static void g_raw_instruction_init(GRawInstruction *); + +/* Supprime toutes les références externes. */ +static void g_raw_instruction_dispose(GRawInstruction *); + +/* Procède à la libération totale de la mémoire. */ +static void g_raw_instruction_finalize(GRawInstruction *); + +/* Fournit le nom humain de l'instruction manipulée. */ +static const char *g_raw_instruction_get_keyword(const GRawInstruction *, AsmSyntax); + + + +/* ---------------------------------------------------------------------------------- */ +/* INSTRUCTION INCONNUE / DONNEES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour une instruction inconnue d'architecture. */ +G_DEFINE_TYPE(GRawInstruction, g_raw_instruction, G_TYPE_ARCH_INSTRUCTION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe générique des opérandes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_raw_instruction_class_init(GRawInstructionClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GArchInstructionClass *instr; /* Encore une autre vision... */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_raw_instruction_dispose; + object->finalize = (GObjectFinalizeFunc)g_raw_instruction_finalize; + + instr = G_ARCH_INSTRUCTION_CLASS(klass); + + instr->get_key = (get_instruction_keyword_fc)g_raw_instruction_get_keyword; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance à initialiser. * +* * +* Description : Initialise une instance d'instruction d'architecture. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_raw_instruction_init(GRawInstruction *instr) +{ + GArchInstruction *parent; /* Instance parente */ + + parent = G_ARCH_INSTRUCTION(instr); + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_raw_instruction_dispose(GRawInstruction *instr) +{ + G_OBJECT_CLASS(g_raw_instruction_parent_class)->dispose(G_OBJECT(instr)); + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_raw_instruction_finalize(GRawInstruction *instr) +{ + G_OBJECT_CLASS(g_raw_instruction_parent_class)->finalize(G_OBJECT(instr)); + +} + + +/****************************************************************************** +* * +* Paramètres : data = flux de données à analyser. * +* size = taille de chacun des éléments à représenter. * +* count = nombre de ces éléments. * +* addr = position courante dans ce flux. [OUT] * +* end = limite des données à analyser. * +* endian = ordre des bits dans la source. * +* * +* Description : Crée une instruction de type 'db/dw/etc' étendue. * +* * +* Retour : Instruction mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchInstruction *g_raw_instruction_new_array(const bin_t *data, MemoryDataSize size, size_t count, vmpa2t *addr, off_t end, SourceEndian endian) +{ + GArchInstruction *result; /* Instruction à retourner */ + vmpa2t *old; /* Sauvegarde de la position */ + size_t i; /* Boucle de parcours */ + GArchOperand *operand; /* Octet non décodé à afficher */ + + /* Par soucis de cohérence */ + if (count == 0) return NULL; + + result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL); + + old = dup_vmpa(addr); + + for (i = 0; i < count; i++) + { + operand = g_imm_operand_new_from_data2(size, data, addr, end, endian); + if (operand == NULL) goto grina_error; + + g_imm_operand_pad(G_IMM_OPERAND(operand), true); + + g_arch_instruction_attach_extra_operand(result, operand); + } + + g_arch_instruction_set_location(result, old, compute_vmpa_diff(addr, old)); + + delete_vmpa(old); + + return result; + + grina_error: + + g_object_unref(G_OBJECT(result)); + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction à traiter. * +* format = format du binaire manipulé. * +* syntax = type de représentation demandée. * +* * +* Description : Fournit le nom humain de l'instruction manipulée. * +* * +* Retour : Mot clef de bas niveau. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const char *g_raw_instruction_get_keyword(const GRawInstruction *instr, AsmSyntax syntax) +{ + GArchOperand *operand; /* Octet décodé à afficher */ + MemoryDataSize size; /* Taille de valeur associée */ + + static char *defines[] = { "dn", "db", "dw", "dd", "dq" }; + + operand = g_arch_instruction_get_operand(instr, 0); + size = g_imm_operand_get_size(G_IMM_OPERAND(operand)); + + return defines[MDS_RANGE(size)]; + +} |