summaryrefslogtreecommitdiff
path: root/testelf.c
blob: 92d88013387157c14d022a355229be7dd8b613e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <glib.h>
#include "elfparser.h"

const char *n;

static void
check (ElfParser *elf, gulong addr)
{
    const ElfSym *sym = elf_parser_lookup_symbol (elf, addr);

    if (!sym)
    {
	g_print ("not found\n");
	return;
    }
    
    n = elf_parser_get_sym_name (elf, sym);
    
    g_print ("%p  =>    ", (void *)addr);

    if (sym)
    {
	g_print ("found: %s (%p)\n",
		 elf_parser_get_sym_name (elf, sym),
		 (void *)elf_parser_get_sym_address (elf, sym));
    }
    else
    {
 	g_print ("not found\n");
    }
}

int
main (int argc, char **argv)
{
    ElfParser *elf;
    const char *build_id;
    const char *filename;

    if (argc == 1)
	filename = "/usr/lib/libgtk-x11-2.0.so";
    else
	filename = argv[1];

    elf = elf_parser_new (filename, NULL);

    if (!elf)
    {
	g_print ("NO ELF!!!!\n");
	return -1;
    }

    build_id = elf_parser_get_build_id (elf);

    g_print ("build ID: %s\n", build_id);
    
    elf_parser_get_crc32 (elf);
    
#if 0
    for (i = 0; i < 5000000; ++i)
#endif
    {
	elf_parser_get_crc32 (elf);
	check (elf, 0x077c80f0 - (0x07787000 - 0)); /* gtk_about_dialog_set_artists  (add - (map - offset)) */
	
	check (elf, 0x077c80f0 - (0x07787000 - 0)); /* same (but in the middle of the function */
    }
    return 0;
}