diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-03-18 23:18:26 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-03-18 23:18:26 (GMT) |
commit | 4cef477cbdfd61a28ed6531d1e91d5a330a67704 (patch) | |
tree | 1b4708f624e0f3bdb26403ab06ac9689cf4cf583 /src | |
parent | 5c1636199a06965c549f748014d582dcb85ba7df (diff) |
Computed limits for all routines according to existing symbols.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@491 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r-- | src/analysis/disass/area.c | 74 | ||||
-rw-r--r-- | src/analysis/disass/disassembler.c | 23 | ||||
-rw-r--r-- | src/analysis/disass/limit.c | 25 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/Makefile.am | 3 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/b_A8818.d | 10 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/bl_A8825.d | 8 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/blx_A8826.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/bx_A8827.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/ldr_A8862.d | 6 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/ldr_A8863.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/ldr_A8864.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/ldr_A8865.d | 2 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/ldrb_A8867.d | 6 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/pop_A88131.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/push_A88133.d | 10 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/str_A88204.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/post.c | 6 | ||||
-rw-r--r-- | src/arch/instruction-int.h | 1 | ||||
-rw-r--r-- | src/arch/instruction.c | 41 | ||||
-rw-r--r-- | src/arch/instruction.h | 14 | ||||
-rw-r--r-- | src/format/format.c | 19 | ||||
-rw-r--r-- | src/format/symbol.c | 32 | ||||
-rw-r--r-- | src/format/symbol.h | 4 |
23 files changed, 272 insertions, 36 deletions
diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c index 916918e..90738be 100644 --- a/src/analysis/disass/area.c +++ b/src/analysis/disass/area.c @@ -71,6 +71,11 @@ static bool mark_range_in_mem_area_as_processed(mem_area *, phys_t, phys_t, GArc +/* S'assure de la présence d'un début de routine à un point. */ +static void update_address_as_routine(GBinFormat *, const vmpa2t *); + + + /* Procède au désassemblage d'un contenu binaire non exécutable. */ static void load_data_from_mem_area(mem_area *, mem_area *, size_t, const GLoadedBinary *, GProcContext *, const vmpa2t *, status_blob_info *); @@ -377,6 +382,70 @@ static bool mark_range_in_mem_area_as_processed(mem_area *area, phys_t start, ph + + + + + + +/****************************************************************************** +* * +* Paramètres : format = format binaire en cours de traitement. * +* addr = adresse d'une instruction présentée comme première. * +* * +* Description : S'assure de la présence d'un début de routine à un point. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void update_address_as_routine(GBinFormat *format, const vmpa2t *addr) +{ + GBinSymbol *symbol; /* Symbole présent ou créé */ + phys_t offset; /* Décallage trouvé */ + bool found; /* Détection de symbole */ + SymbolType sym_type; /* Type de symbole en place */ + bool wrong_type; /* Analyse plus fine de ce type*/ + mrange_t range; /* Etendue du symbole à créer */ + VMPA_BUFFER(loc); /* Traduction de l'adresse */ + char name[5 + VMPA_MAX_LEN]; /* Nom de symbole nouveau */ + GBinRoutine *routine; /* Nouvelle routine trouvée */ + + found = g_binary_format_resolve_symbol(format, addr, &symbol, &offset); + + if (found) + { + sym_type = g_binary_symbol_get_target_type(symbol); + wrong_type = (sym_type != STP_ROUTINE && sym_type != STP_ENTRY_POINT); + } + + if (!found || (found && offset == 0 && wrong_type)) + { + init_mrange(&range, addr, 0); + + vmpa2_virt_to_string(addr, MDS_UNDEFINED, loc, NULL); + snprintf(name, sizeof(name), "ZZZ_%s", loc + 2); + + routine = g_binary_routine_new(); + g_binary_routine_set_name(routine, strdup(name)); + + g_binary_routine_set_range(routine, &range); + + if (!found) + { + symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0); + g_binary_symbol_attach_routine(symbol, routine); + g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); + } + else _g_binary_symbol_attach_routine(symbol, routine, STP_ROUTINE); + + } + +} + + /****************************************************************************** * * * Paramètres : area = aire représentant à contenu à parcourir. * @@ -489,6 +558,11 @@ bool load_code_from_mem_area(mem_area **list, size_t *count, size_t *index, cons g_arch_instruction_set_range(instr, &range); + /* Enregistrement d'un éventuel début de routine */ + + if (g_arch_instruction_get_flags(instr) & AIF_ROUTINE_START) + update_address_as_routine(format, &prev); + /* Eventuel renvoi vers d'autres adresses */ g_arch_instruction_call_hook(instr, IPH_LINK, ctx, format); diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index 37e6996..4b976c3 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -29,7 +29,7 @@ #include <string.h> -#include <i18n.h> ///// +#include <i18n.h> #include "fetch.h" @@ -299,6 +299,27 @@ G_BIN_FORMAT(g_loaded_binary_get_format(disass->binary) + /* Troisième étape */ + + routines = g_binary_format_get_routines(G_BIN_FORMAT(disass->format), &routines_count); + + + + + //id = gtk_extended_status_bar_push(statusbar, _("Finding remaining limits..."), true); + + //qsort(routines, routines_count, sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_rcompare); + + limit_all_routines(disass->format, routines, routines_count, statusbar, id); + + //gtk_extended_status_bar_remove(statusbar, id); + + //run_plugins_on_binary(disass->binary, PGA_BINARY_BOUNDED, true); + + + + + /* Septième étape */ //id = gtk_extended_status_bar_push(statusbar, _("Printing disassembled code..."), true); diff --git a/src/analysis/disass/limit.c b/src/analysis/disass/limit.c index bb2c865..3810978 100644 --- a/src/analysis/disass/limit.c +++ b/src/analysis/disass/limit.c @@ -128,4 +128,29 @@ void limit_all_routines(GExeFormat *format, GBinRoutine **routines, size_t count if (exe_ranges != NULL) free(exe_ranges); + + + + do + { + const mrange_t *_range; + vmpa2t _end; + + printf("LIMIT == %zu routines\n", count); + + for (i = 0; i < count; i++) + { + _range = g_binary_routine_get_range(routines[i]); + compute_mrange_end_addr(_range, &_end); + + printf(" <LIMIT> 0x%08x <-> 0x%08x '%s'\n", + (unsigned int)((get_mrange_addr(_range))->virtual), + (unsigned int)_end.virtual, + g_binary_routine_to_string(routines[i])); + + } + + } while (0); + + } diff --git a/src/arch/arm/v7/opdefs/Makefile.am b/src/arch/arm/v7/opdefs/Makefile.am index 45d4932..318e20b 100644 --- a/src/arch/arm/v7/opdefs/Makefile.am +++ b/src/arch/arm/v7/opdefs/Makefile.am @@ -21,7 +21,8 @@ D2C_MACROS = \ -M Condition=g_arm_instruction_set_cond \ -M Register=translate_armv7_register \ -M "ExpandImmC32=g_imm_operand_new_from_value(MDS_32_BITS_UNSIGNED, " \ - -M SignExtend=sign_extend_armv7_imm + -M SignExtend=sign_extend_armv7_imm \ + -M SetInsFlag=g_arch_instruction_set_flag ARMV7_DEFS = \ adc_A881.d \ diff --git a/src/arch/arm/v7/opdefs/b_A8818.d b/src/arch/arm/v7/opdefs/b_A8818.d index 5d696a3..50bdda9 100644 --- a/src/arch/arm/v7/opdefs/b_A8818.d +++ b/src/arch/arm/v7/opdefs/b_A8818.d @@ -47,7 +47,7 @@ //if cond == '1110' then UNDEFINED; //if cond == '1111' then SEE SVC; - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } @@ -75,7 +75,7 @@ @rules { //if InITBlock() && !LastInITBlock() then UNPREDICTABLE; - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } @@ -105,7 +105,7 @@ //if cond<3:1> == '111' then SEE "Related encodings"; //if InITBlock() then UNPREDICTABLE; - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } @@ -135,7 +135,7 @@ @rules { //if InITBlock() && !LastInITBlock() then UNPREDICTABLE; - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } @@ -163,7 +163,7 @@ @rules { - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/bl_A8825.d b/src/arch/arm/v7/opdefs/bl_A8825.d index c5de31e..63922dd 100644 --- a/src/arch/arm/v7/opdefs/bl_A8825.d +++ b/src/arch/arm/v7/opdefs/bl_A8825.d @@ -46,7 +46,7 @@ @rules { - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } @@ -75,7 +75,7 @@ @rules { - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } @@ -102,7 +102,7 @@ @rules { - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } @@ -129,7 +129,7 @@ @rules { - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/blx_A8826.d b/src/arch/arm/v7/opdefs/blx_A8826.d index 12c55ad..c972af2 100644 --- a/src/arch/arm/v7/opdefs/blx_A8826.d +++ b/src/arch/arm/v7/opdefs/blx_A8826.d @@ -39,7 +39,7 @@ //if m == 15 then UNPREDICTABLE; //if InITBlock() && !LastInITBlock() then UNPREDICTABLE; - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } @@ -61,7 +61,7 @@ @rules { //if m == 15 then UNPREDICTABLE; - //call DefineAsReturn(1) + //chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/bx_A8827.d b/src/arch/arm/v7/opdefs/bx_A8827.d index dd06901..4856885 100644 --- a/src/arch/arm/v7/opdefs/bx_A8827.d +++ b/src/arch/arm/v7/opdefs/bx_A8827.d @@ -44,7 +44,7 @@ @rules { - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } @@ -71,7 +71,7 @@ @rules { - call DefineAsReturn(1) + chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/ldr_A8862.d b/src/arch/arm/v7/opdefs/ldr_A8862.d index ecb530b..49d5c3a 100644 --- a/src/arch/arm/v7/opdefs/ldr_A8862.d +++ b/src/arch/arm/v7/opdefs/ldr_A8862.d @@ -76,7 +76,7 @@ //if Rn == '1111' then SEE LDR (literal); //if t == 15 && InITBlock() && !LastInITBlock() then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -104,7 +104,7 @@ //if Rn == '1101' && P == '0' && U == '1' && W == '1' && imm8 == '00000100' then SEE POP; //if P == '0' && W == '0' then UNDEFINED; //if (wback && n == t) || (t == 15 && InITBlock() && !LastInITBlock()) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -133,7 +133,7 @@ //if Rn == '1101' && P == '0' && U == '1' && W == '1' && imm8 == '00000100' then SEE POP; //if P == '0' && W == '0' then UNDEFINED; //if (wback && n == t) || (t == 15 && InITBlock() && !LastInITBlock()) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/ldr_A8863.d b/src/arch/arm/v7/opdefs/ldr_A8863.d index 39b9079..2360e3a 100644 --- a/src/arch/arm/v7/opdefs/ldr_A8863.d +++ b/src/arch/arm/v7/opdefs/ldr_A8863.d @@ -46,7 +46,7 @@ //t = UInt(Rt); n = UInt(Rn); imm32 = ZeroExtend(imm12, 32); //index = (P == '1'); add = (U == '1'); wback = (P == '0') || (W == '1'); //if wback && n == t then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -76,7 +76,7 @@ //t = UInt(Rt); n = UInt(Rn); imm32 = ZeroExtend(imm12, 32); //index = (P == '1'); add = (U == '1'); wback = (P == '0') || (W == '1'); //if wback && n == t then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/ldr_A8864.d b/src/arch/arm/v7/opdefs/ldr_A8864.d index 3fbc0e3..c5b0dd0 100644 --- a/src/arch/arm/v7/opdefs/ldr_A8864.d +++ b/src/arch/arm/v7/opdefs/ldr_A8864.d @@ -70,7 +70,7 @@ @rules { //if t == 15 && InITBlock() && !LastInITBlock() then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -101,7 +101,7 @@ @rules { //if t == 15 && InITBlock() && !LastInITBlock() then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/ldr_A8865.d b/src/arch/arm/v7/opdefs/ldr_A8865.d index 56a09fb..e8d255b 100644 --- a/src/arch/arm/v7/opdefs/ldr_A8865.d +++ b/src/arch/arm/v7/opdefs/ldr_A8865.d @@ -67,7 +67,7 @@ //if Rn == '1111' then SEE LDR (literal); //if m IN {13,15} then UNPREDICTABLE; //if t == 15 && InITBlock() && !LastInITBlock() then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/ldrb_A8867.d b/src/arch/arm/v7/opdefs/ldrb_A8867.d index 52a50cb..2114330 100644 --- a/src/arch/arm/v7/opdefs/ldrb_A8867.d +++ b/src/arch/arm/v7/opdefs/ldrb_A8867.d @@ -60,7 +60,7 @@ //if Rt == '1111' then SEE PLD; //if Rn == '1111' then SEE LDRB (literal); //if t == 13 then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -88,7 +88,7 @@ //if P == '1' && U == '1' && W == '0' then SEE LDRBT; //if P == '0' && W == '0' then UNDEFINED; //if t == 13 || (t == 15 && W == '1') || (wback && n == t) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -117,7 +117,7 @@ //if P == '1' && U == '1' && W == '0' then SEE LDRBT; //if P == '0' && W == '0' then UNDEFINED; //if t == 13 || (t == 15 && W == '1') || (wback && n == t) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/opdefs/pop_A88131.d b/src/arch/arm/v7/opdefs/pop_A88131.d index 329b705..2663e1b 100644 --- a/src/arch/arm/v7/opdefs/pop_A88131.d +++ b/src/arch/arm/v7/opdefs/pop_A88131.d @@ -48,7 +48,7 @@ @word 1 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 P(1) M(1) 0 register_list(13) - @syntax "push.W" <registers> + @syntax "pop.W" <registers> @conv { @@ -69,7 +69,7 @@ @word 1 1 1 1 1 0 0 0 0 1 0 1 1 1 0 1 Rt(4) 1 0 1 1 0 0 0 0 0 1 0 0 - @syntax "push.W" <registers> + @syntax "pop.W" <registers> @conv { diff --git a/src/arch/arm/v7/opdefs/push_A88133.d b/src/arch/arm/v7/opdefs/push_A88133.d index 0526a56..2ba7293 100644 --- a/src/arch/arm/v7/opdefs/push_A88133.d +++ b/src/arch/arm/v7/opdefs/push_A88133.d @@ -39,6 +39,8 @@ //if BitCount(registers) < 1 then UNPREDICTABLE; + if (M == '1'); call SetInsFlag(AIF_ROUTINE_START); + } } @@ -59,6 +61,8 @@ //if BitCount(registers) < 2 then UNPREDICTABLE; + if (M == '1'); call SetInsFlag(AIF_ROUTINE_START); + } } @@ -80,6 +84,8 @@ //if t IN {13,15} then UNPREDICTABLE + if (Rt == '1110'); call SetInsFlag(AIF_ROUTINE_START); + } } @@ -101,6 +107,8 @@ //if BitCount(register_list) < 2 then SEE STMDB / STMFD; + if (register_list & 0x4000); call SetInsFlag(AIF_ROUTINE_START); + } } @@ -123,6 +131,8 @@ //if t == 13 then UNPREDICTABLE; + if (Rt == '1110'); call SetInsFlag(AIF_ROUTINE_START); + } } diff --git a/src/arch/arm/v7/opdefs/str_A88204.d b/src/arch/arm/v7/opdefs/str_A88204.d index d4e9377..2712e1b 100644 --- a/src/arch/arm/v7/opdefs/str_A88204.d +++ b/src/arch/arm/v7/opdefs/str_A88204.d @@ -43,7 +43,7 @@ //if P == '0' && W == '1' then SEE STRT; //if Rn == '1101' && P == '1' && U == '0' && W == '1' && imm12 == '000000000100' then SEE PUSH; //if wback && (n == 15 || n == t) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } @@ -70,7 +70,7 @@ //if P == '0' && W == '1' then SEE STRT; //if Rn == '1101' && P == '1' && U == '0' && W == '1' && imm12 == '000000000100' then SEE PUSH; //if wback && (n == 15 || n == t) then UNPREDICTABLE; - if (Rt == '1111'); call DefineAsReturn(1) + if (Rt == '1111'); chk_call DefineAsReturn(1) } diff --git a/src/arch/arm/v7/post.c b/src/arch/arm/v7/post.c index dfeb720..e6a6c2e 100644 --- a/src/arch/arm/v7/post.c +++ b/src/arch/arm/v7/post.c @@ -77,7 +77,7 @@ void post_process_branch_instructions(GArchInstruction *instr, GProcContext *con g_binary_routine_set_range(routine, &trange); - symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0); + symbol = g_binary_symbol_new(STP_CODE_LABEL, NULL, ~0); g_binary_symbol_attach_routine(symbol, routine); g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); @@ -203,7 +203,7 @@ void post_process_comp_and_branch_instructions(GArchInstruction *instr, GProcCon g_binary_routine_set_range(routine, &trange); - symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0); + symbol = g_binary_symbol_new(STP_CODE_LABEL, NULL, ~0); g_binary_symbol_attach_routine(symbol, routine); g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); @@ -285,7 +285,7 @@ void post_process_ldr_instructions(GArchInstruction *instr, GProcContext *contex g_binary_routine_set_range(routine, &trange); - symbol = g_binary_symbol_new(STP_ROUTINE, NULL, ~0); + symbol = g_binary_symbol_new(STP_CODE_LABEL, NULL, ~0); g_binary_symbol_attach_routine(symbol, routine); g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index de9c70d..bb45f72 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -55,6 +55,7 @@ struct _GArchInstruction const char *suffix; /* Complément au nom affiché */ char *cached_keyword; /* Désignation complète */ + ArchInstrFlag flags; /* Informations complémentaires*/ instr_hook_fc hooks[IPH_COUNT]; /* Traitements complémentaires */ mrange_t range; /* Emplacement en mémoire */ diff --git a/src/arch/instruction.c b/src/arch/instruction.c index aced77e..0bcc739 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -151,7 +151,7 @@ static void g_arch_instruction_finalize(GArchInstruction *instr) /****************************************************************************** * * * Paramètres : instr = instruction quelconque à modifier. * -* suffix = chaîne de caractères fournie en complément. * +* suffix = chaîne de caractères fournie en complément. * * * * Description : Etend la désignation d'un nom d'instruction. * * * @@ -171,6 +171,45 @@ void g_arch_instruction_append_suffix(GArchInstruction *instr, const char *suffi /****************************************************************************** * * * Paramètres : instr = instruction quelconque à modifier. * +* flag = drapeau d'information complémentaire à planter. * +* * +* Description : Ajoute une information complémentaire à une instruction. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_arch_instruction_set_flag(GArchInstruction *instr, ArchInstrFlag flag) +{ + instr->flags |= flag; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction quelconque à modifier. * +* * +* Description : Fournit les informations complémentaires d'une instruction. * +* * +* Retour : Eventuels drapeaux d'information complémentaire à plantés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +ArchInstrFlag g_arch_instruction_get_flags(const GArchInstruction *instr) +{ + return instr->flags; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction quelconque à modifier. * * type = type de procédure à mémoriser. * * hook = fonction à appeler sur commande. * * * diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 12cfbb9..9251a34 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -62,6 +62,20 @@ GType g_arch_instruction_get_type(void); /* Etend la désignation d'un nom d'instruction. */ void g_arch_instruction_append_suffix(GArchInstruction *, const char *); +/* Drapeaux pour informations complémentaires */ +typedef enum _ArchInstrFlag +{ + AIF_NONE = (0 << 0), /* Aucune information */ + AIF_ROUTINE_START = (1 << 0) /* Début de routine */ + +} ArchInstrFlag; + +/* Ajoute une information complémentaire à une instruction. */ +void g_arch_instruction_set_flag(GArchInstruction *, ArchInstrFlag); + +/* Fournit les informations complémentaires d'une instruction. */ +ArchInstrFlag g_arch_instruction_get_flags(const GArchInstruction *); + /** * La définition de "GBinFormat", utile aux traitements complémentaires, ne peut * se faire en incluant le fichier d'en-tête "../format/format.h", pour cause diff --git a/src/format/format.c b/src/format/format.c index 2808b67..2093469 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -192,11 +192,28 @@ void g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) format->symbols[format->symbols_count - 1] = symbol; - qsort(format->symbols, format->symbols_count, sizeof(GBinSymbol *), (__compar_fn_t)g_binary_symbol_cmp); + switch (g_binary_symbol_get_target_type(symbol)) + { + case STP_ROUTINE: + case STP_ENTRY_POINT: + + format->routines = (GBinRoutine **)realloc(format->routines, + ++format->routines_count * sizeof(GBinRoutine *)); + + format->routines[format->routines_count - 1] = g_binary_symbol_get_routine(symbol); + + qsort(format->routines, format->routines_count, + sizeof(GBinRoutine *), (__compar_fn_t)g_binary_routine_compare); + break; + + default: + break; + + } } diff --git a/src/format/symbol.c b/src/format/symbol.c index d360591..c867b68 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -228,6 +228,7 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol) { case STP_ROUTINE: case STP_ENTRY_POINT: + case STP_CODE_LABEL: result = g_binary_routine_get_name(symbol->extra.routine); break; @@ -292,6 +293,7 @@ const char *g_binary_symbol_get_label(const GBinSymbol *symbol) { case STP_ROUTINE: case STP_ENTRY_POINT: + case STP_CODE_LABEL: result = g_binary_routine_get_name(symbol->extra.routine); break; @@ -344,6 +346,7 @@ void g_binary_symbol_fix_range(GBinSymbol *symbol, const vmpa2t *full) case STP_ROUTINE: case STP_ENTRY_POINT: + case STP_CODE_LABEL: routine = g_binary_symbol_get_routine(symbol); @@ -392,6 +395,7 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol) case STP_ROUTINE: case STP_ENTRY_POINT: + case STP_CODE_LABEL: result = g_binary_routine_get_range(symbol->extra.routine); break; @@ -431,6 +435,7 @@ void g_binary_symbol_set_alt_name(GBinSymbol *symbol, char *alt) * * * Paramètres : symbol = symbole à venir consulter. * * routine = prototype de la fonction représentée. * +* type = (nouveau) type du symbole attaché. * * * * Description : Attache la routine associée au symbole. * * * @@ -440,8 +445,13 @@ void g_binary_symbol_set_alt_name(GBinSymbol *symbol, char *alt) * * ******************************************************************************/ -void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine) +void _g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine, SymbolType type) { + if (symbol->extra.routine != NULL) + g_object_unref(G_OBJECT(symbol->extra.routine)); + + symbol->type = type; + symbol->extra.routine = routine; } @@ -449,6 +459,26 @@ void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine) /****************************************************************************** * * +* Paramètres : symbol = symbole à venir consulter. * +* routine = prototype de la fonction représentée. * +* * +* Description : Attache la routine associée au symbole. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine) +{ + _g_binary_symbol_attach_routine(symbol, routine, symbol->type); + +} + + +/****************************************************************************** +* * * Paramètres : symbol = symbole à venir manipuler. * * instr = représentation du symbole associé. * * * diff --git a/src/format/symbol.h b/src/format/symbol.h index fafc55f..49cde56 100644 --- a/src/format/symbol.h +++ b/src/format/symbol.h @@ -39,6 +39,7 @@ typedef enum _SymbolType { STP_DATA, /* Données brutes */ STP_ROUTINE, /* Simple morceau de code */ + STP_CODE_LABEL, /* Renvoi au sein de code */ STP_OBJECT, /* Objet quelconque */ STP_FUNCTION, /* Simple morceau de code */ STP_ENTRY_POINT, /* Morceau de code en entrée */ @@ -99,6 +100,9 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *); void g_binary_symbol_set_alt_name(GBinSymbol *, char *); /* Attache la routine associée au symbole. */ +void _g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *, SymbolType); + +/* Attache la routine associée au symbole. */ void g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *); /* Attache l'instruction associée au symbole. */ |