diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/instruction.c | 39 | ||||
-rw-r--r-- | src/arch/instruction.h | 11 | ||||
-rw-r--r-- | src/arch/raw.c | 43 | ||||
-rw-r--r-- | src/arch/raw.h | 8 |
4 files changed, 84 insertions, 17 deletions
diff --git a/src/arch/instruction.c b/src/arch/instruction.c index d3ac97e..1090138 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -283,6 +283,8 @@ bool g_arch_instruction_set_flag(GArchInstruction *instr, ArchInstrFlag flag) bool result; /* Bilan à retourner */ instr_obj_extra *extra; /* Données insérées à modifier */ + assert(flag <= AIF_HIGH_USER); + extra = GET_ARCH_INSTR_EXTRA(instr); g_bit_lock(&extra->lock, INSTR_EXTRA_LOCK_BIT); @@ -300,6 +302,41 @@ bool g_arch_instruction_set_flag(GArchInstruction *instr, ArchInstrFlag flag) /****************************************************************************** * * +* Paramètres : instr = instruction quelconque à modifier. * +* flag = drapeau d'information complémentaire à planter. * +* * +* Description : Retire une information complémentaire à une instruction. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_arch_instruction_unset_flag(GArchInstruction *instr, ArchInstrFlag flag) +{ + bool result; /* Bilan à retourner */ + instr_obj_extra *extra; /* Données insérées à modifier */ + + assert(flag <= AIF_HIGH_USER); + + extra = GET_ARCH_INSTR_EXTRA(instr); + + g_bit_lock(&extra->lock, INSTR_EXTRA_LOCK_BIT); + + extra->flags &= ~flag; + + result = true; + + g_bit_unlock(&extra->lock, INSTR_EXTRA_LOCK_BIT); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction quelconque à consulter. * * flag = drapeau d'information à rechercher. * * * @@ -316,6 +353,8 @@ bool g_arch_instruction_has_flag(const GArchInstruction *instr, ArchInstrFlag fl bool result; /* Bilan à retourner */ instr_obj_extra *extra; /* Données insérées à consulter*/ + assert(flag <= AIF_HIGH_USER); + extra = GET_ARCH_INSTR_EXTRA(instr); g_bit_lock(&extra->lock, INSTR_EXTRA_LOCK_BIT); diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 6c04acb..78f0cdb 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -54,12 +54,18 @@ typedef struct _GArchInstructionClass GArchInstructionClass; /* Drapeaux pour informations complémentaires */ + +#define AIF_USER_BIT 3 + typedef enum _ArchInstrFlag { AIF_NONE = (0 << 0), /* Aucune information */ AIF_ROUTINE_START = (1 << 0), /* Début de routine */ AIF_RETURN_POINT = (1 << 1), /* Retour de fonction appelée */ - AIF_CALL = (1 << 2) /* Instruction d'appel */ + AIF_CALL = (1 << 2), /* Instruction d'appel */ + + AIF_LOW_USER = (1 << AIF_USER_BIT), /* Premier bit disponible */ + AIF_HIGH_USER = (1 << 14), /* Dernier bit disponible */ } ArchInstrFlag; @@ -87,6 +93,9 @@ const char *g_arch_instruction_get_encoding(const GArchInstruction *); /* Ajoute une information complémentaire à une instruction. */ bool g_arch_instruction_set_flag(GArchInstruction *, ArchInstrFlag); +/* Retire une information complémentaire à une instruction. */ +bool g_arch_instruction_unset_flag(GArchInstruction *, ArchInstrFlag); + /* Détermine si une instruction possède un fanion particulier. */ bool g_arch_instruction_has_flag(const GArchInstruction *, ArchInstrFlag); diff --git a/src/arch/raw.c b/src/arch/raw.c index 9d597fa..243752d 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -46,9 +46,6 @@ struct _GRawInstruction { GArchInstruction parent; /* A laisser en premier */ - bool is_padding; /* Bourrage à représenter ? */ - bool is_string; /* Chaîne de caractères ? */ - }; /* Définition générique d'une instruction brute d'architecture (classe) */ @@ -450,7 +447,7 @@ static const char *g_raw_instruction_get_encoding(const GRawInstruction *instr) { const char *result; /* Description à retourner */ - if (instr->is_string) + if (g_raw_instruction_is_string(instr)) result = _("String"); else result = _("Raw"); @@ -529,7 +526,7 @@ static bool g_raw_instruction_unserialize(GRawInstruction *instr, GAsmStorage *s result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); if (result) - instr->is_padding = (boolean == 1 ? true : false); + g_raw_instruction_mark_as_padding(instr, (boolean == 1)); } @@ -538,7 +535,7 @@ static bool g_raw_instruction_unserialize(GRawInstruction *instr, GAsmStorage *s result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); if (result) - instr->is_string = (boolean == 1 ? true : false); + g_raw_instruction_mark_as_string(instr, (boolean == 1)); } @@ -573,13 +570,13 @@ static bool g_raw_instruction_serialize(GRawInstruction *instr, GAsmStorage *sto if (result) { - boolean = (instr->is_padding ? 1 : 0); + boolean = (g_raw_instruction_is_padding(instr) ? 1 : 0); result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); } if (result) { - boolean = (instr->is_string ? 1 : 0); + boolean = (g_raw_instruction_is_string(instr) ? 1 : 0); result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); } @@ -636,10 +633,10 @@ static void g_raw_instruction_print(GRawInstruction *instr, GBufferLine *line, s /* Contenu */ - if (instr->is_padding) + if (g_raw_instruction_is_padding(instr)) max_displayed_len = 0; - else if (instr->is_string) + else if (g_raw_instruction_is_string(instr)) max_displayed_len = 1; else @@ -657,7 +654,7 @@ static void g_raw_instruction_print(GRawInstruction *instr, GBufferLine *line, s g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, key, klen, RTT_INSTRUCTION, NULL); - if (instr->is_padding) + if (g_raw_instruction_is_padding(instr)) g_buffer_line_append_text(line, BLC_ASSEMBLY, "...", 3, RTT_RAW, NULL); else @@ -683,7 +680,7 @@ static void g_raw_instruction_print(GRawInstruction *instr, GBufferLine *line, s if (g_imm_operand_get_size(imm) != MDS_8_BITS) goto grip_fallback; - if (!instr->is_string && g_imm_operand_get_display(imm) != IOD_CHAR) + if (!g_raw_instruction_is_string(instr) && g_imm_operand_get_display(imm) != IOD_CHAR) goto grip_fallback; #ifndef NDEBUG @@ -794,7 +791,10 @@ static void g_raw_instruction_print(GRawInstruction *instr, GBufferLine *line, s void g_raw_instruction_mark_as_padding(GRawInstruction *instr, bool is_padding) { - instr->is_padding = is_padding; + if (is_padding) + g_arch_instruction_set_flag(G_ARCH_INSTRUCTION(instr), RIF_PADDING); + else + g_arch_instruction_unset_flag(G_ARCH_INSTRUCTION(instr), RIF_PADDING); } @@ -814,7 +814,11 @@ void g_raw_instruction_mark_as_padding(GRawInstruction *instr, bool is_padding) bool g_raw_instruction_is_padding(const GRawInstruction *instr) { - return instr->is_padding; + bool result; /* Indication à retourner */ + + result = g_arch_instruction_has_flag(G_ARCH_INSTRUCTION(instr), RIF_PADDING); + + return result; } @@ -834,7 +838,10 @@ bool g_raw_instruction_is_padding(const GRawInstruction *instr) void g_raw_instruction_mark_as_string(GRawInstruction *instr, bool is_string) { - instr->is_string = is_string; + if (is_string) + g_arch_instruction_set_flag(G_ARCH_INSTRUCTION(instr), RIF_STRING); + else + g_arch_instruction_unset_flag(G_ARCH_INSTRUCTION(instr), RIF_STRING); } @@ -854,6 +861,10 @@ void g_raw_instruction_mark_as_string(GRawInstruction *instr, bool is_string) bool g_raw_instruction_is_string(const GRawInstruction *instr) { - return instr->is_string; + bool result; /* Indication à retourner */ + + result = g_arch_instruction_has_flag(G_ARCH_INSTRUCTION(instr), RIF_STRING); + + return result; } diff --git a/src/arch/raw.h b/src/arch/raw.h index aac48ea..a1c3619 100644 --- a/src/arch/raw.h +++ b/src/arch/raw.h @@ -66,6 +66,14 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa /* Crée une instruction de type 'db/dw/etc' étendue. */ GArchInstruction *g_raw_instruction_new_array(const GBinContent *, MemoryDataSize, size_t, vmpa2t *, SourceEndian); +/* Drapeaux pour informations complémentaires */ +typedef enum _RawInstrFlag +{ + RIF_PADDING = (1 << (AIF_USER_BIT + 0)),/* Données de bourrage */ + RIF_STRING = (1 << (AIF_USER_BIT + 1)),/* Impression en chaîne */ + +} RawInstrFlag; + /* Marque l'instruction comme ne contenant que du bourrage. */ void g_raw_instruction_mark_as_padding(GRawInstruction *, bool); |