- Elf32_Ehdr *hdr = Base;
- Elf32_Phdr *phtab;
- int i, j; // Counters
- char *libPath;
- intptr_t iRealBase = -1;
- intptr_t iBaseDiff;
- int iSegmentCount;
-// int iSymCount;
- Elf32_Rel *rel = NULL;
- Elf32_Rela *rela = NULL;
- void *plt = NULL;
- int relSz=0, relEntSz=8;
- int relaSz=0, relaEntSz=8;
- int pltSz=0, pltType=0;
- Elf32_Dyn *dynamicTab = NULL; // Dynamic Table Pointer
- char *dynstrtab = NULL; // .dynamic String Table
- Elf32_Sym *dynsymtab;
- int (*do_relocate)(uint32_t t_info, uint32_t *ptr, Elf32_Addr addend, int Type, int bRela, const char *Sym, intptr_t iBaseDiff);
-
- DEBUGS("ElfRelocate: (Base=0x%x)", Base);
-
- // Check magic header
-
-
- // Parse Program Header to get Dynamic Table
- phtab = (void*)( (uintptr_t)Base + hdr->phoff );
- iSegmentCount = hdr->phentcount;
- for(i=0;i<iSegmentCount;i++)
- {
- // Determine linked base address
- if(phtab[i].Type == PT_LOAD && iRealBase > phtab[i].VAddr)
- iRealBase = phtab[i].VAddr;
-
- // Find Dynamic Section
- if(phtab[i].Type == PT_DYNAMIC) {
- if(dynamicTab) {
- DEBUGS(" WARNING - elf_relocate: Multiple PT_DYNAMIC segments");
- continue;
- }
- dynamicTab = (void *) (intptr_t) phtab[i].VAddr;
- j = i; // Save Dynamic Table ID
- }
- }
-
- // Page Align real base
- iRealBase &= ~0xFFF;
- DEBUGS(" elf_relocate: True Base = 0x%x, Compiled Base = 0x%x", Base, iRealBase);
-
- // Adjust "Real" Base
- iBaseDiff = (intptr_t)Base - iRealBase;
-
-// hdr->entrypoint += iBaseDiff; // Adjust Entrypoint
-
- // Check if a PT_DYNAMIC segement was found
- if(!dynamicTab) {
- SysDebug(" elf_relocate: No PT_DYNAMIC segment in image %p, returning", Base);
- return (void *)(intptr_t)(hdr->entrypoint + iBaseDiff);
- }
-
- // Allow writing to read-only segments, just in case they need to be relocated
- // - Will be reversed at the end of the function
- for( i = 0; i < iSegmentCount; i ++ )