Skip to content

Commit

Permalink
cleanup/fixes
Browse files Browse the repository at this point in the history
I believe this also fixes #5
  • Loading branch information
jogolden committed Aug 31, 2018
1 parent d5b855f commit 976d04b
Show file tree
Hide file tree
Showing 30 changed files with 1,030 additions and 373 deletions.
20 changes: 0 additions & 20 deletions Makefile

This file was deleted.

78 changes: 78 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# I decide to just clean it all then build from scratch each go around lol
# golden :P

clean_build() {
cd ps4-ksdk
make clean
cd ..

cd ps4-payload-sdk/libPS4/
make clean
cd ../../

cd debugger
make clean
cd ..

cd kdebugger
make clean
cd ..

cd installer
make clean
cd ..
}

build_submodules() {
cd ps4-ksdk
make
cd ..

cd ps4-payload-sdk/libPS4/
make
cd ../../
}

build_debugger() {
cd debugger
make
cd ..
}

build_kdebugger() {
cd kdebugger
make
cd ..
}

build_installer() {
cd installer
make
cd ..
}

if (( $# == 1 ));
then
if [ $1 == "clean" ]
then
echo "cleaning build..."
clean_build
fi
fi

echo "ps4debug building..."

echo "=> submodules..."
build_submodules
echo "=> debugger..."
build_debugger
echo "=> kdebugger..."
build_kdebugger
echo "=> installer..."
build_installer

cp ./installer/installer.bin ./ps4debug.bin

echo ""
echo "enjoy ps4debug! golden :P"
2 changes: 1 addition & 1 deletion debugger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TARGET = debugger.bin
$(TARGET): $(ODIR) $(OBJS)
$(CC) $(LIBPS4)/crt0.s $(ODIR)/*.o -o temp.t $(CFLAGS) $(LFLAGS) $(LIBS)
$(OBJCOPY) -O binary temp.t $(TARGET)
#rm -f temp.t
rm -f temp.t

$(ODIR)/%.o: $(SDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion debugger/include/kdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ int sys_kern_rw(uint64_t address, void *data, uint64_t length, uint64_t write);
#define SYS_CONSOLE_CMD_JAILBREAK 3
int sys_console_cmd(uint64_t cmd, void *data);

#define uprintf(fmt, ...) { /*char buffer[256]; snprintf(buffer, 256, fmt, ##__VA_ARGS__); sys_console_cmd(SYS_CONSOLE_CMD_PRINT, buffer);*/ }
#define uprintf(fmt, ...) { char buffer[256]; snprintf(buffer, 256, fmt, ##__VA_ARGS__); sys_console_cmd(SYS_CONSOLE_CMD_PRINT, buffer); }

#endif
3 changes: 1 addition & 2 deletions debugger/include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#define SERVER_IN IN_ADDR_ANY
#define SERVER_PORT 744

// this will block
void configure_socket(int fd, int buffersize);
void configure_socket(int fd);
void start_server();

#endif
10 changes: 5 additions & 5 deletions debugger/source/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ int debug_attach_handle(int fd, struct cmd_packet *packet) {
if(ap) {
r = ptrace(PT_ATTACH, ap->pid, NULL, NULL);
if(r) {
uprintf("[ps4debug] ptrace PT_ATTACH failed");
uprintf("ptrace PT_ATTACH failed");
net_send_status(fd, CMD_ERROR);
return 1;
}

//wait4(ap->pid, NULL, NULL, NULL);
r = ptrace(PT_CONTINUE, ap->pid, (void *)1, NULL);
if(r) {
uprintf("[ps4debug] ptrace PT_CONTINUE failed");
uprintf("ptrace PT_CONTINUE failed");
net_send_status(fd, CMD_ERROR);
return 1;
}
Expand All @@ -34,12 +34,12 @@ int debug_attach_handle(int fd, struct cmd_packet *packet) {
// connect to server
r = connect_debugger();
if(r) {
uprintf("[ps4debug] could not connect to server");
uprintf("could not connect to server");
net_send_status(fd, CMD_ERROR);
return 1;
}

uprintf("[ps4debug] debugger is attached");
uprintf("debugger is attached");

net_send_status(fd, CMD_SUCCESS);

Expand Down Expand Up @@ -153,7 +153,7 @@ int debug_watchpt_handle(int fd, struct cmd_packet *packet) {
dbreg64.dr[7] |= DBREG_DR7_SET(wp->index, NULL, NULL, DBREG_DR7_DISABLE);
}

uprintf("[ps4debug] dr%i: %llX dr7: %llX", wp->index, wp->address, dbreg64.dr[7]);
//uprintf("dr%i: %llX dr7: %llX", wp->index, wp->address, dbreg64.dr[7]);

// for each current lwpid edit the watchpoint
for(int i = 0; i < nlwps; i++) {
Expand Down
2 changes: 1 addition & 1 deletion debugger/source/kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "kern.h"

// todo: same as proc.c with the read/write functions, send as chunks
// TODO: same as proc.c with the read/write functions, send as chunks

int kern_base_handle(int fd, struct cmd_packet *packet) {
uint64_t kernbase;
Expand Down
2 changes: 0 additions & 2 deletions debugger/source/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ int net_send_data(int fd, void *data, int length) {
return offset;
}

#include "kdbg.h"

int net_recv_data(int fd, void *data, int length, int force) {
int left = length;
int offset = 0;
Expand Down
32 changes: 27 additions & 5 deletions debugger/source/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ int proc_list_handle(int fd, struct cmd_packet *packet) {
if(num > 0) {
length = sizeof(struct proc_list_entry) * num;
data = malloc(length);
if(!data) {
net_send_status(fd, CMD_DATA_NULL);
return 1;
}

sys_proc_list(data, &num);
net_send_status(fd, CMD_SUCCESS);
net_send_data(fd, &num, sizeof(uint32_t));
Expand All @@ -22,9 +27,8 @@ int proc_list_handle(int fd, struct cmd_packet *packet) {

return 0;
}

net_send_status(fd, CMD_DATA_NULL);

return 1;
}

Expand Down Expand Up @@ -144,12 +148,29 @@ int proc_info_handle(int fd, struct cmd_packet *packet) {

size = args.num * sizeof(struct proc_vm_map_entry);

args.maps = (struct proc_vm_map_entry *)malloc(size);
// I will use mmap because malloc is giving a kernel panic because it isnt allocating correctly?
// fuck you sony!
/*args.maps = (struct proc_vm_map_entry *)malloc(size);
if(!args.maps) {
net_send_status(fd, CMD_DATA_NULL);
return 1;
}*/
args.maps = (struct proc_vm_map_entry *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, NULL);
if(!args.maps) {
net_send_status(fd, CMD_DATA_NULL);
return 1;
}

// prefault memory, wont work without this - thanks cturt...
for(uint64_t i = 0; i < size; i++) {
volatile uint8_t c;
(void)c;

c = ((char *)args.maps)[i];
}

uprintf("address: %llX size: %X", args.maps, size);

if(sys_proc_cmd(ip->pid, SYS_PROC_VM_MAP, &args)) {
net_send_status(fd, CMD_ERROR);
return 1;
Expand All @@ -159,8 +180,9 @@ int proc_info_handle(int fd, struct cmd_packet *packet) {
num = (uint32_t)args.num;
net_send_data(fd, &num, sizeof(uint32_t));
net_send_data(fd, args.maps, size);

free(args.maps);

munmap(args.maps, size);
//free(args.maps);

return 0;
}
Expand Down
Loading

0 comments on commit 976d04b

Please sign in to comment.