PARSE_ELF_BIN_TARGET=parse_elf
PARSE_ELF_HEADER=parse_elf.h
+WARN_CFLAGS= -Werror -Wall -Wextra
CFLAGS=-fPIC
+CFLAGS+=$(WARN_CFLAGS)
PARSE_ELF_LIB_SRC=lib_parse_elf.c
PARSE_ELF_BIN_SRC=parse_elf.c
#include <string.h>
#include <stdio.h>
#include <regex.h>
+#include <unistd.h>
#include <stdbool.h>
#include <malloc.h>
#include <search.h>
return NULL;
}
-static const Elf_Shdr *get_section_by_type(const void *elf, Elf_Word sh_type)
-{
- const Elf_Ehdr *elf_header = elf;
- const Elf_Shdr *section_table = elf + elf_header->e_shoff;
- int i;
-
- for (i = 0; i != elf_header->e_shnum; ++i) {
- const Elf_Shdr *entry = section_table + i;
- if (entry->sh_type == sh_type)
- return entry;
- }
- return NULL;
-}
-
static void __do_free_sym_entry(struct sym_table_entry *entry)
{
if (entry == NULL)
const char *name;
Elf_Addr addr;
unsigned int type;
- int entries_num;
- int i, j;
+ size_t i, j, entries_num;
struct sym_table_entry *first = NULL, *elem = NULL, *prev = NULL;
regex_t regex;
const Elf_Shdr *shdr;
const Elf_Sym *sym_table;
const char* name;
- int plt_table_size;
- int i, j;
+ size_t i, j, plt_table_size;
int ret = 0;
regex_t regex;
int base = got_plt_shdr->sh_addr - got_plt_shdr->sh_offset;
- int j;
+ size_t j;
for (j = 0; j < n; j++) {
if (addrs[j])
addrs[j] = *(Elf_Addr *)(elf + addrs[j] - base) - 6;
const char *get_str_error(int err)
{
- char *str;
+ const char *str;
switch (err) {
case ELF_PARSE_SUCCESS:
unsigned long get_addr_by_name(struct sym_table_entry *entry, const char *name)
{
- struct sym_table_entry *first;
size_t len_one, len_two, len;
- first = entry;
-
do {
len_one = strlen(entry->name);
len_two = strlen(name);
void print_sym_table(struct sym_table_entry *entry,int fast)
{
- struct sym_table_entry *first;
- int i;
-
if (!entry)
return;
- first = entry;
-
do {
if (!(fast && entry->addr == 0))
printf("%08x %s %s\n", entry->addr, name_by_type(entry->type), entry->name);
void print_sym_addrs(struct sym_table_entry *entry, const char **names,
size_t len)
{
- int i;
- int addr;
+ size_t i;
if (!entry)
return;
for (i = 0; i < len; i++)
- printf("%08x\n", get_addr_by_name(entry, names[i]));
+ printf("%08lx\n", get_addr_by_name(entry, names[i]));
}
void clean_syms(struct sym_table_entry *entry)
int main(int argc, char **argv)
{
const char *filename = argv[1];
- size_t entries_num = 0;
- int i;
+ size_t i, entries_num = 0;
int ret = 0;
/* TODO fix coding style */