diff options
Diffstat (limited to 'src/arch/instructions')
-rw-r--r-- | src/arch/instructions/Makefile.am | 18 | ||||
-rw-r--r-- | src/arch/instructions/raw.c | 64 | ||||
-rw-r--r-- | src/arch/instructions/undefined-int.h | 58 | ||||
-rw-r--r-- | src/arch/instructions/undefined.c | 136 |
4 files changed, 193 insertions, 83 deletions
diff --git a/src/arch/instructions/Makefile.am b/src/arch/instructions/Makefile.am index 24d3eb5..28cf90f 100644 --- a/src/arch/instructions/Makefile.am +++ b/src/arch/instructions/Makefile.am @@ -1,24 +1,14 @@ noinst_LTLIBRARIES = libarchinstructions.la -libarchinstructions_la_SOURCES = \ - raw.h raw.c \ - undefined-int.h \ +libarchinstructions_la_SOURCES = \ + raw.h raw.c \ + undefined-int.h \ undefined.h undefined.c -libarchinstructions_la_LIBADD = - -libarchinstructions_la_LDFLAGS = +libarchinstructions_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libarchinstructions_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - - -SUBDIRS = diff --git a/src/arch/instructions/raw.c b/src/arch/instructions/raw.c index 481dd1c..26282fa 100644 --- a/src/arch/instructions/raw.c +++ b/src/arch/instructions/raw.c @@ -35,7 +35,7 @@ #include "../instruction-int.h" #include "../operands/immediate.h" #include "../operands/target.h" -#include "../../gtkext/gtkblockdisplay.h" +#include "../../core/columns.h" @@ -213,17 +213,17 @@ static void g_raw_instruction_finalize(GRawInstruction *instr) GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDataSize size, uint64_t value) { GArchInstruction *result; /* Instruction à retourner */ - GImmOperand *operand; /* Octet non décodé à afficher */ + GArchOperand *operand; /* Octet non décodé à afficher */ mrange_t range; /* Couverture de l'instruction */ result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL); - operand = G_IMM_OPERAND(g_imm_operand_new_from_value(size, value)); - if (operand == NULL) goto grinfv_error; + operand = g_imm_operand_new_from_value(size, value); + if (operand == NULL) goto error; - g_imm_operand_pad(operand, true); + g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING); - g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); + g_arch_instruction_attach_extra_operand(result, operand); switch (size) { @@ -249,7 +249,7 @@ GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDat default: assert(false); - goto grinfv_error; + goto error; break; } @@ -258,7 +258,7 @@ GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDat return result; - grinfv_error: + error: g_object_unref(G_OBJECT(result)); @@ -287,13 +287,15 @@ GArchInstruction *g_raw_instruction_new_uleb128(const GBinContent *content, vmpa uleb128_t value; /* Valeur uleb128 à représenter*/ phys_t diff; /* Couverture de la lecture */ MemoryDataSize leb_size; /* Taille de la valeur */ - GImmOperand *operand; /* Octet non décodé à afficher */ + GArchOperand *operand; /* Octet non décodé à afficher */ mrange_t range; /* Couverture de l'instruction */ + result = NULL; + copy_vmpa(&start, addr); if (!g_binary_content_read_uleb128(content, addr, &value)) - goto grinu_error; + goto error; diff = compute_vmpa_diff(&start, addr); @@ -305,16 +307,18 @@ GArchInstruction *g_raw_instruction_new_uleb128(const GBinContent *content, vmpa init_mrange(&range, &start, diff); g_arch_instruction_set_range(result, &range); - operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value)); - if (operand == NULL) goto grinu_error; + operand = g_imm_operand_new_from_value(leb_size, (uint64_t)value); + if (operand == NULL) goto error; - g_imm_operand_pad(operand, true); + g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING); - g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); + g_arch_instruction_attach_extra_operand(result, operand); return result; - grinu_error: + error: + + g_clear_object(&result); return NULL; @@ -341,13 +345,15 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa uleb128_t value; /* Valeur uleb128 à représenter*/ phys_t diff; /* Couverture de la lecture */ MemoryDataSize leb_size; /* Taille de la valeur */ - GImmOperand *operand; /* Octet non décodé à afficher */ + GArchOperand *operand; /* Octet non décodé à afficher */ mrange_t range; /* Couverture de l'instruction */ + result = NULL; + copy_vmpa(&start, addr); if (!g_binary_content_read_uleb128(content, addr, &value)) - goto grins_error; + goto error; diff = compute_vmpa_diff(&start, addr); @@ -359,16 +365,18 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa init_mrange(&range, &start, diff); g_arch_instruction_set_range(result, &range); - operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value)); - if (operand == NULL) goto grins_error; + operand = g_imm_operand_new_from_value(leb_size, (uint64_t)value); + if (operand == NULL) goto error; - g_imm_operand_pad(operand, true); + g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING); - g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); + g_arch_instruction_attach_extra_operand(result, operand); return result; - grins_error: + error: + + g_clear_object(&result); return NULL; @@ -396,7 +404,7 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory GArchInstruction *result; /* Instruction à retourner */ vmpa2t old; /* Sauvegarde de la position */ size_t i; /* Boucle de parcours */ - GImmOperand *operand; /* Octet non décodé à afficher */ + GArchOperand *operand; /* Octet non décodé à afficher */ mrange_t range; /* Couverture de l'instruction */ /* Par soucis de cohérence */ @@ -408,12 +416,12 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory for (i = 0; i < count; i++) { - operand = G_IMM_OPERAND(g_imm_operand_new_from_data(size, content, addr, endian)); - if (operand == NULL) goto grina_error; + operand = g_imm_operand_new_from_data(size, content, addr, endian); + if (operand == NULL) goto error; - g_imm_operand_pad(operand, true); + g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING); - g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); + g_arch_instruction_attach_extra_operand(result, operand); } @@ -423,7 +431,7 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory return result; - grina_error: + error: g_object_unref(G_OBJECT(result)); diff --git a/src/arch/instructions/undefined-int.h b/src/arch/instructions/undefined-int.h index 8a648cf..a9b7627 100644 --- a/src/arch/instructions/undefined-int.h +++ b/src/arch/instructions/undefined-int.h @@ -32,63 +32,57 @@ /* Informations glissées dans la structure GObject de GArchInstruction */ -typedef union _undef_obj_extra +typedef struct _undef_extra_data_t { - struct - { - InstrExpectedBehavior behavior; /* Conséquences réelles */ + /** + * Le champ uid de la structure parente attendue conduit à une taille + * alignée sur 2 octets, donc à une taille totale de 4 octets ce qui + * représente la limite maximale de taille supportée. + * + * Pour 3 octets à la base, qui devraient laisser 8 - 1 octets disponbibles + * en incluant le bit de verrouillage. + * + * On reproduit donc la structure instr_extra_data_t ici, en basculant + * l'énumération InstrExpectedBehavior en champ de bits. + */ - }; + itid_t uid; /* Identifiant unique du type */ + ArchInstrFlag flags; /* Informations complémentaires*/ - gint lock; /* Gestion d'accès aux fanions */ + unsigned int behavior : 2; /* Conséquences réelles */ + +} undef_extra_data_t; -} undef_obj_extra; /* Définition générique d'une instruction au comportement non défini (instance) */ struct _GUndefInstruction { GArchInstruction parent; /* A laisser en premier */ -#if __SIZEOF_INT__ == __SIZEOF_LONG__ - - /** - * L'inclusion des informations suivantes dépend de l'architecture. - * - * Si la structure GObject possède un trou, on remplit de préférence - * ce dernier. - */ - - undef_obj_extra extra; /* Externalisation embarquée */ +}; -#endif +/* Définition générique d'une instruction au comportement non défini (classe) */ +struct _GUndefInstructionClass +{ + GArchInstructionClass parent; /* A laisser en premier */ }; + /** * Accès aux informations éventuellement déportées. */ -#if __SIZEOF_INT__ == __SIZEOF_LONG__ +#if 1 //__SIZEOF_INT__ == __SIZEOF_LONG__ -# define INIT_UNDEF_INSTR_EXTRA(ins) ins->extra.lock = 0 - -# define GET_UNDEF_INSTR_EXTRA(ins) &ins->extra +# define GET_UNDEF_INSTR_EXTRA(ins) ((undef_extra_data_t *)&((GArchInstruction *)ins)->extra) #else -# define INIT_UNDEF_INSTR_EXTRA(ins) INIT_GOBJECT_EXTRA(G_OBJECT(ins)) - -# define GET_UNDEF_INSTR_EXTRA(ins) GET_GOBJECT_EXTRA(G_OBJECT(ins), undef_obj_extra) +# define GET_UNDEF_INSTR_EXTRA(ins) GET_GOBJECT_EXTRA(G_OBJECT(ins), undef_extra_data_t) #endif -/* Définition générique d'une instruction au comportement non défini (classe) */ -struct _GUndefInstructionClass -{ - GArchInstructionClass parent; /* A laisser en premier */ - -}; - #endif /* _ARCH_INSTRUCTIONS_UNDEFINED_INT_H */ diff --git a/src/arch/instructions/undefined.c b/src/arch/instructions/undefined.c index 880e338..15c63e7 100644 --- a/src/arch/instructions/undefined.c +++ b/src/arch/instructions/undefined.c @@ -31,7 +31,7 @@ #include "undefined-int.h" -#include "../../gtkext/gtkblockdisplay.h" +#include "../../core/columns.h" @@ -74,6 +74,17 @@ static void g_undef_instruction_print(GUndefInstruction *, GBufferLine *, size_t +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Charge un contenu depuis une mémoire tampon. */ +static bool g_undef_instruction_load(GUndefInstruction *, GObjectStorage *, packed_buffer_t *); + +/* Sauvegarde un contenu dans une mémoire tampon. */ +static bool g_undef_instruction_store(GUndefInstruction *, GObjectStorage *, packed_buffer_t *); + + + /* ---------------------------------------------------------------------------------- */ /* INSTRUCTION INCONNUE / DONNEES */ /* ---------------------------------------------------------------------------------- */ @@ -115,6 +126,9 @@ static void g_undef_instruction_class_init(GUndefInstructionClass *klass) instr->print = (print_instruction_fc)g_undef_instruction_print; + instr->load = (load_instruction_fc)g_undef_instruction_load; + instr->store = (store_instruction_fc)g_undef_instruction_store; + } @@ -132,7 +146,7 @@ static void g_undef_instruction_class_init(GUndefInstructionClass *klass) static void g_undef_instruction_init(GUndefInstruction *instr) { - INIT_ARCH_INSTR_EXTRA(instr); + GET_UNDEF_INSTR_EXTRA(instr)->behavior = IEB_UNDEFINED; } @@ -190,7 +204,7 @@ static void g_undef_instruction_finalize(GUndefInstruction *instr) GArchInstruction *g_undef_instruction_new(InstrExpectedBehavior behavior) { GArchInstruction *result; /* Instruction à retourner */ - undef_obj_extra *extra; /* Données insérées à modifier */ + undef_extra_data_t *extra; /* Données insérées à modifier */ result = g_object_new(G_TYPE_UNDEF_INSTRUCTION, NULL); @@ -241,7 +255,7 @@ static const char *g_undef_instruction_get_encoding(const GUndefInstruction *ins const char *g_undef_instruction_get_keyword(const GUndefInstruction *instr) { const char *result; /* Désignation à retourner */ - undef_obj_extra *extra; /* Données insérées à consulter*/ + undef_extra_data_t *extra; /* Données insérées à consulter*/ extra = GET_UNDEF_INSTR_EXTRA(instr); @@ -300,7 +314,8 @@ static bool g_undef_instruction_unserialize(GUndefInstruction *instr, GAsmStorag { bool result; /* Bilan à retourner */ GArchInstructionClass *parent; /* Classe parente à consulter */ - undef_obj_extra *extra; /* Données insérées à modifier */ + undef_extra_data_t *extra; /* Données insérées à consulter*/ + uint8_t val; /* Champ de bits manipulé */ parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class); @@ -310,7 +325,12 @@ static bool g_undef_instruction_unserialize(GUndefInstruction *instr, GAsmStorag { extra = GET_UNDEF_INSTR_EXTRA(instr); - result = extract_packed_buffer(pbuf, &extra->behavior, sizeof(InstrExpectedBehavior), true); + LOCK_GOBJECT_EXTRA(extra); + + result = extract_packed_buffer(pbuf, &val, sizeof(uint8_t), false); + extra->behavior = val; + + UNLOCK_GOBJECT_EXTRA(extra); } @@ -337,7 +357,7 @@ static bool g_undef_instruction_serialize(GUndefInstruction *instr, GAsmStorage { bool result; /* Bilan à retourner */ GArchInstructionClass *parent; /* Classe parente à consulter */ - undef_obj_extra *extra; /* Données insérées à consulter*/ + undef_extra_data_t *extra; /* Données insérées à consulter*/ parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class); @@ -347,7 +367,11 @@ static bool g_undef_instruction_serialize(GUndefInstruction *instr, GAsmStorage { extra = GET_UNDEF_INSTR_EXTRA(instr); - result = extend_packed_buffer(pbuf, &extra->behavior, sizeof(InstrExpectedBehavior), true); + LOCK_GOBJECT_EXTRA(extra); + + result = extend_packed_buffer(pbuf, (uint8_t []){ extra->behavior }, sizeof(uint8_t), false); + + UNLOCK_GOBJECT_EXTRA(extra); } @@ -417,12 +441,106 @@ static void g_undef_instruction_print(GUndefInstruction *instr, GBufferLine *lin InstrExpectedBehavior g_undef_instruction_get_behavior(const GUndefInstruction *instr) { InstrExpectedBehavior result; /* Comportement à retourner */ - undef_obj_extra *extra; /* Données insérées à consulter*/ + undef_extra_data_t *extra; /* Données insérées à consulter*/ extra = GET_UNDEF_INSTR_EXTRA(instr); + LOCK_GOBJECT_EXTRA(extra); + result = extra->behavior; + UNLOCK_GOBJECT_EXTRA(extra); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : instr = élément GLib à constuire. * +* storage = conservateur de données à manipuler ou NULL. * +* pbuf = zone tampon à lire. * +* * +* Description : Charge un contenu depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_undef_instruction_load(GUndefInstruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchInstructionClass *parent; /* Classe parente à consulter */ + undef_extra_data_t *extra; /* Données insérées à consulter*/ + uint8_t val; /* Champ de bits manipulé */ + + parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class); + + result = parent->load(G_ARCH_INSTRUCTION(instr), storage, pbuf); + + if (result) + { + extra = GET_UNDEF_INSTR_EXTRA(instr); + + LOCK_GOBJECT_EXTRA(extra); + + result = extract_packed_buffer(pbuf, &val, sizeof(uint8_t), false); + extra->behavior = val; + + UNLOCK_GOBJECT_EXTRA(extra); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = élément GLib à consulter. * +* storage = conservateur de données à manipuler ou NULL. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde un contenu dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_undef_instruction_store(GUndefInstruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchInstructionClass *parent; /* Classe parente à consulter */ + undef_extra_data_t *extra; /* Données insérées à consulter*/ + + parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class); + + result = parent->store(G_ARCH_INSTRUCTION(instr), storage, pbuf); + + if (result) + { + extra = GET_UNDEF_INSTR_EXTRA(instr); + + LOCK_GOBJECT_EXTRA(extra); + + result = extend_packed_buffer(pbuf, (uint8_t []){ extra->behavior }, sizeof(uint8_t), false); + + UNLOCK_GOBJECT_EXTRA(extra); + + } + return result; } |