Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add support for arbitrary syscalls
Thanks for the idea, sleirsgoevy
- Loading branch information
1 parent
0b13c7b
commit e8f9b3b
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* Copyright (C) 2023 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/>. */ | ||
|
|
||
| #include "payload.h" | ||
|
|
||
|
|
||
| static __attribute__ ((used)) long ptr_syscall; | ||
|
|
||
|
|
||
| asm(".intel_syntax noprefix\n" | ||
| ".global syscall\n" | ||
| ".type syscall @function\n" | ||
| "syscall:\n" | ||
| " mov rax, rdi\n" // sysno | ||
| " mov rdi, rsi\n" // arg1 | ||
| " mov rsi, rdx\n" // arg2 | ||
| " mov rdx, rcx\n" // arg3 | ||
| " mov r10, r8\n" // arg4 | ||
| " mov r8, r9\n" // arg5 | ||
| " mov r9, qword ptr [rsp + 8]\n" // arg6 | ||
| " jmp qword ptr [rip + ptr_syscall]\n" // syscall | ||
| " ret\n" | ||
| ); | ||
|
|
||
|
|
||
| __attribute__((constructor(101))) static void | ||
| constructor(const payload_args_t *args) { | ||
| *args->payloadout = args->sceKernelDlsym(0x2001, "getpid", &ptr_syscall); | ||
| ptr_syscall += 0xa; // jump directly to syscall instruction | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| *.elf | ||
| *.o | ||
| *~ | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Copyright (C) 2023 John Törnblom | ||
| # | ||
| # This file 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 of the License, 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/>. | ||
|
|
||
| ifndef PS5_PAYLOAD_SDK | ||
| $(error PS5_PAYLOAD_SDK is undefined) | ||
| endif | ||
|
|
||
| PS5_HOST ?= ps5 | ||
| PS5_PORT ?= 9020 | ||
|
|
||
| ELF := arbitrary_syscall.elf | ||
|
|
||
| CC := $(PS5_PAYLOAD_SDK)/host/x86_64-ps5-payload-cc | ||
| LD := $(PS5_PAYLOAD_SDK)/host/x86_64-ps5-payload-ld | ||
|
|
||
| CFLAGS := -O2 | ||
| LDADD := -lSceLibcInternal | ||
|
|
||
| all: $(ELF) | ||
|
|
||
| %.o: %.c | ||
| $(CC) -c $(CFLAGS) -o $@ $^ | ||
|
|
||
| $(ELF): main.o | ||
| $(LD) $^ $(LDADD) -o $@ | ||
|
|
||
| clean: | ||
| rm -f *.o $(ELF) | ||
|
|
||
| test: $(ELF) | ||
| nc -q0 $(PS5_HOST) $(PS5_PORT) < $^ | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* Copyright (C) 2023 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/>. */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
| #include <sys/syscall.h> | ||
|
|
||
|
|
||
| int main() { | ||
| printf("%d\n", (int)syscall(SYS_getuid)); | ||
|
|
||
| return 0; | ||
| } |