Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions crt/kernel_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,74 @@ void kernel_init_rw(int master_sock, int victim_sock, int *rw_pipe, uint64_t pip
}

// Internal kwrite function - not friendly, only for setting up better primitives.
void kwrite(uint64_t addr, uint64_t *data) {
int kwrite(uint64_t addr, uint64_t *data) {
uint64_t victim_buf[3];

victim_buf[0] = addr;
victim_buf[1] = 0;
victim_buf[2] = 0;

setsockopt(_master_sock, IPPROTO_IPV6, IPV6_PKTINFO, victim_buf, 0x14);
setsockopt(_victim_sock, IPPROTO_IPV6, IPV6_PKTINFO, data, 0x14);
if(setsockopt(_master_sock, IPPROTO_IPV6, IPV6_PKTINFO, victim_buf, 0x14)) {
return -1;
}
if(setsockopt(_victim_sock, IPPROTO_IPV6, IPV6_PKTINFO, data, 0x14)) {
return -1;
}
return 0;
}

// Public API function to write kernel data.
void kernel_copyin(void *src, uint64_t kdest, size_t length)
int kernel_copyin(void *src, uint64_t kdest, size_t length)
{
uint64_t write_buf[3];

// Set pipe flags
write_buf[0] = 0;
write_buf[1] = 0x4000000000000000;
write_buf[2] = 0;
kwrite(_pipe_addr, (uint64_t *) &write_buf);
if(kwrite(_pipe_addr, (uint64_t *) &write_buf)) {
return -1;
}

// Set pipe data addr
write_buf[0] = kdest;
write_buf[1] = 0;
write_buf[2] = 0;
kwrite(_pipe_addr + 0x10, (uint64_t *) &write_buf);
if(kwrite(_pipe_addr + 0x10, (uint64_t *) &write_buf)) {
return -1;
}

// Perform write across pipe
_write(_rw_pipe[1], src, length);
if(_write(_rw_pipe[1], src, length) < 0) {
return -1;
}
return 0;
}

// Public API function to read kernel data.
void kernel_copyout(uint64_t ksrc, void *dest, size_t length)
int kernel_copyout(uint64_t ksrc, void *dest, size_t length)
{
uint64_t write_buf[3];

// Set pipe flags
write_buf[0] = 0x4000000040000000;
write_buf[1] = 0x4000000000000000;
write_buf[2] = 0;
kwrite(_pipe_addr, (uint64_t *) &write_buf);
if(kwrite(_pipe_addr, (uint64_t *) &write_buf)) {
return -1;
}

// Set pipe data addr
write_buf[0] = ksrc;
write_buf[1] = 0;
write_buf[2] = 0;
kwrite(_pipe_addr + 0x10, (uint64_t *) &write_buf);
if(kwrite(_pipe_addr + 0x10, (uint64_t *) &write_buf)) {
return -1;
}

// Perform read across pipe
_read(_rw_pipe[0], dest, length);
}
if(_read(_rw_pipe[0], dest, length) < 0) {
return -1;
}
return 0;
}
4 changes: 2 additions & 2 deletions ps5/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

// Public hacking API
void kernel_init_rw(int master_sock, int victim_sock, int *rw_pipe, uint64_t pipe_addr);
void kernel_copyin(void *src, uint64_t kdest, size_t length);
void kernel_copyout(uint64_t ksrc, void *dest, size_t length);
int kernel_copyin(void *src, uint64_t kdest, size_t length);
int kernel_copyout(uint64_t ksrc, void *dest, size_t length);

#endif // PS5SDK_KERNEL_H