summaryrefslogtreecommitdiff
path: root/src/binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/binary.c')
-rw-r--r--src/binary.c94
1 files changed, 43 insertions, 51 deletions
diff --git a/src/binary.c b/src/binary.c
index 4938b0f..862a4d0 100644
--- a/src/binary.c
+++ b/src/binary.c
@@ -123,9 +123,16 @@ void fill_snippet(GtkSnippet *snippet)
asm_processor *proc;
asm_instr *instr;
- uint8_t *data = "\x66\xba\x0c\x00\x00\x00\x66\xb9\x28\x00\xee\x00\x66\xbb\x01\x00\x00\x00\x66\xb8\x04\x00\x00\x00\xcd\x80\x66\xbb\x00\x00\x00\x00\x66\xb8\x01\x00\x00\x00\xcd\x80\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x0a";
+ char **comments;
+ uint64_t *offsets;
+ size_t comments_count;
+ code_line_info **comments_list;
- //uint8_t *data = "\x66\xbb\x00\x00\x00\x00\x66\xb8\x01\x00\x00\x00\xcd\x80\x90";
+
+
+ code_line_info **list;
+ size_t list_len;
+ code_line_info *item;
off_t start;
off_t pos;
@@ -136,6 +143,8 @@ void fill_snippet(GtkSnippet *snippet)
uint64_t base = 0;
uint64_t offset = 0;
+ size_t i;
+
proc = create_x86_processor();
pos = 0;
@@ -154,16 +163,27 @@ void fill_snippet(GtkSnippet *snippet)
format = load_elf(bin_data, length);
dformat = load_dwarf(bin_data, length, format);
+
+
+ comments_count = get_dwarf_comments(dformat, &comments, &offsets);
+
+ comments_list = (code_line_info **)calloc(comments_count, sizeof(code_line_info *));
+
+ for (i = 0; i < comments_count; i++)
+ comments_list[i] = create_code_line_info(offsets[i], NULL, strdup(comments[i]));
+
+ i = 0;
+
find_exe_section(format, ".text", &pos, &len, &base);
/*find_line_info(bin_data, &len);*/
-
+ /*
printf("Exiting...\n");
exit(0);
-
+ */
offset = base;
@@ -171,77 +191,49 @@ void fill_snippet(GtkSnippet *snippet)
gtk_snippet_set_processor(snippet, proc);
- gtk_snippet_add_line(snippet, offset, NULL, "Simple HelloWorld !");
+ gtk_snippet_add_line(snippet, create_code_line_info(offset, NULL, "Simple HelloWorld !"));
-#if 1
start = pos;
pos = 0;
- while (pos < len)
- {
- offset = base + pos;
-
- instr = decode_instruction(proc, &bin_data[start], &pos, len, offset);
-
- gtk_snippet_add_line(snippet, offset, instr, NULL);
-
-
- }
-
-
- ret = munmap(bin_data, length);
-
-
-#else
-
- pos = 0;
- len = 0x28;
-
+ list = NULL;
+ list_len = 0;
while (pos < len)
{
offset = base + pos;
- instr = decode_instruction(proc, data, &pos, len, offset);
-
- gtk_snippet_add_line(snippet, offset, instr, NULL);
+ /* Si on a un commentaire pour cette ligne... */
+ if (comments_count > 0 && offsets[i] == offset)
+ {
+ list = (code_line_info **)realloc(list, ++list_len * sizeof(code_line_info *));
+ list[list_len - 1] = comments_list[i++];
+ }
- }
+ instr = decode_instruction(proc, &bin_data[start], &pos, len, offset);
- gtk_snippet_add_line(snippet, offset, NULL, "Simple HelloWorld !");
+ item = create_code_line_info(offset, instr, NULL);
- pos = 0;
- while (pos < len)
- {
- offset = base + pos;
+ list = (code_line_info **)realloc(list, ++list_len * sizeof(code_line_info *));
+ list[list_len - 1] = item;
- instr = decode_instruction(proc, data, &pos, len, offset);
-
- gtk_snippet_add_line(snippet, offset, instr, NULL);
+ //gtk_snippet_add_line(snippet, offset, instr, NULL);
}
-
- gtk_snippet_add_line(snippet, offset, NULL, "Simple HelloWorld !");
-
- pos = 0;
- while (pos < len)
+ for (i = 0; i < list_len; i++)
{
- offset = base + pos;
-
- instr = decode_instruction(proc, data, &pos, len, offset);
-
- gtk_snippet_add_line(snippet, offset, instr, NULL);
-
-
+ gtk_snippet_add_line(snippet, list[i]);
+ /* TODO: free() */
}
-#endif
+ ret = munmap(bin_data, length);
+
/*
gtk_snippet_build_content(snippet);