2010-01-05 04:21:45 +00:00
|
|
|
/* MSPDebug - debugging tool for the eZ430
|
2010-01-08 08:17:24 +00:00
|
|
|
* Copyright (C) 2009, 2010 Daniel Beer
|
2010-01-05 04:21:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2010-03-27 09:50:02 +00:00
|
|
|
#include <stdlib.h>
|
2010-01-05 04:21:45 +00:00
|
|
|
#include <string.h>
|
2011-07-26 13:51:06 +00:00
|
|
|
|
2010-05-15 03:13:58 +00:00
|
|
|
#include "elf32.h"
|
2011-07-26 22:35:46 +00:00
|
|
|
#include "elf_format.h"
|
2010-08-16 23:07:03 +00:00
|
|
|
#include "output.h"
|
2011-07-26 13:51:06 +00:00
|
|
|
#include "util.h"
|
2010-01-05 04:21:45 +00:00
|
|
|
|
2010-05-11 22:13:39 +00:00
|
|
|
#ifndef EM_MSP430
|
2010-01-05 04:21:45 +00:00
|
|
|
#define EM_MSP430 0x69
|
2010-05-11 22:13:39 +00:00
|
|
|
#endif
|
2010-01-05 04:21:45 +00:00
|
|
|
|
2010-05-13 00:57:21 +00:00
|
|
|
static const uint8_t elf32_id[] = {
|
2010-01-05 04:21:45 +00:00
|
|
|
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ELFCLASS32
|
|
|
|
};
|
|
|
|
|
2019-09-20 14:18:51 +00:00
|
|
|
#define MAX_PHDRS 128
|
|
|
|
#define MAX_SHDRS 512
|
2010-01-05 04:21:45 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
struct elf32_info {
|
|
|
|
Elf32_Ehdr file_ehdr;
|
|
|
|
Elf32_Phdr file_phdrs[MAX_PHDRS];
|
|
|
|
Elf32_Shdr file_shdrs[MAX_SHDRS];
|
2010-01-05 04:21:45 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
char *string_tab;
|
|
|
|
int string_len;
|
|
|
|
};
|
2010-03-27 09:50:02 +00:00
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
static int parse_ehdr(Elf32_Ehdr *e, FILE *in)
|
|
|
|
{
|
|
|
|
uint8_t data[52];
|
|
|
|
|
|
|
|
if (fread(data, sizeof(data), 1, in) != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memcpy(e->e_ident, data, EI_NIDENT);
|
|
|
|
e->e_type = LE_WORD(data, 16);
|
|
|
|
e->e_machine = LE_WORD(data, 18);
|
|
|
|
e->e_version = LE_LONG(data, 20);
|
|
|
|
e->e_entry = LE_LONG(data, 24);
|
|
|
|
e->e_phoff = LE_LONG(data, 28);
|
|
|
|
e->e_shoff = LE_LONG(data, 32);
|
|
|
|
e->e_flags = LE_LONG(data, 36);
|
|
|
|
e->e_ehsize = LE_WORD(data, 40);
|
|
|
|
e->e_phentsize = LE_WORD(data, 42);
|
|
|
|
e->e_phnum = LE_WORD(data, 44);
|
|
|
|
e->e_shentsize = LE_WORD(data, 46);
|
|
|
|
e->e_shnum = LE_WORD(data, 48);
|
|
|
|
e->e_shstrndx = LE_WORD(data, 50);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_phdr(Elf32_Phdr *p, FILE *in)
|
|
|
|
{
|
|
|
|
uint8_t data[32];
|
|
|
|
|
|
|
|
if (fread(data, sizeof(data), 1, in) != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
p->p_type = LE_LONG(data, 0);
|
|
|
|
p->p_offset = LE_LONG(data, 4);
|
|
|
|
p->p_vaddr = LE_LONG(data, 8);
|
|
|
|
p->p_paddr = LE_LONG(data, 12);
|
|
|
|
p->p_filesz = LE_LONG(data, 16);
|
|
|
|
p->p_memsz = LE_LONG(data, 20);
|
|
|
|
p->p_flags = LE_LONG(data, 24);
|
|
|
|
p->p_align = LE_LONG(data, 28);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_shdr(Elf32_Shdr *s, FILE *in)
|
|
|
|
{
|
|
|
|
uint8_t data[40];
|
|
|
|
|
|
|
|
if (fread(data, sizeof(data), 1, in) != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
s->sh_name = LE_LONG(data, 0);
|
|
|
|
s->sh_type = LE_LONG(data, 4);
|
|
|
|
s->sh_flags = LE_LONG(data, 8);
|
|
|
|
s->sh_addr = LE_LONG(data, 12);
|
|
|
|
s->sh_offset = LE_LONG(data, 16);
|
|
|
|
s->sh_size = LE_LONG(data, 20);
|
|
|
|
s->sh_link = LE_LONG(data, 24);
|
|
|
|
s->sh_info = LE_LONG(data, 28);
|
|
|
|
s->sh_addralign = LE_LONG(data, 32);
|
|
|
|
s->sh_entsize = LE_LONG(data, 36);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_sym(Elf32_Sym *s, FILE *in)
|
|
|
|
{
|
|
|
|
uint8_t data[16];
|
|
|
|
|
|
|
|
if (fread(data, sizeof(data), 1, in) != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
s->st_name = LE_LONG(data, 0);
|
|
|
|
s->st_value = LE_LONG(data, 4);
|
|
|
|
s->st_size = LE_LONG(data, 8);
|
|
|
|
s->st_info = data[12];
|
|
|
|
s->st_other = data[13];
|
|
|
|
s->st_shndx = LE_WORD(data, 14);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int read_ehdr(struct elf32_info *info, FILE *in)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
|
|
|
/* Read and check the ELF header */
|
|
|
|
rewind(in);
|
2012-05-09 22:00:58 +00:00
|
|
|
if (parse_ehdr(&info->file_ehdr, in) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("elf32: couldn't read ELF header");
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (memcmp(info->file_ehdr.e_ident, elf32_id, sizeof(elf32_id))) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: not an ELF32 file\n");
|
2010-04-30 10:09:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-05 04:21:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int read_phdr(struct elf32_info *info, FILE *in)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (info->file_ehdr.e_phnum > MAX_PHDRS) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: too many program headers: %d\n",
|
2010-04-30 10:09:57 +00:00
|
|
|
info->file_ehdr.e_phnum);
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
for (i = 0; i < info->file_ehdr.e_phnum; i++) {
|
|
|
|
if (fseek(in, i * info->file_ehdr.e_phentsize +
|
|
|
|
info->file_ehdr.e_phoff,
|
2010-01-05 04:21:45 +00:00
|
|
|
SEEK_SET) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: can't seek to phdr %d\n", i);
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
if (parse_phdr(&info->file_phdrs[i], in) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: can't read phdr %d: %s\n",
|
2011-07-26 13:51:06 +00:00
|
|
|
i, last_error());
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int read_shdr(struct elf32_info *info, FILE *in)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (info->file_ehdr.e_shnum > MAX_SHDRS) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: too many section headers: %d\n",
|
2010-04-30 10:09:57 +00:00
|
|
|
info->file_ehdr.e_shnum);
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
for (i = 0; i < info->file_ehdr.e_shnum; i++) {
|
|
|
|
if (fseek(in, i * info->file_ehdr.e_shentsize +
|
|
|
|
info->file_ehdr.e_shoff,
|
2010-01-05 04:21:45 +00:00
|
|
|
SEEK_SET) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: can't seek to shdr %d\n", i);
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
if (parse_shdr(&info->file_shdrs[i], in) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: can't read shdr %d: %s\n",
|
2011-07-26 13:51:06 +00:00
|
|
|
i, last_error());
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-13 00:57:21 +00:00
|
|
|
static uint32_t file_to_phys(struct elf32_info *info, uint32_t v)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
for (i = 0; i < info->file_ehdr.e_phnum; i++) {
|
|
|
|
Elf32_Phdr *p = &info->file_phdrs[i];
|
2010-01-05 04:21:45 +00:00
|
|
|
|
|
|
|
if (v >= p->p_offset && v - p->p_offset < p->p_filesz)
|
|
|
|
return v - p->p_offset + p->p_paddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int feed_section(struct elf32_info *info,
|
2011-10-12 00:52:56 +00:00
|
|
|
FILE *in, const Elf32_Shdr *sh,
|
2010-08-05 04:12:35 +00:00
|
|
|
binfile_imgcb_t cb, void *user_data)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
2011-10-12 00:52:56 +00:00
|
|
|
uint32_t offset = sh->sh_offset;
|
|
|
|
uint32_t size = sh->sh_size;
|
2010-05-13 00:57:21 +00:00
|
|
|
uint8_t buf[1024];
|
2010-08-05 04:12:35 +00:00
|
|
|
uint32_t addr = file_to_phys(info, offset);
|
2011-10-12 00:52:56 +00:00
|
|
|
const char *name = NULL;
|
2010-01-05 04:21:45 +00:00
|
|
|
|
|
|
|
if (fseek(in, offset, SEEK_SET) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("elf32: can't seek to section");
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
if (info->string_tab &&
|
|
|
|
sh->sh_name < info->string_len)
|
|
|
|
name = info->string_tab + sh->sh_name;
|
|
|
|
|
2010-01-05 04:21:45 +00:00
|
|
|
while (size) {
|
|
|
|
int ask = size > sizeof(buf) ? sizeof(buf) : size;
|
|
|
|
int len = fread(buf, 1, ask, in);
|
2011-10-12 00:52:56 +00:00
|
|
|
struct binfile_chunk ch = {0};
|
2010-01-05 04:21:45 +00:00
|
|
|
|
|
|
|
if (len < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("elf32: can't read section");
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
ch.name = name;
|
|
|
|
ch.addr = addr;
|
|
|
|
ch.data = buf;
|
|
|
|
ch.len = len;
|
|
|
|
|
|
|
|
if (cb(user_data, &ch) < 0)
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
size -= len;
|
|
|
|
offset += len;
|
|
|
|
addr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int read_all(struct elf32_info *info, FILE *in)
|
2010-01-05 04:21:45 +00:00
|
|
|
{
|
2014-02-09 07:32:47 +00:00
|
|
|
memset(info, 0, sizeof(*info));
|
2010-04-30 10:09:57 +00:00
|
|
|
|
|
|
|
if (read_ehdr(info, in) < 0)
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
2010-05-27 01:58:00 +00:00
|
|
|
|
|
|
|
if (info->file_ehdr.e_machine != EM_MSP430)
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: warning: unknown machine type: 0x%x\n",
|
2010-05-27 01:58:00 +00:00
|
|
|
info->file_ehdr.e_machine);
|
2010-01-05 04:21:45 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (read_phdr(info, in) < 0)
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
2010-04-30 10:09:57 +00:00
|
|
|
if (read_shdr(info, in) < 0)
|
2010-01-05 04:21:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-01-05 11:09:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
static int load_strings(struct elf32_info *info, FILE *in, Elf32_Shdr *s)
|
|
|
|
{
|
|
|
|
int len = s->sh_size;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (fseek(in, s->sh_offset, SEEK_SET) < 0) {
|
|
|
|
pr_error("elf32: can't seek to strings");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->string_len = len;
|
|
|
|
info->string_tab = malloc(len + 1);
|
|
|
|
|
|
|
|
if (!info->string_tab) {
|
|
|
|
pr_error("elf32: can't allocate string table memory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
if (!fread(info->string_tab, info->string_len, 1, in)) {
|
2011-10-12 00:52:56 +00:00
|
|
|
if (ferror(in)) {
|
|
|
|
pr_error("elf32: error reading strings");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printc_err("elf32: eof reading strings\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->string_tab[info->string_len] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-15 03:13:58 +00:00
|
|
|
int elf32_extract(FILE *in, binfile_imgcb_t cb, void *user_data)
|
2010-01-05 11:09:08 +00:00
|
|
|
{
|
2010-04-30 10:09:57 +00:00
|
|
|
struct elf32_info info;
|
2010-01-05 11:09:08 +00:00
|
|
|
int i;
|
2011-10-12 00:52:56 +00:00
|
|
|
int ret = 0;
|
2010-01-05 11:09:08 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (read_all(&info, in) < 0)
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
if (load_strings(&info, in,
|
|
|
|
&info.file_shdrs[info.file_ehdr.e_shstrndx]) < 0) {
|
|
|
|
printc_err("elf32: warning: can't load section string "
|
|
|
|
"table\n");
|
|
|
|
info.string_tab = NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
for (i = 0; i < info.file_ehdr.e_shnum; i++) {
|
|
|
|
Elf32_Shdr *s = &info.file_shdrs[i];
|
2010-01-05 04:21:45 +00:00
|
|
|
|
|
|
|
if (s->sh_type == SHT_PROGBITS && s->sh_flags & SHF_ALLOC &&
|
2012-07-18 02:00:16 +00:00
|
|
|
feed_section(&info, in, s, cb, user_data) < 0) {
|
2011-10-12 00:52:56 +00:00
|
|
|
ret = -1;
|
2012-07-18 02:00:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-01-05 04:21:45 +00:00
|
|
|
}
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
if (info.string_tab)
|
|
|
|
free(info.string_tab);
|
|
|
|
|
|
|
|
return ret;
|
2010-01-05 04:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int elf32_check(FILE *in)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rewind(in);
|
|
|
|
for (i = 0; i < sizeof(elf32_id); i++)
|
|
|
|
if (fgetc(in) != elf32_id[i])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2010-01-05 11:09:08 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static Elf32_Shdr *find_shdr(struct elf32_info *info, Elf32_Word type)
|
2010-01-05 11:09:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
for (i = 0; i < info->file_ehdr.e_shnum; i++) {
|
|
|
|
Elf32_Shdr *s = &info->file_shdrs[i];
|
2010-01-05 11:09:08 +00:00
|
|
|
|
|
|
|
if (s->sh_type == type)
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define N_SYMS 128
|
|
|
|
|
2011-02-21 20:49:53 +00:00
|
|
|
#ifndef STT_COMMON
|
|
|
|
#define STT_COMMON 5
|
|
|
|
#endif
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
static int syms_load_syms(struct elf32_info *info, FILE *in,
|
2011-03-15 02:20:50 +00:00
|
|
|
Elf32_Shdr *s)
|
2010-01-05 11:09:08 +00:00
|
|
|
{
|
2012-05-09 22:00:58 +00:00
|
|
|
int len = s->sh_size / 16;
|
|
|
|
int i;
|
2010-01-05 11:09:08 +00:00
|
|
|
|
|
|
|
if (fseek(in, s->sh_offset, SEEK_SET) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("elf32: can't seek to symbols");
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
Elf32_Sym y;
|
|
|
|
int st;
|
|
|
|
const char *name;
|
2010-01-05 11:09:08 +00:00
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
if (parse_sym(&y, in) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("elf32: error reading symbols");
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
st = ELF32_ST_TYPE(y.st_info);
|
|
|
|
name = info->string_tab + y.st_name;
|
|
|
|
|
|
|
|
if (y.st_name > info->string_len) {
|
|
|
|
printc_err("elf32: symbol out of bounds\n");
|
|
|
|
return -1;
|
2010-01-05 11:09:08 +00:00
|
|
|
}
|
2010-03-27 09:50:02 +00:00
|
|
|
|
2012-05-09 22:00:58 +00:00
|
|
|
if (name[0] &&
|
|
|
|
(st == STT_OBJECT || st == STT_FUNC ||
|
|
|
|
st == STT_SECTION || st == STT_COMMON ||
|
|
|
|
st == STT_TLS) &&
|
|
|
|
stab_set(info->string_tab + y.st_name,
|
|
|
|
y.st_value) < 0)
|
|
|
|
return -1;
|
2010-01-05 11:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-15 02:20:50 +00:00
|
|
|
int elf32_syms(FILE *in)
|
2010-01-05 11:09:08 +00:00
|
|
|
{
|
2010-04-30 10:09:57 +00:00
|
|
|
struct elf32_info info;
|
2010-01-05 11:09:08 +00:00
|
|
|
Elf32_Shdr *s;
|
2010-04-30 10:09:57 +00:00
|
|
|
int ret = 0;
|
2010-01-05 11:09:08 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (read_all(&info, in) < 0)
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
s = find_shdr(&info, SHT_SYMTAB);
|
2010-01-05 11:09:08 +00:00
|
|
|
if (!s) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: no symbol table\n");
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (s->sh_link <= 0 || s->sh_link >= info.file_ehdr.e_shnum) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("elf32: no string table\n");
|
2010-01-05 11:09:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:52:56 +00:00
|
|
|
if (load_strings(&info, in, &info.file_shdrs[s->sh_link]) < 0 ||
|
2011-03-15 02:20:50 +00:00
|
|
|
syms_load_syms(&info, in, s) < 0)
|
2010-04-30 10:09:57 +00:00
|
|
|
ret = -1;
|
2010-03-27 09:50:02 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
if (info.string_tab)
|
|
|
|
free(info.string_tab);
|
2010-01-05 11:09:08 +00:00
|
|
|
|
2010-04-30 10:09:57 +00:00
|
|
|
return ret;
|
2010-01-05 11:09:08 +00:00
|
|
|
}
|