summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/disass/output.c101
1 files changed, 46 insertions, 55 deletions
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
index 78aba82..fb3f5ed 100644
--- a/src/analysis/disass/output.c
+++ b/src/analysis/disass/output.c
@@ -37,6 +37,8 @@
#define ROUTINE_INTRO_MSG "; --------------- BEGIN OF PROCEDURE ---------------"
+#define ROUTINE_OUTRO_MSG "; ---------------- END OF PROCEDURE ----------------"
+
/******************************************************************************
@@ -66,27 +68,18 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
GBinSymbol **symbols; /* Symboles à représenter */
size_t sym_count; /* Qté de symboles présents */
size_t sym_index; /* Prochain symbole non traité */
-
- //GArchProcessor *proc; /* Architecture du binaire */
MemoryDataSize msize; /* Taille du bus d'adresses */
const GBinContent *content; /* Contenu binaire global */
-
size_t count; /* Nombre total d'instructions */
activity_id_t id; /* Identifiant de progression */
-
-
-
+ bool expect_outro; /* Fin de zone de code définie */
size_t i; /* Boucle de parcours */
GArchInstruction *instr; /* Instruction à traiter */
-
const vmpa2t *iaddr; /* Adresse d'instruction */
- const vmpa2t *saddr; /* Adresse de symbole */
-
+ vmpa2t outro_addr; /* Adresse de fin de code */
GBufferLine *line;
-
-
const vmpa2t *paddr; /* Adresse de portion */
-
+ const vmpa2t *saddr; /* Adresse de symbole */
int compared; /* Bilan d'une comparaison */
SymbolType stype; /* Type de symbole trouvé */
const char *label; /* Etiquette ciblant un symbole*/
@@ -107,6 +100,8 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
+
+
output = g_asm_output_new();
layer = g_exe_format_get_main_layer(format);
@@ -117,65 +112,55 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &sym_count);
sym_index = 0;
-#if 0
- for (i = 0; i < sym_count; i++)
- {
- saddr = get_mrange_addr(g_binary_symbol_get_range(symbols[i]));
- if (saddr == NULL) continue;
-
- //if (g_binary_symbol_get_label(symbols[i]) == NULL) continue;
-
- printf(" <symbol> '%s' -> 0x%08lx\n",
- "g_binary_symbol_get_label(symbols[i])",
- saddr->virtual);
-
- }
-#endif
- //GDbCollection *g_loaded_binary_find_collection(GLoadedBinary *, DBFeatures);
-
-
-
-
- //proc = get_arch_processor_from_format(format);
msize = g_arch_processor_get_memory_size(proc);
content = g_binary_format_get_content(G_BIN_FORMAT(format));
-#if 0
- g_arch_instruction_get_location(instrs, NULL, NULL, &start);
- start =
-
- iter = g_arch_instruction_find_last(instrs);
- g_arch_instruction_get_location(iter, NULL, NULL, &end);
-#endif
-
-
count = g_arch_processor_count_disassembled_instructions(proc);
id = gtk_status_stack_add_activity(status, _("Printing all disassebled parts..."), count);
+ expect_outro = false;
+
for (i = 0; i < count; i++)
{
instr = g_arch_processor_get_disassembled_instruction(proc, i);
+ iaddr = get_mrange_addr(g_arch_instruction_get_range(instr));
+ /* Fin d'une portion de code précédente ? */
-#if 0
- g_arch_instruction_get_location(iter, NULL, NULL, &iaddr);
-
- /* Ajout des prototypes de fonction */
- for (; i < count; i++)
+ if (expect_outro && cmp_vmpa(iaddr, &outro_addr) >= 0)
{
- raddr = g_binary_routine_get_address(routines[i]);
- if (raddr > iaddr) break;
+ expect_outro = false;
- g_binary_routine_output_info(routines[i], output, buffer);
+ init_mrange(&range, &outro_addr, 0);
- }
-#endif
+ line = g_code_buffer_prepare_new_line(buffer, &range);
+ g_buffer_line_add_flag(line, BLF_IS_LABEL);
+ g_buffer_line_fill_mrange(line, msize, msize);
+ g_code_buffer_append_new_line(buffer, line);
- iaddr = get_mrange_addr(g_arch_instruction_get_range(instr));
+ line = g_code_buffer_prepare_new_line(buffer, &range);
+ g_buffer_line_add_flag(line, BLF_IS_LABEL);
+ g_buffer_line_fill_mrange(line, msize, msize);
+
+ g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD,
+ ROUTINE_OUTRO_MSG, strlen(ROUTINE_OUTRO_MSG), RTT_COMMENT);
+
+ g_code_buffer_append_new_line(buffer, line);
+
+ line = g_code_buffer_prepare_new_line(buffer, &range);
+ g_buffer_line_add_flag(line, BLF_IS_LABEL);
+ g_buffer_line_fill_mrange(line, msize, msize);
+
+ g_code_buffer_append_new_line(buffer, line);
+
+ }
+
+ /* Début d'une nouvelle portion ? */
while (portion_index < portions_count)
{
@@ -190,9 +175,7 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
}
-
-
-
+ /* Début d'un nouveau symbole ? */
if (sym_index < sym_count)
{
@@ -225,6 +208,8 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
if (stype == STP_ROUTINE || stype == STP_FUNCTION || stype == STP_ENTRY_POINT)
{
+ /* Impression de la marque de début */
+
init_mrange(&range, get_mrange_addr(g_binary_symbol_get_range(symbols[sym_index])), 0);
line = g_code_buffer_prepare_new_line(buffer, &range);
@@ -249,6 +234,12 @@ void print_disassembled_instructions(GCodeBuffer *buffer, GExeFormat *format, GA
g_code_buffer_append_new_line(buffer, line);
+ /* Mémorisation de la fin */
+
+ compute_mrange_end_addr(g_binary_symbol_get_range(symbols[sym_index]), &outro_addr);
+
+ expect_outro = true;
+
}
/* Etiquette ? */