; System Call - 1 Argument
%macro SYSCALL1 2
_SYSCALL_HEAD %1, %2
- mov rdi, [rbp+2*8]
+; mov rdi, [rbp+3*8]
SYSCALL_OP
_SYSCALL_TAIL
%endmacro
; System Call - 2 Arguments
%macro SYSCALL2 2
_SYSCALL_HEAD %1, %2
- mov rdi, [rbp+2*8]
- mov rsi, [rbp+3*8]
+; mov rdi, [rbp+3*8]
+; mov rsi, [rbp+4*8]
SYSCALL_OP
_SYSCALL_TAIL
%endmacro
; System Call - 3 Arguments
%macro SYSCALL3 2
_SYSCALL_HEAD %1, %2
-; mov rdi, [rbp+2*8]
-; mov rsi, [rbp+3*8]
-; mov rdx, [rbp+4*8]
+; mov rdi, [rbp+3*8]
+; mov rsi, [rbp+4*8]
+; mov rdx, [rbp+5*8]
SYSCALL_OP
_SYSCALL_TAIL
%endmacro
void *pltrel = NULL;
int plt_size = 0, plt_type = 0;
- DEBUGS("Elf64Relocate: e_ident = '%.16s'", hdr->e_ident);
- DEBUGS("Elf64Relocate: e_phoff = %i, e_phnum = %i",
- hdr->e_phoff, hdr->e_phnum);
+ DEBUGS("Elf64Relocate: hdr = {");
+ DEBUGS("Elf64Relocate: e_ident = '%.16s'", hdr->e_ident);
+ DEBUGS("Elf64Relocate: e_type = 0x%x", hdr->e_type);
+ DEBUGS("Elf64Relocate: e_machine = 0x%x", hdr->e_machine);
+ DEBUGS("Elf64Relocate: e_version = 0x%x", hdr->e_version);
+ DEBUGS("Elf64Relocate: e_entry = %p", hdr->e_entry);
+ DEBUGS("Elf64Relocate: e_phoff = 0x%llx", hdr->e_phoff);
+ DEBUGS("Elf64Relocate: e_shoff = 0x%llx", hdr->e_shoff);
+ DEBUGS("Elf64Relocate: e_flags = 0x%x", hdr->e_flags);
+ DEBUGS("Elf64Relocate: e_ehsize = 0x%x", hdr->e_ehsize);
+ DEBUGS("Elf64Relocate: e_phentsize = 0x%x", hdr->e_phentsize);
+ DEBUGS("Elf64Relocate: e_phnum = %i", hdr->e_phnum);
// Scan for the dynamic table (and find the compiled base)
phtab = Base + hdr->e_phoff;
// Second pass on dynamic table
for(i = 0; dyntab[i].d_tag != DT_NULL; i ++)
{
+ DEBUGS("dyntab[%i].d_tag = %i", i, dyntab[i].d_tag);
switch(dyntab[i].d_tag)
{
case DT_SONAME: break;
case DT_NEEDED: {
char *libPath = strtab + dyntab[i].d_un.d_val;
+ DEBUGS("Elf64Relocate: libPath = '%s'", libPath);
if(LoadLibrary(libPath, NULL, envp) == 0) {
SysDebug("ld-acess - Elf64Relocate: Unable to load '%s'", libPath);
return NULL;
break;
default:
SysDebug("ld-acess - _Elf64DoReloc: Unknown relocation type %i", type);
+ break;
}
}
if( rel )
{
+ DEBUGS("rel_count = %i", rel_count);
for( i = 0; i < rel_count; i ++ )
{
uint64_t *ptr = (void *)( rel[i].r_offset + baseDiff );
if( rela )
{
+ DEBUGS("rela_count = %i", rela_count);
for( i = 0; i < rela_count; i ++ )
{
_Elf64DoReloc( rela[i].r_info, (void *)( rela[i].r_offset + baseDiff ), rela[i].r_addend );
if( plt_type == DT_REL ) {
Elf64_Rel *plt = pltrel;
int count = plt_size / sizeof(Elf64_Rel);
+ DEBUGS("plt rel count = %i", count);
for( i = 0; i < count; i ++ )
{
uint64_t *ptr = (void *)( plt[i].r_offset + baseDiff );
else {
Elf64_Rela *plt = pltrel;
int count = plt_size / sizeof(Elf64_Rela);
+ DEBUGS("plt rela count = %i", count);
for( i = 0; i < count; i ++ )
{
_Elf64DoReloc( plt[i].r_info, (void *)(plt[i].r_offset + baseDiff), plt[i].r_addend);
}
}
+ DEBUGS("Elf64Relocate: Relocations done, return %p", (void *)(hdr->e_entry + baseDiff));
return (void *)(hdr->e_entry + baseDiff);
}
typedef uint16_t Elf64_Half;
typedef uint32_t Elf64_Word;
+
typedef uint64_t Elf64_Addr;
typedef uint64_t Elf64_Off;
typedef uint64_t Elf64_Xword;
Elf64_Half e_shentsize;
Elf64_Half e_shnum;
Elf64_Half e_shstrndx;
-} Elf64_Ehdr;
+} __attribute__((packed)) Elf64_Ehdr;
typedef struct
{
int file_exists(const char *filename)
{
int fd;
- //fd = open(filename, OPENFLAG_READ);
- fd = open(filename, 0);
- if(fd == -1) return 0;
- close(fd);
- return 1;
+ //fd = open(filename, OPENFLAG_READ);
+ fd = open(filename, 0);
+ if(fd == -1) return 0;
+ close(fd);
+ return 1;
}
*/
#include "common.h"
-#define DEBUG 0
+#define DEBUG 1
#if DEBUG
# define DEBUGS(v...) SysDebug(v)
void *base;
void (*fEntry)(void *, int, char *[], char**);
- DEBUGS("LoadLibrary: (filename='%s', envp=0x%x)\n", filename, envp);
+ DEBUGS("LoadLibrary: (SoName='%s', SearchDir='%s', envp=0x%x)", SoName, SearchDir, envp);
// Create Temp Name
filename = FindLibrary(sTmpName, SoName, SearchDir);
if(filename == NULL) {
- DEBUGS("LoadLibrary: RETURN 0\n");
+ DEBUGS("LoadLibrary: RETURN 0");
return 0;
}
- DEBUGS(" LoadLibrary: filename='%s'\n", filename);
+ DEBUGS(" LoadLibrary: filename='%s'", filename);
if( (base = IsFileLoaded(filename)) )
return base;
-
+
+ DEBUGS(" LoadLibrary: SysLoadBin()");
// Load Library
base = SysLoadBin(filename, (void**)&fEntry);
if(!base) {
- DEBUGS("LoadLibrary: RETURN 0\n");
+ DEBUGS("LoadLibrary: RETURN 0");
return 0;
}
- DEBUGS(" LoadLibrary: iArg=%p, iEntry=0x%x\n", base, fEntry);
+ DEBUGS(" LoadLibrary: iArg=%p, iEntry=0x%x", base, fEntry);
// Load Symbols
fEntry = DoRelocate( base, envp, filename );
// Call Entrypoint
- DEBUGS(" LoadLibrary: '%s' Entry 0x%x\n", SoName, fEntry);
+ DEBUGS(" LoadLibrary: '%s' Entry 0x%x", SoName, fEntry);
fEntry(base, 0, NULL, envp);
- DEBUGS("LoadLibrary: RETURN 1\n");
+ DEBUGS("LoadLibrary: RETURN 1");
return base;
}
strcpy(name, File);
gLoadedLibraries[i].Name = name;
gsNextAvailString = &name[length+1];
- DEBUGS("'%s' (0x%x) loaded as %i\n", name, base, i);
+ DEBUGS("'%s' (0x%x) loaded as %i", name, base, i);
return;
}
//typedef unsigned int uint;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
-typedef unsigned long uint32_t;
+typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef signed short int16_t;
-typedef signed long int32_t;
+typedef signed int int32_t;
typedef signed long long int64_t;
#ifdef __LP64__