From ada6b756efd6ca109f6c46aa4d3eb11c17ad6b84 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Wed, 1 Oct 2014 20:44:39 +0000 Subject: Prepared the ground for the ARMv7 architecture. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@408 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 51 +++++++++ configure.ac | 3 +- src/arch/arm/Makefile.am | 10 +- src/arch/arm/cond.h | 64 ++++++++++++ src/arch/arm/encoding.h | 70 ------------- src/arch/arm/instruction-int.h | 3 + src/arch/arm/instruction.c | 101 ++++++++++++------ src/arch/arm/instruction.h | 36 +++---- src/arch/arm/processor-int.h | 50 +++++++++ src/arch/arm/processor.c | 119 ++------------------- src/arch/arm/processor.h | 18 ++-- src/arch/arm/register-int.h | 56 ++++++++++ src/arch/arm/register.c | 204 ++++++++++++++++++++++++++++++++++++ src/arch/arm/register.h | 56 ++++++++++ src/arch/arm/v7/Makefile.am | 17 +++ src/arch/arm/v7/instruction.c | 206 ++++++++++++++++++++++++++++++++++++ src/arch/arm/v7/instruction.h | 63 ++++++++++++ src/arch/arm/v7/processor.c | 173 +++++++++++++++++++++++++++++++ src/arch/arm/v7/processor.h | 56 ++++++++++ src/arch/arm/v7/register.c | 229 +++++++++++++++++++++++++++++++++++++++++ src/arch/arm/v7/register.h | 56 ++++++++++ src/arch/dalvik/instruction.c | 2 +- src/arch/dalvik/register.c | 18 ++-- src/arch/processor.c | 2 +- src/arch/register-int.h | 18 ++-- src/arch/register.c | 14 +-- 26 files changed, 1423 insertions(+), 272 deletions(-) create mode 100644 src/arch/arm/cond.h delete mode 100644 src/arch/arm/encoding.h create mode 100644 src/arch/arm/processor-int.h create mode 100644 src/arch/arm/register-int.h create mode 100644 src/arch/arm/register.c create mode 100644 src/arch/arm/register.h create mode 100644 src/arch/arm/v7/Makefile.am create mode 100644 src/arch/arm/v7/instruction.c create mode 100644 src/arch/arm/v7/instruction.h create mode 100644 src/arch/arm/v7/processor.c create mode 100644 src/arch/arm/v7/processor.h create mode 100644 src/arch/arm/v7/register.c create mode 100644 src/arch/arm/v7/register.h diff --git a/ChangeLog b/ChangeLog index 2eb182c..700c8d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,54 @@ +14-10-01 Cyrille Bagard + + * configure.ac: + Add the new Makefile from the 'src/arch/arm/v7 directory. + + * src/arch/arm/cond.h: + New entry: define global ARM execution conditions. + + * src/arch/arm/encoding.h: + Renamed entry; see cond.h. + + * src/arch/arm/instruction.c: + * src/arch/arm/instruction.h: + * src/arch/arm/instruction-int.h: + + * src/arch/arm/Makefile.am: + Remove 'encoding.h' from libarcharm_la_SOURCES, and add the + 'register-int*[ch]' files. Update libarcharm_la_LIBADD for ARMv7 support. + + * src/arch/arm/processor.c: + * src/arch/arm/processor.h: + Update code. + + * src/arch/arm/processor-int.h: + New entry: define a generic ARM processor. + + * src/arch/arm/register.c: + * src/arch/arm/register.h: + * src/arch/arm/register-int.h: + New entries: define a generic ARM register. + + * src/arch/arm/v7/instruction.c: + * src/arch/arm/v7/instruction.h: + * src/arch/arm/v7/Makefile.am: + * src/arch/arm/v7/processor.c: + * src/arch/arm/v7/processor.h: + * src/arch/arm/v7/register.c: + * src/arch/arm/v7/register.h: + New entries: prepare the ground for the ARMv7 architecture. + + * src/arch/dalvik/instruction.c: + * src/arch/dalvik/register.c: + Typo. + + * src/arch/processor.c: + Update code. + + * src/arch/register.c: + * src/arch/register-int.h: + Move code from instances to classes. + 14-09-21 Cyrille Bagard * src/format/format.c: diff --git a/configure.ac b/configure.ac index c788e4d..3534c4f 100644 --- a/configure.ac +++ b/configure.ac @@ -305,8 +305,7 @@ AC_CONFIG_FILES([Makefile src/analysis/types/Makefile src/arch/Makefile src/arch/arm/Makefile - src/arch/arm/v456/Makefile - src/arch/arm/v456/operands/Makefile + src/arch/arm/v7/Makefile src/arch/dalvik/Makefile src/arch/dalvik/decomp/Makefile src/arch/dalvik/opcodes/Makefile diff --git a/src/arch/arm/Makefile.am b/src/arch/arm/Makefile.am index c480a47..9bf0fe9 100644 --- a/src/arch/arm/Makefile.am +++ b/src/arch/arm/Makefile.am @@ -2,13 +2,15 @@ noinst_LTLIBRARIES = libarcharm.la libarcharm_la_SOURCES = \ - encoding.h \ + cond.h \ instruction-int.h \ instruction.h instruction.c \ - processor.h processor.c + processor.h processor.c \ + register-int.h \ + register.h register.c libarcharm_la_LIBADD = \ - v456/libarcharmv456.la + v7/libarcharmv7.la libarcharm_la_CFLAGS = $(AM_CFLAGS) @@ -18,4 +20,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = v456 +SUBDIRS = v7 diff --git a/src/arch/arm/cond.h b/src/arch/arm/cond.h new file mode 100644 index 0000000..942c243 --- /dev/null +++ b/src/arch/arm/cond.h @@ -0,0 +1,64 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * encoding.h - prototypes pour le décodage des conditions d'exécution ARM + * + * Copyright (C) 2013 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 . + */ + + +#ifndef _ARCH_ARM_ENCODING_H +#define _ARCH_ARM_ENCODING_H + + + +/** + * Les conditions d'exécutions sont partagées par les architectures ARM : + * + * ARMv7 Instruction Details + * § A8.3 Conditional execution + * + * ARMv8 Instruction Set Overview. + * § 4.3 Condition Codes. + * + */ + +/* Liste des conditions possibles */ +typedef enum _ArmCondCode +{ + ACC_EQ = 0x0, /* Equal */ + ACC_NE = 0x1, /* Not equal */ + ACC_HS = 0x2, /* Unsigned higher or same */ + ACC_LO = 0x2, /* Unsigned lower */ + ACC_MI = 0x3, /* Minus */ + ACC_PL = 0x4, /* Plus or zero */ + ACC_VS = 0x5, /* Overflow set */ + ACC_VC = 0x6, /* Overflow clear */ + ACC_HI = 0x7, /* Unsigned higher */ + ACC_LS = 0x9, /* Unsigned lower or same */ + ACC_GE = 0xa, /* Signed greater than or equal*/ + ACC_LT = 0xb, /* Signed less than */ + ACC_GT = 0xc, /* Signed greater than */ + ACC_LE = 0xd, /* Signed less than or equal */ + ACC_AL = 0xe, /* Always */ + ACC_NV = 0xf, /* (Never) */ + +} ArmCondCode; + + + +#endif /* _ARCH_ARM_ENCODING_H */ diff --git a/src/arch/arm/encoding.h b/src/arch/arm/encoding.h deleted file mode 100644 index 733c6b2..0000000 --- a/src/arch/arm/encoding.h +++ /dev/null @@ -1,70 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * encoding.h - prototypes pour le décodage des instructions ARM - * - * Copyright (C) 2013 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 . - */ - - -#ifndef _ARCH_ARM_ENCODING_H -#define _ARCH_ARM_ENCODING_H - - - - - - - -/** - * ARMv8 Instruction Set Overview. - * § 4.3 Condition Codes. - */ - - -/* Liste des conditions possibles */ -typedef enum _ArmCondCode -{ - ACC_EQ = 0x0, /* Equal */ - ACC_NE = 0x1, /* Not equal */ - ACC_HS = 0x2, /* Unsigned higher or same */ - ACC_LO = 0x2, /* Unsigned lower */ - ACC_MI = 0x3, /* Minus */ - ACC_PL = 0x4, /* Plus or zero */ - ACC_VS = 0x5, /* Overflow set */ - ACC_VC = 0x6, /* Overflow clear */ - ACC_HI = 0x7, /* Unsigned higher */ - ACC_LS = 0x9, /* Unsigned lower or same */ - ACC_GE = 0xa, /* Signed greater than or equal*/ - ACC_LT = 0xb, /* Signed less than */ - ACC_GT = 0xc, /* Signed greater than */ - ACC_LE = 0xd, /* Signed less than or equal */ - ACC_AL = 0xe, /* Always */ - ACC_NV = 0xf, /* (Never) */ - -} ArmCondCode; - - - -#define INSTR_TO_COND(i) (((i) & 0xf0000000) >> 28) - - - - - - -#endif /* _ARCH_ARM_ENCODING_H */ diff --git a/src/arch/arm/instruction-int.h b/src/arch/arm/instruction-int.h index 1189045..d87bcc4 100644 --- a/src/arch/arm/instruction-int.h +++ b/src/arch/arm/instruction-int.h @@ -25,6 +25,7 @@ #define _ARCH_ARM_INSTRUCTION_INT_H +#include "instruction.h" #include "../instruction-int.h" @@ -34,6 +35,8 @@ struct _GArmInstruction { GArchInstruction parent; /* A laisser en premier */ + ArmCondCode cond; /* Condition d'exécution */ + }; /* Définition générique d'une instruction d'architecture ARM (classe) */ diff --git a/src/arch/arm/instruction.c b/src/arch/arm/instruction.c index 77dd621..5ea3926 100644 --- a/src/arch/arm/instruction.c +++ b/src/arch/arm/instruction.c @@ -28,29 +28,29 @@ - - -/* Initialise la classe des instructions pour Arm. */ +/* Initialise la classe des instructions ARM. */ static void g_arm_instruction_class_init(GArmInstructionClass *); -/* Initialise une instance d'opérande d'architecture Arm. */ +/* Initialise une instance de instruction ARM. */ static void g_arm_instruction_init(GArmInstruction *); +/* Supprime toutes les références externes. */ +static void g_arm_instruction_dispose(GArmInstruction *); +/* Procède à la libération totale de la mémoire. */ +static void g_arm_instruction_finalize(GArmInstruction *); - -/* Indique le type défini pour une instruction d'architecture Arm. */ -G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARCH_INSTRUCTION); - +/* Indique le type défini pour une représentation d'une instruction ARM. */ +G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARM_INSTRUCTION); /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * * * -* Description : Initialise la classe des instructions pour ARM. * +* Description : Initialise la classe des instructions ARM. * * * * Retour : - * * * @@ -60,6 +60,12 @@ G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARCH_INSTRUCTION); static void g_arm_instruction_class_init(GArmInstructionClass *klass) { + GObjectClass *object_class; /* Autre version de la classe */ + + object_class = G_OBJECT_CLASS(klass); + + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_arm_instruction_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_arm_instruction_finalize; } @@ -68,7 +74,7 @@ static void g_arm_instruction_class_init(GArmInstructionClass *klass) * * * Paramètres : instr = instance à initialiser. * * * -* Description : Initialise une instance d'instruction d'architecture ARM. * +* Description : Initialise une instance d'instruction ARM. * * * * Retour : - * * * @@ -78,51 +84,82 @@ static void g_arm_instruction_class_init(GArmInstructionClass *klass) static void g_arm_instruction_init(GArmInstruction *instr) { - GArchInstruction *parent; /* Instance parente */ - parent = G_ARCH_INSTRUCTION(instr); +} - /* ... TODO ! */ -} +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +static void g_arm_instruction_dispose(GArmInstruction *instr) +{ + G_OBJECT_CLASS(g_arm_instruction_parent_class)->dispose(G_OBJECT(instr)); +} -/* ---------------------------------------------------------------------------------- */ -/* AIDE A LA MISE EN PLACE D'INSTRUCTIONS */ -/* ---------------------------------------------------------------------------------- */ +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +static void g_arm_instruction_finalize(GArmInstruction *instr) +{ + G_OBJECT_CLASS(g_arm_instruction_parent_class)->finalize(G_OBJECT(instr)); +} -#if 0 /****************************************************************************** * * -* Paramètres : data = flux de données à analyser. * -* pos = position courante dans ce flux. * -* end = limite des données à analyser. * +* Paramètres : instr = instruction ARM à mettre à jour. * +* cond = condition d'exécution de l'instruction. * * * -* Description : Recherche l'identifiant de la prochaine instruction. * +* Description : Définit les conditions d'exécution d'une instruction ARM. * * * -* Retour : Identifiant de la prochaine instruction à tenter de charger. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -ArmOpcodes arm_guess_next_instruction(const bin_t *data, off_t pos, off_t end) +void g_armv7_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond) { - ArmOpcodes result; /* Identifiant à retourner */ + instr->cond = cond; - result = (ArmOpcodes)data[pos]; +} - /* Si l'instruction est marquée comme non utilisée... */ - if (_instructions[result].keyword == NULL) - result = DOP_COUNT; - return result; +/****************************************************************************** +* * +* Paramètres : instr = instruction ARM à consulter. * +* * +* Description : Indique les conditions d'exécution d'une instruction ARM. * +* * +* Retour : Condition d'exécution de l'instruction. * +* * +* Remarques : - * +* * +******************************************************************************/ -} +ArmCondCode g_armv7_instruction_get_cond(const GArmInstruction *instr) +{ + return instr->cond; -#endif +} diff --git a/src/arch/arm/instruction.h b/src/arch/arm/instruction.h index 0725726..0736015 100644 --- a/src/arch/arm/instruction.h +++ b/src/arch/arm/instruction.h @@ -25,37 +25,37 @@ #define _ARCH_ARM_INSTRUCTION_H -#include "../instruction.h" +#include +#include +#include "cond.h" -#define G_TYPE_ARM_INSTRUCTION g_arm_instruction_get_type() -#define G_ARM_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_instruction_get_type(), GArmInstruction)) -#define G_IS_ARM_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_instruction_get_type())) -#define G_ARM_INSTRUCTION_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_arm_instruction_get_type(), GArmInstructionIface)) -/* Définition générique d'une instruction d'architecture ARM (instance) */ +#define G_TYPE_ARM_INSTRUCTION g_arm_instruction_get_type() +#define G_ARM_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_instruction_get_type(), GArmInstruction)) +#define G_IS_ARM_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_instruction_get_type())) +#define G_ARM_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARM_INSTRUCTION, GArmInstructionClass)) +#define G_IS_ARM_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARM_INSTRUCTION)) +#define G_ARM_INSTRUCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARM_INSTRUCTION, GArmInstructionClass)) + + +/* Définition d'une instruction d'architecture ARM (instance) */ typedef struct _GArmInstruction GArmInstruction; -/* Définition générique d'une instruction d'architecture ARM (classe) */ +/* Définition d'une instruction d'architecture ARM (classe) */ typedef struct _GArmInstructionClass GArmInstructionClass; -/* Indique le type défini pour une instruction d'architecture ARM. */ +/* Indique le type défini pour une représentation d'une instruction ARM. */ GType g_arm_instruction_get_type(void); +/* Définit les conditions d'exécution d'une instruction ARM. */ +void g_armv7_instruction_set_cond(GArmInstruction *, ArmCondCode); - -/* --------------------- AIDE A LA MISE EN PLACE D'INSTRUCTIONS --------------------- */ - - -/* Recherche l'identifiant de la prochaine instruction. */ -//ArmOpcodes arm_guess_next_instruction(const bin_t *, off_t, off_t); - - - -/* ------------------------ AIDE A LA PHASE DE DECOMPILATION ------------------------ */ +/* Indique les conditions d'exécution d'une instruction ARM. */ +ArmCondCode g_armv7_instruction_get_cond(const GArmInstruction *); diff --git a/src/arch/arm/processor-int.h b/src/arch/arm/processor-int.h new file mode 100644 index 0000000..48f8151 --- /dev/null +++ b/src/arch/arm/processor-int.h @@ -0,0 +1,50 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction-int.h - prototypes pour la définition générique interne des processeurs ARM + * + * Copyright (C) 2014 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 . + */ + + +#ifndef _ARCH_ARM_PROCESSOR_INT_H +#define _ARCH_ARM_PROCESSOR_INT_H + + +#include "processor.h" +#include "../processor-int.h" + + + +/* Définition du processeur ARM (instance) */ +struct _GArmProcessor +{ + GArchProcessor parent; /* Instance parente */ + +}; + + +/* Définition du processeur ARM (classe) */ +struct _GArmProcessorClass +{ + GArchProcessorClass parent; /* Classe parente */ + +}; + + + +#endif /* _ARCH_ARM_PROCESSOR_INT_H */ diff --git a/src/arch/arm/processor.c b/src/arch/arm/processor.c index 4bd342f..2c676be 100644 --- a/src/arch/arm/processor.c +++ b/src/arch/arm/processor.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * processor.c - manipulation du processeur ARM * - * Copyright (C) 2010-2013 Cyrille Bagard + * Copyright (C) 2014 Cyrille Bagard * * This file is part of Chrysalide. * @@ -24,32 +24,14 @@ #include "processor.h" -//#include "instruction.h" -//#include "opcodes.h" -#include "../processor-int.h" +#include "processor-int.h" -/* Définition du processeur ARM (instance) */ -struct _GArmProcessor -{ - GArchProcessor parent; /* Instance parente */ - -}; - - -/* Définition du processeur ARM (classe) */ -struct _GArmProcessorClass -{ - GArchProcessorClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des processeurs ARM. */ +/* Initialise la classe des registres ARM. */ static void g_arm_processor_class_init(GArmProcessorClass *); -/* Initialise une instance de processeur ARM. */ +/* Initialise une instance de registre ARM. */ static void g_arm_processor_init(GArmProcessor *); /* Supprime toutes les références externes. */ @@ -58,15 +40,12 @@ static void g_arm_processor_dispose(GArmProcessor *); /* Procède à la libération totale de la mémoire. */ static void g_arm_processor_finalize(GArmProcessor *); -/* Décode une instruction dans un flux de données. */ -static GArchInstruction *g_arm_processor_decode_instruction(const GArmProcessor *, GProcContext *, const bin_t *, off_t *, off_t, vmpa_t, GBinFormat *); /* Indique le type défini par la GLib pour le processeur ARM. */ G_DEFINE_TYPE(GArmProcessor, g_arm_processor, G_TYPE_ARCH_PROCESSOR); - /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * @@ -81,17 +60,12 @@ G_DEFINE_TYPE(GArmProcessor, g_arm_processor, G_TYPE_ARCH_PROCESSOR); static void g_arm_processor_class_init(GArmProcessorClass *klass) { - GObjectClass *object; /* Autre version de la classe */ - GArchProcessorClass *proc; /* Encore une autre vision... */ - - object = G_OBJECT_CLASS(klass); - - object->dispose = (GObjectFinalizeFunc/* ! */)g_arm_processor_dispose; - object->finalize = (GObjectFinalizeFunc)g_arm_processor_finalize; + GObjectClass *object_class; /* Autre version de la classe */ - proc = G_ARCH_PROCESSOR_CLASS(klass); + object_class = G_OBJECT_CLASS(klass); - proc->decode = (decode_instruction_fc)g_arm_processor_decode_instruction; + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_arm_processor_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_arm_processor_finalize; } @@ -110,13 +84,6 @@ static void g_arm_processor_class_init(GArmProcessorClass *klass) static void g_arm_processor_init(GArmProcessor *proc) { - GArchProcessor *parent; /* Instance parente */ - - parent = G_ARCH_PROCESSOR(proc); - - parent->endianness = SRE_LITTLE; - parent->memsize = MDS_32_BITS; - parent->inssize = MDS_32_BITS; } @@ -142,7 +109,7 @@ static void g_arm_processor_dispose(GArmProcessor *proc) /****************************************************************************** * * -* Paramètres : bookmark = instance d'objet GLib à traiter. * +* Paramètres : proc = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * @@ -157,71 +124,3 @@ static void g_arm_processor_finalize(GArmProcessor *proc) G_OBJECT_CLASS(g_arm_processor_parent_class)->finalize(G_OBJECT(proc)); } - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Crée le support de l'architecture ARM. * -* * -* Retour : Architecture mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchProcessor *g_arm_processor_new(void) -{ - GArchProcessor *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_ARM_PROCESSOR, NULL); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : proc = architecture visée par la procédure. * -* ctx = contexte lié à l'exécution du processeur. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* addr = adresse virtuelle de l'instruction. * -* format = format du fichier contenant le code. * -* * -* Description : Décode une instruction dans un flux de données. * -* * -* Retour : Instruction mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ -#include "encoding.h" -extern GArchInstruction *try_to_decode_arm_v456_instr(bin_t *); - -static GArchInstruction *g_arm_processor_decode_instruction(const GArmProcessor *proc, GProcContext *ctx, const bin_t *data, off_t *pos, off_t end, vmpa_t addr, GBinFormat *format) -{ - GArchInstruction *result; /* Instruction à renvoyer */ - - - uint32_t *instr; - - if (data == NULL) - return NULL; - - - instr = (uint32_t *)(data + *pos); - - - //printf("[0x%08x] cond=%x\n", *instr, INSTR_TO_COND(*instr)); - - result = try_to_decode_arm_v456_instr(data + *pos); - - if (result != NULL) *pos += 4; - - return result; - -} diff --git a/src/arch/arm/processor.h b/src/arch/arm/processor.h index d98306c..425652d 100644 --- a/src/arch/arm/processor.h +++ b/src/arch/arm/processor.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * processor.h - prototypes pour la manipulation du processeur ARM * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2014 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,14 +25,17 @@ #define _ARCH_ARM_PROCESSOR_H -#include "../processor.h" +#include +#include -#define G_TYPE_ARM_PROCESSOR g_arm_processor_get_type() -#define G_ARM_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_processor_get_type(), GArmProcessor)) -#define G_IS_ARM_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_processor_get_type())) -#define G_ARM_PROCESSOR_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_arm_processor_get_type(), GArmProcessorIface)) +#define G_TYPE_ARM_PROCESSOR g_arm_processor_get_type() +#define G_ARM_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_processor_get_type(), GArmProcessor)) +#define G_IS_ARM_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_processor_get_type())) +#define G_ARM_PROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARM_PROCESSOR, GArmProcessorClass)) +#define G_IS_ARM_PROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARM_PROCESSOR)) +#define G_ARM_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARM_PROCESSOR, GArmProcessorClass)) /* Définition du processeur ARM (instance) */ @@ -45,9 +48,6 @@ typedef struct _GArmProcessorClass GArmProcessorClass; /* Indique le type défini par la GLib pour le processeur ARM. */ GType g_arm_processor_get_type(void); -/* Crée le support de l'architecture ARM. */ -GArchProcessor *g_arm_processor_new(void); - #endif /* _ARCH_ARM_PROCESSOR_H */ diff --git a/src/arch/arm/register-int.h b/src/arch/arm/register-int.h new file mode 100644 index 0000000..4ea0bc9 --- /dev/null +++ b/src/arch/arm/register-int.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * register-int.h - définitions internes pour la représentation d'un registre ARM + * + * Copyright (C) 2012-2013 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 . + */ + + +#ifndef _ARCH_ARM_REGISTER_INT_H +#define _ARCH_ARM_REGISTER_INT_H + + + +#include "register.h" +#include "../register-int.h" + + + +#define MAX_REGNAME_LEN 8 + + +/* Représentation d'un registre ARM (instance) */ +struct _GArmRegister +{ + GArchRegister parent; /* A laisser en premier */ + + uint8_t index; /* Indice du registre */ + +}; + + +/* Représentation d'un registre ARM (classe) */ +struct _GArmRegisterClass +{ + GArchRegisterClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _ARCH_ARM_REGISTER_INT_H */ diff --git a/src/arch/arm/register.c b/src/arch/arm/register.c new file mode 100644 index 0000000..dd287ca --- /dev/null +++ b/src/arch/arm/register.c @@ -0,0 +1,204 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * registers.c - aides auxiliaires relatives aux registres ARM + * + * Copyright (C) 2010-2013 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 . + */ + + +#include "register.h" + + +#include "register-int.h" + + + +/* Initialise la classe des registres ARM. */ +static void g_arm_register_class_init(GArmRegisterClass *); + +/* Initialise une instance de registre ARM. */ +static void g_arm_register_init(GArmRegister *); + +/* Supprime toutes les références externes. */ +static void g_arm_register_dispose(GArmRegister *); + +/* Procède à la libération totale de la mémoire. */ +static void g_arm_register_finalize(GArmRegister *); + +/* Produit une empreinte à partir d'un registre. */ +static guint g_arm_register_hash(const GArmRegister *); + +/* Compare un registre avec un autre. */ +static int g_arm_register_compare(const GArmRegister *, const GArmRegister *); + + + +/* Indique le type défini pour une représentation d'un registre ARM. */ +G_DEFINE_TYPE(GArmRegister, g_arm_register, G_TYPE_ARCH_REGISTER); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des registres Arm. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arm_register_class_init(GArmRegisterClass *klass) +{ + GObjectClass *object_class; /* Autre version de la classe */ + GArchRegisterClass *register_class; /* Classe de haut niveau */ + + object_class = G_OBJECT_CLASS(klass); + register_class = G_ARCH_REGISTER_CLASS(klass); + + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_arm_register_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_arm_register_finalize; + + register_class->hash = (reg_hash_fc)g_arm_register_hash; + register_class->compare = (reg_compare_fc)g_arm_register_compare; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance à initialiser. * +* * +* Description : Initialise une instance de registre ARM. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arm_register_init(GArmRegister *reg) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arm_register_dispose(GArmRegister *reg) +{ + G_OBJECT_CLASS(g_arm_register_parent_class)->dispose(G_OBJECT(reg)); + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arm_register_finalize(GArmRegister *reg) +{ + G_OBJECT_CLASS(g_arm_register_parent_class)->finalize(G_OBJECT(reg)); + +} + + +/****************************************************************************** +* * +* Paramètres : reg = registre à consulter. * +* * +* Description : Fournit l'indice d'un registre ARM. * +* * +* Retour : Inditifiant représentant le registre. * +* * +* Remarques : - * +* * +******************************************************************************/ + +uint8_t g_arm_register_get_index(const GArmRegister *reg) +{ + return reg->index; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = opérande à consulter pour le calcul. * +* * +* Description : Produit une empreinte à partir d'un registre. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static guint g_arm_register_hash(const GArmRegister *reg) +{ + return reg->index; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un registre avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_arm_register_compare(const GArmRegister *a, const GArmRegister *b) +{ + int result; /* Bilan à retourner */ + + if (a->index < b->index) + result = -1; + else if (a->index > b->index) + result = 1; + else + result = 0; + + return result; + +} diff --git a/src/arch/arm/register.h b/src/arch/arm/register.h new file mode 100644 index 0000000..0c24d21 --- /dev/null +++ b/src/arch/arm/register.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * registers.h - prototypes pour les aides auxiliaires relatives aux registres ARM + * + * Copyright (C) 2010-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 . + */ + + +#ifndef _ARCH_ARM_REGISTER_H +#define _ARCH_ARM_REGISTER_H + + +#include +#include + + + +#define G_TYPE_ARM_REGISTER g_arm_register_get_type() +#define G_ARM_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_register_get_type(), GArmRegister)) +#define G_IS_ARM_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_register_get_type())) +#define G_ARM_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARM_REGISTER, GArmRegisterClass)) +#define G_IS_ARM_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARM_REGISTER)) +#define G_ARM_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARM_REGISTER, GArmRegisterClass)) + + +/* Représentation d'un registre ARM (instance) */ +typedef struct _GArmRegister GArmRegister; + +/* Représentation d'un registre ARM (classe) */ +typedef struct _GArmRegisterClass GArmRegisterClass; + + +/* Indique le type défini pour une représentation d'un registre ARM. */ +GType g_arm_register_get_type(void); + +/* Fournit l'indice d'un registre ARM. */ +uint8_t g_arm_register_get_index(const GArmRegister *); + + + +#endif /* _ARCH_ARM_REGISTER_H */ diff --git a/src/arch/arm/v7/Makefile.am b/src/arch/arm/v7/Makefile.am new file mode 100644 index 0000000..1ac1c76 --- /dev/null +++ b/src/arch/arm/v7/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libarcharmv7.la + +libarcharmv7_la_SOURCES = \ + instruction.h instruction.c \ + processor.h processor.c \ + register.h register.c + +libarcharmv7_la_CFLAGS = $(AM_CFLAGS) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + + +SUBDIRS = #opdefs diff --git a/src/arch/arm/v7/instruction.c b/src/arch/arm/v7/instruction.c new file mode 100644 index 0000000..0fc95c9 --- /dev/null +++ b/src/arch/arm/v7/instruction.c @@ -0,0 +1,206 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.c - gestion des instructions ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#include "instruction.h" + + +#include "../instruction-int.h" + + + +/* Définition d'une instruction d'architecture ARMv7 (instance) */ +struct _GArmV7Instruction +{ + GArmInstruction parent; /* Instance parente */ + + bool setflags; /* Mise à jour des drapeaux */ + +}; + + +/* Définition d'une instruction d'architecture ARMv7 (classe) */ +struct _GArmV7InstructionClass +{ + GArmInstructionClass parent; /* Classe parente */ + +}; + + +/* Initialise la classe des instructions ARMv7. */ +static void g_armv7_instruction_class_init(GArmV7InstructionClass *); + +/* Initialise une instance d'instruction ARMv7. */ +static void g_armv7_instruction_init(GArmV7Instruction *); + +/* Supprime toutes les références externes. */ +static void g_armv7_instruction_dispose(GArmV7Instruction *); + +/* Procède à la libération totale de la mémoire. */ +static void g_armv7_instruction_finalize(GArmV7Instruction *); + + + +/* Indique le type défini pour une représentation d'une instruction ARMv7. */ +G_DEFINE_TYPE(GArmV7Instruction, g_armv7_instruction, G_TYPE_ARM_INSTRUCTION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des instructions ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_instruction_class_init(GArmV7InstructionClass *klass) +{ + GObjectClass *object_class; /* Autre version de la classe */ + + object_class = G_OBJECT_CLASS(klass); + + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_instruction_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_armv7_instruction_finalize; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance à initialiser. * +* * +* Description : Initialise une instance d'instruction ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_instruction_init(GArmV7Instruction *instr) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_instruction_dispose(GArmV7Instruction *instr) +{ + G_OBJECT_CLASS(g_armv7_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_armv7_instruction_finalize(GArmV7Instruction *instr) +{ + G_OBJECT_CLASS(g_armv7_instruction_parent_class)->finalize(G_OBJECT(instr)); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée une instruction pour l'architecture ARMv7. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArmV7Instruction *g_armv7_instruction_new(void) +{ + GArmV7Instruction *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_ARMV7_INSTRUCTION, NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction ARMv7 à mettre à jour. * +* set = statut à enregistrer. * +* * +* Description : Définit si une instruction ARMv7 met à jour les drapeaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_armv7_instruction_define_setflags(GArmV7Instruction *instr, bool set) +{ + instr->setflags = set; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction ARMv7 à consulter. * +* * +* Description : Indique si une instruction ARMv7 met à jour les drapeaux. * +* * +* Retour : Statut des incidences de l'instruction. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_armv7_instruction_get_setflags(const GArmV7Instruction *instr) +{ + return instr->setflags; + +} diff --git a/src/arch/arm/v7/instruction.h b/src/arch/arm/v7/instruction.h new file mode 100644 index 0000000..0265911 --- /dev/null +++ b/src/arch/arm/v7/instruction.h @@ -0,0 +1,63 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.h - prototypes pour la gestion des instructions ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#ifndef _ARCH_ARM_V7_INSTRUCTION_H +#define _ARCH_ARM_V7_INSTRUCTION_H + + +#include +#include +#include + + + +#define G_TYPE_ARMV7_INSTRUCTION g_armv7_instruction_get_type() +#define G_ARMV7_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_instruction_get_type(), GArmV7Instruction)) +#define G_IS_ARMV7_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_instruction_get_type())) +#define G_ARMV7_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARMV7_INSTRUCTION, GArmV7InstructionClass)) +#define G_IS_ARMV7_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARMV7_INSTRUCTION)) +#define G_ARMV7_INSTRUCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARMV7_INSTRUCTION, GArmV7InstructionClass)) + + +/* Définition d'une instruction d'architecture ARMv7 (instance) */ +typedef struct _GArmV7Instruction GArmV7Instruction; + +/* Définition d'une instruction d'architecture ARMv7 (classe) */ +typedef struct _GArmV7InstructionClass GArmV7InstructionClass; + + +/* Indique le type défini pour une représentation d'une instruction ARMv7. */ +GType g_armv7_instruction_get_type(void); + +/* Crée une instruction pour l'architecture ARMv7. */ +GArmV7Instruction *g_armv7_instruction_new(void); + +/* Définit si une instruction ARMv7 met à jour les drapeaux. */ +void g_armv7_instruction_define_setflags(GArmV7Instruction *, bool); + +/* Indique si une instruction ARMv7 met à jour les drapeaux. */ +bool g_armv7_instruction_get_setflags(const GArmV7Instruction *); + + + +#endif /* _ARCH_ARM_V7_INSTRUCTION_H */ diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c new file mode 100644 index 0000000..bcd44e9 --- /dev/null +++ b/src/arch/arm/v7/processor.c @@ -0,0 +1,173 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.c - manipulation du processeur ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#include "processor.h" + + +#include "../processor-int.h" + + + +/* Définition du processeur ARMv7 (instance) */ +struct _GArmV7Processor +{ + GArmProcessor parent; /* Instance parente */ + +}; + + +/* Définition du processeur ARMv7 (classe) */ +struct _GArmV7ProcessorClass +{ + GArmProcessorClass parent; /* Classe parente */ + +}; + + +/* Initialise la classe des registres ARMv7. */ +static void g_armv7_processor_class_init(GArmV7ProcessorClass *); + +/* Initialise une instance de registre ARMv7. */ +static void g_armv7_processor_init(GArmV7Processor *); + +/* Supprime toutes les références externes. */ +static void g_armv7_processor_dispose(GArmV7Processor *); + +/* Procède à la libération totale de la mémoire. */ +static void g_armv7_processor_finalize(GArmV7Processor *); + + + +/* Indique le type défini par la GLib pour le processeur ARMv7. */ +G_DEFINE_TYPE(GArmV7Processor, g_armv7_processor, G_TYPE_ARM_PROCESSOR); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des processeurs ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_processor_class_init(GArmV7ProcessorClass *klass) +{ + GObjectClass *object_class; /* Autre version de la classe */ + + object_class = G_OBJECT_CLASS(klass); + + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_processor_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_armv7_processor_finalize; + +} + + +/****************************************************************************** +* * +* Paramètres : proc = instance à initialiser. * +* * +* Description : Initialise une instance de processeur ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_processor_init(GArmV7Processor *proc) +{ + + GArchProcessor *parent; /* Instance parente */ + + parent = G_ARCH_PROCESSOR(proc); + + parent->endianness = SRE_LITTLE; + parent->memsize = MDS_32_BITS; + parent->inssize = MDS_32_BITS; + +} + + +/****************************************************************************** +* * +* Paramètres : proc = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_processor_dispose(GArmV7Processor *proc) +{ + G_OBJECT_CLASS(g_armv7_processor_parent_class)->dispose(G_OBJECT(proc)); + +} + + +/****************************************************************************** +* * +* Paramètres : proc = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_processor_finalize(GArmV7Processor *proc) +{ + G_OBJECT_CLASS(g_armv7_processor_parent_class)->finalize(G_OBJECT(proc)); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée le support de l'architecture ARMv7. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArmV7Processor *g_armv7_processor_new(void) +{ + GArmV7Processor *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_ARMV7_PROCESSOR, NULL); + + return result; + +} diff --git a/src/arch/arm/v7/processor.h b/src/arch/arm/v7/processor.h new file mode 100644 index 0000000..0361c55 --- /dev/null +++ b/src/arch/arm/v7/processor.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.h - prototypes pour la manipulation du processeur ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#ifndef _ARCH_ARM_V7_PROCESSOR_H +#define _ARCH_ARM_V7_PROCESSOR_H + + +#include +#include + + + +#define G_TYPE_ARMV7_PROCESSOR g_armv7_processor_get_type() +#define G_ARMV7_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_processor_get_type(), GArmV7Processor)) +#define G_IS_ARMV7_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_processor_get_type())) +#define G_ARMV7_PROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARMV7_PROCESSOR, GArmV7ProcessorClass)) +#define G_IS_ARMV7_PROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARMV7_PROCESSOR)) +#define G_ARMV7_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARMV7_PROCESSOR, GArmV7ProcessorClass)) + + +/* Définition du processeur ARMv7 (instance) */ +typedef struct _GArmV7Processor GArmV7Processor; + +/* Définition du processeur ARMv7 (classe) */ +typedef struct _GArmV7ProcessorClass GArmV7ProcessorClass; + + +/* Indique le type défini par la GLib pour le processeur ARMv7. */ +GType g_armv7_processor_get_type(void); + +/* Crée le support de l'architecture ARMv7. */ +GArmV7Processor *g_armv7_processor_new(void); + + + +#endif /* _ARCH_ARM_V7_PROCESSOR_H */ diff --git a/src/arch/arm/v7/register.c b/src/arch/arm/v7/register.c new file mode 100644 index 0000000..f9bb731 --- /dev/null +++ b/src/arch/arm/v7/register.c @@ -0,0 +1,229 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * registers.c - aides auxiliaires relatives aux registres ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#include "register.h" + + +#include + + +#include "../register-int.h" + + + +/* Représentation d'un registre ARMv7 (instance) */ +struct _GArmV7Register +{ + GArmRegister parent; /* Instance parente */ + +}; + + +/* Représentation d'un registre ARMv7 (classe) */ +struct _GArmV7RegisterClass +{ + GArmRegisterClass parent; /* Classe parente */ + +}; + + +#define MAX_REGNAME_LEN 8 + + +/* Initialise la classe des registres ARMv7. */ +static void g_armv7_register_class_init(GArmV7RegisterClass *); + +/* Initialise une instance de registre ARMv7. */ +static void g_armv7_register_init(GArmV7Register *); + +/* Supprime toutes les références externes. */ +static void g_armv7_register_dispose(GArmV7Register *); + +/* Procède à la libération totale de la mémoire. */ +static void g_armv7_register_finalize(GArmV7Register *); + +/* Traduit un registre en version humainement lisible. */ +static void g_armv7_register_print(const GArmV7Register *, GBufferLine *, AsmSyntax); + + + +/* Indique le type défini pour une représentation d'un registre ARMv7. */ +G_DEFINE_TYPE(GArmV7Register, g_armv7_register, G_TYPE_ARM_REGISTER); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des registres ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_register_class_init(GArmV7RegisterClass *klass) +{ + GObjectClass *object_class; /* Autre version de la classe */ + GArchRegisterClass *reg_class; /* Classe de haut niveau */ + + object_class = G_OBJECT_CLASS(klass); + reg_class = G_ARCH_REGISTER_CLASS(klass); + + object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_register_dispose; + object_class->finalize = (GObjectFinalizeFunc)g_armv7_register_finalize; + + reg_class->print = (reg_print_fc)g_armv7_register_print; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance à initialiser. * +* * +* Description : Initialise une instance de registre ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_register_init(GArmV7Register *reg) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_register_dispose(GArmV7Register *reg) +{ + G_OBJECT_CLASS(g_armv7_register_parent_class)->dispose(G_OBJECT(reg)); + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_register_finalize(GArmV7Register *reg) +{ + G_OBJECT_CLASS(g_armv7_register_parent_class)->finalize(G_OBJECT(reg)); + +} + + +/****************************************************************************** +* * +* Paramètres : index = indice du registre correspondant. * +* * +* Description : Crée une réprésentation de registre ARMv7. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArmV7Register *g_armv7_register_new(uint8_t index) +{ + GArmV7Register *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_ARMV7_REGISTER, NULL); + + G_ARM_REGISTER(result)->index = index; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = registre à transcrire. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un registre en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_register_print(const GArmV7Register *reg, GBufferLine *line, AsmSyntax syntax) +{ + char key[MAX_REGNAME_LEN]; /* Mot clef principal */ + size_t klen; /* Taille de ce mot clef */ + + switch (G_ARM_REGISTER(reg)->index) + { + case 0 ... 12: + klen = snprintf(key, MAX_REGNAME_LEN, "r%hhu", G_ARM_REGISTER(reg)->index); + break; + case 13: + klen = snprintf(key, MAX_REGNAME_LEN, "sp"); + break; + case 14: + klen = snprintf(key, MAX_REGNAME_LEN, "lr"); + break; + case 15: + klen = snprintf(key, MAX_REGNAME_LEN, "pc"); + break; + case 16: + klen = snprintf(key, MAX_REGNAME_LEN, "cpsr"); + break; + case 17: + klen = snprintf(key, MAX_REGNAME_LEN, "spsr"); + break; + default: + klen = snprintf(key, MAX_REGNAME_LEN, "r??"); + break; + } + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER); + +} diff --git a/src/arch/arm/v7/register.h b/src/arch/arm/v7/register.h new file mode 100644 index 0000000..ab71995 --- /dev/null +++ b/src/arch/arm/v7/register.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * registers.h - prototypes pour les aides auxiliaires relatives aux registres ARMv7 + * + * Copyright (C) 2014 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 . + */ + + +#ifndef _ARCH_ARM_V7_REGISTER_H +#define _ARCH_ARM_V7_REGISTER_H + + +#include +#include + + + +#define G_TYPE_ARMV7_REGISTER g_armv7_register_get_type() +#define G_ARMV7_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_register_get_type(), GArmV7Register)) +#define G_IS_ARMV7_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_register_get_type())) +#define G_ARMV7_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARMV7_REGISTER, GArmV7RegisterClass)) +#define G_IS_ARMV7_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARMV7_REGISTER)) +#define G_ARMV7_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARMV7_REGISTER, GArmV7RegisterClass)) + + +/* Représentation d'un registre ARMv7 (instance) */ +typedef struct _GArmV7Register GArmV7Register; + +/* Représentation d'un registre ARMv7 (classe) */ +typedef struct _GArmV7RegisterClass GArmV7RegisterClass; + + +/* Indique le type défini pour une représentation d'un registre ARMv7. */ +GType g_armv7_register_get_type(void); + +/* Crée une réprésentation de registre ARMv7. */ +GArmV7Register *g_armv7_register_new(uint8_t); + + + +#endif /* _ARCH_ARM_V7_REGISTER_H */ diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c index c0c6675..e02619c 100644 --- a/src/arch/dalvik/instruction.c +++ b/src/arch/dalvik/instruction.c @@ -445,7 +445,7 @@ static void g_dalvik_instruction_finalize(GDalvikInstruction *instr) * * * Description : Crée une instruction pour l'architecture Dalvik. * * * -* Retour : Architecture mise en place. * +* Retour : Adresse de la structure mise en place. * * * * Remarques : - * * * diff --git a/src/arch/dalvik/register.c b/src/arch/dalvik/register.c index e0165b4..7c0b601 100644 --- a/src/arch/dalvik/register.c +++ b/src/arch/dalvik/register.c @@ -81,6 +81,13 @@ G_DEFINE_TYPE(GDalvikRegister, g_dalvik_register, G_TYPE_ARCH_REGISTER); static void g_dalvik_register_class_init(GDalvikRegisterClass *klass) { + GArchRegisterClass *register_class; /* Classe de haut niveau */ + + register_class = G_ARCH_REGISTER_CLASS(klass); + + register_class->hash = (reg_hash_fc)g_dalvik_register_hash; + register_class->compare = (reg_compare_fc)g_dalvik_register_compare; + register_class->print = (reg_print_fc)g_dalvik_register_print; } @@ -99,13 +106,6 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *klass) static void g_dalvik_register_init(GDalvikRegister *reg) { - GArchRegister *base; /* Version basique */ - - base = G_ARCH_REGISTER(reg); - - base->hash = (reg_hash_fc)g_dalvik_register_hash; - base->compare = (reg_compare_fc)g_dalvik_register_compare; - base->print = (reg_print_fc)g_dalvik_register_print; } @@ -224,11 +224,11 @@ void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *line, AsmS switch (syntax) { case ASX_INTEL: - klen = snprintf(key, MAX_REGNAME_LEN, "v%hd", reg->index); + klen = snprintf(key, MAX_REGNAME_LEN, "v%hu", reg->index); break; case ASX_ATT: - klen = snprintf(key, MAX_REGNAME_LEN, "%%v%hd", reg->index); + klen = snprintf(key, MAX_REGNAME_LEN, "%%v%hu", reg->index); break; default: diff --git a/src/arch/processor.c b/src/arch/processor.c index 48d0924..67457d2 100644 --- a/src/arch/processor.c +++ b/src/arch/processor.c @@ -294,7 +294,7 @@ GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *proc bool init_all_processors(void) { - _processors_list[APT_ARM] = g_arm_processor_new(); + _processors_list[APT_ARM] = g_armv7_processor_new(); _processors_list[APT_DALVIK] = g_dalvik_processor_new(); _processors_list[APT_JVM] = g_jvm_processor_new(); _processors_list[APT_MIPS] = g_mips_processor_new(); diff --git a/src/arch/register-int.h b/src/arch/register-int.h index 75f0ce3..fe9db8c 100644 --- a/src/arch/register-int.h +++ b/src/arch/register-int.h @@ -21,8 +21,8 @@ */ -#ifndef _ARCH_ARCH_REGISTER_INT_H -#define _ARCH_ARCH_REGISTER_INT_H +#ifndef _ARCH_REGISTER_INT_H +#define _ARCH_REGISTER_INT_H #include "register.h" @@ -51,12 +51,6 @@ struct _GArchRegister { GObject parent; /* A laisser en premier */ - reg_hash_fc hash; /* Production d'empreinte */ - reg_compare_fc compare; /* Comparaison de registres */ - reg_print_fc print; /* Impression du registre */ - reg_is_base_pointer_fc is_bp; /* Correspondance avec ebp */ - reg_is_stack_pointer_fc is_sp; /* Correspondance avec esp */ - }; @@ -65,8 +59,14 @@ struct _GArchRegisterClass { GObjectClass parent; /* A laisser en premier */ + reg_hash_fc hash; /* Production d'empreinte */ + reg_compare_fc compare; /* Comparaison de registres */ + reg_print_fc print; /* Impression du registre */ + reg_is_base_pointer_fc is_bp; /* Correspondance avec ebp */ + reg_is_stack_pointer_fc is_sp; /* Correspondance avec esp */ + }; -#endif /* _ARCH_ARCH_REGISTER_INT_H */ +#endif /* _ARCH_REGISTER_INT_H */ diff --git a/src/arch/register.c b/src/arch/register.c index 2674c48..389e71a 100644 --- a/src/arch/register.c +++ b/src/arch/register.c @@ -90,7 +90,7 @@ static void g_arch_register_init(GArchRegister *reg) guint g_arch_register_hash(const GArchRegister *reg) { - return reg->hash(reg); + return G_ARCH_REGISTER_GET_CLASS(reg)->hash(reg); } @@ -110,7 +110,7 @@ guint g_arch_register_hash(const GArchRegister *reg) int g_arch_register_compare(const GArchRegister *a, const GArchRegister *b) { - return a->compare(a, b); + return G_ARCH_REGISTER_GET_CLASS(a)->compare(a, b); } @@ -155,7 +155,7 @@ gboolean g_arch_register_equal(const GArchRegister *a, const GArchRegister *b) void g_arch_register_print(const GArchRegister *reg, GBufferLine *line, AsmSyntax syntax) { - reg->print(reg, line, syntax); + G_ARCH_REGISTER_GET_CLASS(reg)->print(reg, line, syntax); } @@ -176,8 +176,8 @@ bool g_arch_register_is_base_pointer(const GArchRegister *reg) { bool result; /* Bilan à renvoyer */ - if (reg->is_bp) - result = reg->is_bp(reg); + if (G_ARCH_REGISTER_GET_CLASS(reg)->is_bp != NULL) + result = G_ARCH_REGISTER_GET_CLASS(reg)->is_bp(reg); else result = false; @@ -202,8 +202,8 @@ bool g_arch_register_is_stack_pointer(const GArchRegister *reg) { bool result; /* Bilan à renvoyer */ - if (reg->is_sp) - result = reg->is_sp(reg); + if (G_ARCH_REGISTER_GET_CLASS(reg)->is_sp != NULL) + result = G_ARCH_REGISTER_GET_CLASS(reg)->is_sp(reg); else result = false; -- cgit v0.11.2-87-g4458