mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-09 22:50:54 +00:00
New function
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk> * elfparser.c (elf_parser_new_from_file): New function
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
1b72901c4d
commit
7d8f3c232d
@ -1,3 +1,7 @@
|
|||||||
|
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
|
* elfparser.c (elf_parser_new_from_file): New function
|
||||||
|
|
||||||
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk>
|
2006-08-20 Soren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* elfparser.c (elf_parser_get_debug_link): New function
|
* elfparser.c (elf_parser_get_debug_link): New function
|
||||||
|
|||||||
28
elfparser.c
28
elfparser.c
@ -36,6 +36,8 @@ struct ElfParser
|
|||||||
int n_symbols;
|
int n_symbols;
|
||||||
ElfSym * symbols;
|
ElfSym * symbols;
|
||||||
gsize sym_strings;
|
gsize sym_strings;
|
||||||
|
|
||||||
|
GMappedFile * file;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean parse_elf_signature (const guchar *data, gsize length,
|
static gboolean parse_elf_signature (const guchar *data, gsize length,
|
||||||
@ -164,6 +166,29 @@ elf_parser_new (const guchar *data, gsize length)
|
|||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElfParser *
|
||||||
|
elf_parser_new_from_file (const char *filename,
|
||||||
|
GError **err)
|
||||||
|
{
|
||||||
|
const guchar *data;
|
||||||
|
gsize length;
|
||||||
|
ElfParser *parser;
|
||||||
|
|
||||||
|
GMappedFile *file = g_mapped_file_new (filename, FALSE, NULL);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
data = (guchar *)g_mapped_file_get_contents (file);
|
||||||
|
length = g_mapped_file_get_length (file);
|
||||||
|
|
||||||
|
parser = elf_parser_new (data, length);
|
||||||
|
|
||||||
|
parser->file = file;
|
||||||
|
|
||||||
|
return parser;
|
||||||
|
}
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
elf_parser_get_crc32 (ElfParser *parser)
|
elf_parser_get_crc32 (ElfParser *parser)
|
||||||
{
|
{
|
||||||
@ -238,6 +263,9 @@ elf_parser_free (ElfParser *parser)
|
|||||||
for (i = 0; i < parser->n_sections; ++i)
|
for (i = 0; i < parser->n_sections; ++i)
|
||||||
section_free (parser->sections[i]);
|
section_free (parser->sections[i]);
|
||||||
g_free (parser->sections);
|
g_free (parser->sections);
|
||||||
|
|
||||||
|
if (parser->file)
|
||||||
|
g_mapped_file_free (parser->file);
|
||||||
|
|
||||||
g_free (parser);
|
g_free (parser);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@ typedef struct ElfParser ElfParser;
|
|||||||
|
|
||||||
ElfParser *elf_parser_new (const guchar *data,
|
ElfParser *elf_parser_new (const guchar *data,
|
||||||
gsize length);
|
gsize length);
|
||||||
|
ElfParser *elf_parser_new_from_file (const char *filename,
|
||||||
|
GError **err);
|
||||||
void elf_parser_free (ElfParser *parser);
|
void elf_parser_free (ElfParser *parser);
|
||||||
|
|
||||||
/* Lookup a symbol in the file.
|
/* Lookup a symbol in the file.
|
||||||
|
|||||||
18
testelf.c
18
testelf.c
@ -33,16 +33,22 @@ check (ElfParser *elf, gulong addr)
|
|||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
GMappedFile *libgtk = g_mapped_file_new ("/usr/lib/libgtk-x11-2.0.so",
|
ElfParser *elf;
|
||||||
FALSE, NULL);
|
|
||||||
ElfParser *elf = elf_parser_new (
|
|
||||||
g_mapped_file_get_contents (libgtk),
|
|
||||||
g_mapped_file_get_length (libgtk));
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
elf = elf_parser_new_from_file ("/usr/lib/libgtk-x11-2.0.so", NULL);
|
||||||
|
|
||||||
|
if (!elf)
|
||||||
|
{
|
||||||
|
g_print ("NO ELF!!!!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
elf_parser_get_crc32 (elf);
|
||||||
|
|
||||||
for (i = 0; i < 5000000; ++i)
|
for (i = 0; i < 5000000; ++i)
|
||||||
{
|
{
|
||||||
|
elf_parser_get_crc32 (elf);
|
||||||
check (elf, 0x077c80f0 - (0x07787000 - 0)); /* gtk_about_dialog_set_artists (add - (map - offset)) */
|
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 */
|
check (elf, 0x077c80f0 - (0x07787000 - 0)); /* same (but in the middle of the function */
|
||||||
|
|||||||
Reference in New Issue
Block a user