mirror of
https://github.com/ps5-payload-dev/elfldr.git
synced 2026-10-19 02:19:52 -05:00
cosmetics
This commit is contained in:
1 parent
5de9433fc9
commit
1dc9e6813b
6 files changed
+63
-38
No files matched your search
@@ -28,34 +28,25 @@ LDADD := -lSceSsl -lSceHttp
|
||||
|
||||
all: elfldr-ps5.elf
|
||||
|
||||
socksrv_elf.c: socksrv.elf
|
||||
bootstrap_elf.c: bootstrap.elf
|
||||
|
||||
bootstrap.o: socksrv_elf.c
|
||||
main.o: bootstrap_elf.c
|
||||
bootstrap.o: socksrv.elf
|
||||
main.o: bootstrap.elf
|
||||
|
||||
bootstrap.elf: bootstrap.o elfldr.o pt.o notify.o
|
||||
$(CC) -o $@ $^
|
||||
$(STRIP) $@
|
||||
|
||||
bootstrap_elf.c: bootstrap.elf
|
||||
xxd -i $^ > $@
|
||||
|
||||
socksrv.elf: socksrv.o selfldr.o elfldr.o pt.o notify.o uri.o
|
||||
$(CC) -o $@ $^ $(LDADD)
|
||||
$(STRIP) $@
|
||||
|
||||
socksrv_elf.c: socksrv.elf
|
||||
xxd -i $^ > $@
|
||||
|
||||
elfldr-ps5.elf: main.o elfldr.o pt.o notify.o
|
||||
$(CC) -o $@ $^
|
||||
$(STRIP) $@
|
||||
|
||||
clean:
|
||||
rm -f bootstrap_elf.c socksrv_elf.c *.o *.elf
|
||||
rm -f *.o *.elf
|
||||
|
||||
test: elfldr-ps5.elf
|
||||
$(PS5_DEPLOY) -h $(PS5_HOST) -p $(PS5_PORT) $^
|
||||
|
||||
.INTERMEDIATE: socksrv_elf.c socksrv.elf bootstrap_elf.c bootstrap.elf
|
||||
.INTERMEDIATE: socksrv.elf bootstrap.elf
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Copyright (C) 2026 John Törnblom
|
||||
|
||||
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 3, 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; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#define INCASSET(name, file) \
|
||||
__asm__(".section .rodata\n" \
|
||||
".global " #name "\n" \
|
||||
".global " #name "_end\n" \
|
||||
".global " #name "_size\n" \
|
||||
".align 16\n" \
|
||||
#name ":\n" \
|
||||
".incbin \"" file "\"\n" \
|
||||
#name "_end:\n" \
|
||||
#name "_size:\n" \
|
||||
".quad " #name "_end - " #name "\n" \
|
||||
".previous\n"); \
|
||||
extern const uint8_t name[]; \
|
||||
extern const size_t name##_size;
|
||||
+4
-4
@@ -19,13 +19,13 @@ along with this program; see the file COPYING. If not, see
|
||||
|
||||
#include <ps5/kernel.h>
|
||||
|
||||
#include "asset.h"
|
||||
#include "elfldr.h"
|
||||
#include "log.h"
|
||||
#include "notify.h"
|
||||
#include "pt.h"
|
||||
|
||||
|
||||
#include "socksrv_elf.c"
|
||||
INCASSET(socksrv_elf, "socksrv.elf");
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ main() {
|
||||
notify("Spawning elfldr.elf...");
|
||||
LOG_PUTS("Spawning elfldr.elf...");
|
||||
|
||||
if(elfldr_sanity_check(socksrv_elf, socksrv_elf_len)) {
|
||||
if(elfldr_sanity_check(socksrv_elf, socksrv_elf_size)) {
|
||||
LOG_PUTS("socksrv.elf is corrupted");
|
||||
return -1;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ main() {
|
||||
ret = -1;
|
||||
} else {
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
ret = elfldr_spawn(-1, argv, socksrv_elf, socksrv_elf_len);
|
||||
ret = elfldr_spawn(-1, argv, socksrv_elf, socksrv_elf_size);
|
||||
}
|
||||
|
||||
// restore my privileges
|
||||
|
||||
@@ -59,8 +59,8 @@ along with this program; see the file COPYING. If not, see
|
||||
* Context structure for the ELF loader.
|
||||
**/
|
||||
typedef struct elfldr_ctx {
|
||||
uint8_t* elf;
|
||||
pid_t pid;
|
||||
const uint8_t* elf;
|
||||
pid_t pid;
|
||||
|
||||
intptr_t base_addr;
|
||||
size_t base_size;
|
||||
@@ -78,7 +78,7 @@ static const char* SceSpZeroConf = "/system/vsh/app/NPXS40112/eboot.bin";
|
||||
* Parse a R_X86_64_RELATIVE relocatable.
|
||||
**/
|
||||
static int
|
||||
r_relative(elfldr_ctx_t *ctx, Elf64_Rela* rela) {
|
||||
r_relative(elfldr_ctx_t *ctx, const Elf64_Rela* rela) {
|
||||
intptr_t* loc = ctx->base_mirror + rela->r_offset;
|
||||
intptr_t val = ctx->base_addr + rela->r_addend;
|
||||
|
||||
@@ -92,7 +92,7 @@ r_relative(elfldr_ctx_t *ctx, Elf64_Rela* rela) {
|
||||
* Parse a PT_LOAD program header.
|
||||
**/
|
||||
static int
|
||||
data_load(elfldr_ctx_t *ctx, Elf64_Phdr *phdr) {
|
||||
data_load(elfldr_ctx_t *ctx, const Elf64_Phdr *phdr) {
|
||||
void* data = ctx->base_mirror + phdr->p_vaddr;
|
||||
|
||||
if(!phdr->p_memsz) {
|
||||
@@ -110,9 +110,9 @@ data_load(elfldr_ctx_t *ctx, Elf64_Phdr *phdr) {
|
||||
|
||||
|
||||
int
|
||||
elfldr_sanity_check(uint8_t *elf, size_t elf_size) {
|
||||
Elf64_Ehdr *ehdr = (Elf64_Ehdr*)elf;
|
||||
Elf64_Phdr *phdr;
|
||||
elfldr_sanity_check(const uint8_t *elf, size_t elf_size) {
|
||||
const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)elf;
|
||||
const Elf64_Phdr *phdr;
|
||||
|
||||
if(elf_size < sizeof(Elf64_Ehdr) ||
|
||||
elf_size < sizeof(Elf64_Phdr) + ehdr->e_phoff ||
|
||||
@@ -125,7 +125,7 @@ elfldr_sanity_check(uint8_t *elf, size_t elf_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
phdr = (Elf64_Phdr*)(elf + ehdr->e_phoff);
|
||||
phdr = (const Elf64_Phdr*)(elf + ehdr->e_phoff);
|
||||
for(int i=0; i<ehdr->e_phnum; i++) {
|
||||
if(phdr[i].p_offset + phdr[i].p_filesz > elf_size) {
|
||||
return -1;
|
||||
@@ -140,10 +140,10 @@ elfldr_sanity_check(uint8_t *elf, size_t elf_size) {
|
||||
* Load an ELF into the address space of a process with the given pid.
|
||||
**/
|
||||
static intptr_t
|
||||
elfldr_load(pid_t pid, uint8_t *elf) {
|
||||
Elf64_Ehdr *ehdr = (Elf64_Ehdr*)elf;
|
||||
Elf64_Phdr *phdr = (Elf64_Phdr*)(elf + ehdr->e_phoff);
|
||||
Elf64_Shdr *shdr = (Elf64_Shdr*)(elf + ehdr->e_shoff);
|
||||
elfldr_load(pid_t pid, const uint8_t *elf) {
|
||||
const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)elf;
|
||||
const Elf64_Phdr *phdr = (const Elf64_Phdr*)(elf + ehdr->e_phoff);
|
||||
const Elf64_Shdr *shdr = (const Elf64_Shdr*)(elf + ehdr->e_shoff);
|
||||
|
||||
elfldr_ctx_t ctx = {.elf = elf, .pid=pid};
|
||||
|
||||
@@ -207,7 +207,7 @@ elfldr_load(pid_t pid, uint8_t *elf) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Elf64_Rela* rela = (Elf64_Rela*)(elf + shdr[i].sh_offset);
|
||||
const Elf64_Rela* rela = (const Elf64_Rela*)(elf + shdr[i].sh_offset);
|
||||
for(int j=0; j<shdr[i].sh_size/sizeof(Elf64_Rela); j++) {
|
||||
switch(rela[j].r_info & 0xffffffffl) {
|
||||
case R_X86_64_RELATIVE:
|
||||
@@ -348,7 +348,7 @@ elfldr_payload_args(pid_t pid) {
|
||||
* Prepare registers of a process for execution of an ELF.
|
||||
**/
|
||||
static int
|
||||
elfldr_prepare_exec(pid_t pid, uint8_t *elf) {
|
||||
elfldr_prepare_exec(pid_t pid, const uint8_t *elf) {
|
||||
intptr_t entry;
|
||||
intptr_t args;
|
||||
struct reg r;
|
||||
@@ -437,7 +437,7 @@ elfldr_raise_privileges(pid_t pid) {
|
||||
* Execute an ELF inside the process with the given pid.
|
||||
**/
|
||||
int
|
||||
elfldr_exec(pid_t pid, int stdio, uint8_t* elf) {
|
||||
elfldr_exec(pid_t pid, int stdio, const uint8_t* elf) {
|
||||
uint8_t caps[16];
|
||||
intptr_t jaildir;
|
||||
intptr_t rootdir;
|
||||
@@ -600,7 +600,7 @@ elfldr_rfork_entry(void* argv) {
|
||||
* Execute an ELF inside a new process.
|
||||
**/
|
||||
pid_t
|
||||
elfldr_spawn(int stdio, char* const argv[], uint8_t* elf, size_t payload_size) {
|
||||
elfldr_spawn(int stdio, char* const argv[], const uint8_t* elf, size_t payload_size) {
|
||||
uint8_t int3instr = 0xcc;
|
||||
struct kevent evt;
|
||||
intptr_t brkpoint;
|
||||
|
||||
@@ -28,13 +28,14 @@ pid_t elfldr_find_pid(const char* name);
|
||||
/**
|
||||
* Spawn a new process that executes the given ELF file.
|
||||
**/
|
||||
pid_t elfldr_spawn(int stdio, char* const argv[], uint8_t *elf, size_t elf_size);
|
||||
pid_t elfldr_spawn(int stdio, char* const argv[], const uint8_t *elf,
|
||||
size_t elf_size);
|
||||
|
||||
|
||||
/**
|
||||
* Execute an ELF file in a given process.
|
||||
**/
|
||||
int elfldr_exec(pid_t pid, int stdio, uint8_t* elf);
|
||||
int elfldr_exec(pid_t pid, int stdio, const uint8_t* elf);
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ int elfldr_exec(pid_t pid, int stdio, uint8_t* elf);
|
||||
int elfldr_read(int fd, uint8_t** elf, size_t* elf_size);
|
||||
|
||||
|
||||
int elfldr_sanity_check(uint8_t *elf, size_t elf_size);
|
||||
int elfldr_sanity_check(const uint8_t *elf, size_t elf_size);
|
||||
|
||||
|
||||
int elfldr_raise_privileges(pid_t pid);
|
||||
@@ -16,12 +16,13 @@ along with this program; see the file COPYING. If not, see
|
||||
|
||||
#include <ps5/kernel.h>
|
||||
|
||||
#include "asset.h"
|
||||
#include "elfldr.h"
|
||||
#include "log.h"
|
||||
#include "notify.h"
|
||||
#include "pt.h"
|
||||
|
||||
#include "bootstrap_elf.c"
|
||||
INCASSET(bootstrap_elf, "bootstrap.elf");
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,7 @@ main() {
|
||||
notify("Bootstrapping elfldr.elf...");
|
||||
LOG_PUTS("Bootstrapping elfldr.elf...");
|
||||
|
||||
if(elfldr_sanity_check(bootstrap_elf, bootstrap_elf_len)) {
|
||||
if(elfldr_sanity_check(bootstrap_elf, bootstrap_elf_size)) {
|
||||
LOG_PUTS("bootstrap.elf is corrupted");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user