22 extern void writeStr(
const char *str);
23 int StringCopyN(
char *dest,
const char *src,
int len)
32 int ByteSet(
void *buf,
int c,
size_t len)
34 unsigned char *tmp = (
unsigned char *) buf;
41 void MemoryCopy(
void *dest,
const void *src,
size_t len)
43 const unsigned char *sp = (
const unsigned char *) src;
44 unsigned char *dp = (
unsigned char *) dest;
45 for (; len != 0; len--)
49 int StringCompare(
const char *p1,
const char *p2)
53 while (p1[i] !=
'\0' && p2[i] !=
'\0')
63 if ((p1[i] ==
'\0' && p2[i] !=
'\0') || (p1[i] !=
'\0' && p2[i] ==
'\0'))
70 : m_pHeader(0), m_pSymbolTable(0), m_pStringTable(0), m_pShstrtab(0),
71 m_pGotTable(0), m_pRelTable(0), m_pSectionHeaders(0), m_pBuffer(0)
73 StringCopyN(m_pId, name, 127);
80 bool Elf32::load(uint8_t *pBuffer,
unsigned int nBufferLength)
83 m_pHeader =
reinterpret_cast<Elf32Header_t *
>(pBuffer);
86 if ((m_pHeader->ident[1] !=
'E') || (m_pHeader->ident[2] !=
'L') ||
87 (m_pHeader->ident[3] !=
'F') || (m_pHeader->ident[0] != 127))
89 m_pHeader = (Elf32Header_t *) 0;
95 reinterpret_cast<Elf32SectionHeader_t *
>(&pBuffer[m_pHeader->shoff]);
98 m_pStringTable = &m_pSectionHeaders[m_pHeader->shstrndx];
101 const char *pStrtab =
102 reinterpret_cast<const char *
>(&pBuffer[m_pStringTable->offset]);
105 for (
int i = 0; i < m_pHeader->shnum; i++)
107 const char *pStr = pStrtab + m_pSectionHeaders[i].name;
108 if (!StringCompare(pStr,
".symtab"))
110 m_pSymbolTable = &m_pSectionHeaders[i];
112 if (!StringCompare(pStr,
".strtab"))
113 m_pStringTable = &m_pSectionHeaders[i];
165 for (
int i = 0; i < m_pHeader->shnum; i++)
167 if (m_pSectionHeaders[i].flags & SHF_ALLOC)
169 if (m_pSectionHeaders[i].type != SHT_NOBITS)
173 (uint8_t *) m_pSectionHeaders[i].addr,
175 m_pSectionHeaders[i].size);
180 (uint8_t *) m_pSectionHeaders[i].addr, 0,
181 m_pSectionHeaders[i].size);
193 if (!m_pSymbolTable || !m_pStringTable)
197 Elf32Symbol_t *pSymbol =
198 reinterpret_cast<Elf32Symbol_t *
>(&
m_pBuffer[m_pSymbolTable->offset]);
199 const char *pStrtab =
200 reinterpret_cast<const char *
>(&
m_pBuffer[m_pStringTable->offset]);
202 for (
size_t i = 0; i < m_pSymbolTable->size /
sizeof(Elf32Symbol_t); i++)
205 if (ELF32_ST_TYPE(pSymbol->info) != 0x2 &&
206 ELF32_ST_TYPE(pSymbol->info) != 0x0 )
214 uint32_t size = pSymbol->size;
217 if ((addr >= pSymbol->value) && (addr < (pSymbol->value + size)))
219 const char *pStr = pStrtab + pSymbol->name;
221 *startAddr = pSymbol->value;
226 return (
const char *) 3;
243 return m_pHeader->entry;
unsigned int getLastAddress()
uint32_t getGlobalOffsetTable()
const char * lookupSymbol(unsigned int addr, unsigned int *startAddr=0)
char * lookupDynamicSymbolName(uint32_t off)
uint32_t lookupDynamicSymbolAddress(uint32_t off)
uint8_t * m_pBuffer
Offset of the file in memory.
bool load(uint8_t *pBuffer, unsigned int nBufferLength)