Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed May 12, 2024
1 parent dad223d commit 667c887
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions crt/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static int (*sceKernelDlsym)(int, const char*, void*) = 0;
**/
static int
patch_sceKernelSpawn(void) {
int pid = syscall(SYS_getpid);
unsigned long loc;
unsigned long val;

Expand All @@ -49,7 +48,7 @@ patch_sceKernelSpawn(void) {
}

loc += 52;
if(mdbg_copyout(pid, loc, &val, sizeof(val))) {
if(mdbg_copyout(-1, loc, &val, sizeof(val))) {
klog_perror("mdbg_copyout");
return -1;
}
Expand All @@ -64,7 +63,7 @@ patch_sceKernelSpawn(void) {
}

val = 0x90909090a8758948l;
if(mdbg_copyin(pid, &val, loc, sizeof(val))) {
if(mdbg_copyin(-1, &val, loc, sizeof(val))) {
klog_perror("mdbg_copyin");
return -1;
}
Expand Down Expand Up @@ -107,7 +106,7 @@ patch_kernel_ucred(void) {


__attribute__((constructor(105))) static void
payload_constructor(payload_args_t *args) {
patch_constructor(payload_args_t *args) {
sceKernelDlsym = args->sceKernelDlsym;
patch_sceKernelSpawn();
patch_kernel_ucred();
Expand Down
9 changes: 3 additions & 6 deletions crt/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,11 @@ r_glob_dat(Elf64_Rela* rela) {
unsigned long loc = (unsigned long)(__image_start + rela->r_offset);
Elf64_Sym* sym = symtab + ELF64_R_SYM(rela->r_info);
const char* name = strtab + sym->st_name;
int pid = syscall(SYS_getpid);
unsigned long val = 0;

for(rtld_lib_t *lib=libhead; lib!=0; lib=lib->next) {
if((val=rtld_sym(lib, name))) {
return mdbg_copyin(pid, &val, loc, sizeof(val));
return mdbg_copyin(-1, &val, loc, sizeof(val));
}
}

Expand All @@ -430,14 +429,13 @@ static int
r_relative(Elf64_Rela* rela) {
unsigned long loc = (unsigned long)(__image_start + rela->r_offset);
unsigned long val = (unsigned long)(__image_start + rela->r_addend);
int pid = syscall(SYS_getpid);

// ELF loader allready applied relocation
if(*((unsigned long*)loc) == val) {
return 0;
}

if(mdbg_copyin(pid, &val, loc, sizeof(val))) {
if(mdbg_copyin(-1, &val, loc, sizeof(val))) {
klog_perror("mdbg_copyin");
return -1;
}
Expand All @@ -454,13 +452,12 @@ r_direct_64(Elf64_Rela* rela) {
unsigned long loc = (unsigned long)(__image_start + rela->r_offset);
Elf64_Sym* sym = symtab + ELF64_R_SYM(rela->r_info);
const char* name = strtab + sym->st_name;
int pid = syscall(SYS_getpid);
unsigned long val = 0;

for(rtld_lib_t *lib=libhead; lib!=0; lib=lib->next) {
if((val=rtld_sym(lib, name))) {
val += rela->r_addend;
return mdbg_copyin(pid, &val, loc, sizeof(val));
return mdbg_copyin(-1, &val, loc, sizeof(val));
}
}

Expand Down

0 comments on commit 667c887

Please sign in to comment.