Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andryshik345 committed Aug 24, 2024
0 parents commit 4193911
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
LIBPS4 := $(PS4SDK)/libPS4

CC := gcc -DPS4
OBJCOPY := objcopy
ODIR := build
SDIR := source
IDIRS := -I$(LIBPS4)/include -Iinclude
LDIRS := -L$(LIBPS4)
MAPFILE := $(shell basename "$(CURDIR)").map
CFLAGS := $(IDIRS) -O3 -std=c11 -ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nostdlib -Wall -Wextra -Wstrict-aliasing -masm=intel -march=btver2 -mtune=btver2 -m64 -mabi=sysv -mcmodel=small -fpie -fPIC
LFLAGS := $(LDIRS) -Xlinker -T $(LIBPS4)/linker.x -Xlinker -Map="$(MAPFILE)" -Wl,--build-id=none -Wl,--gc-sections
CFILES := $(wildcard $(SDIR)/*.c)
SFILES := $(wildcard $(SDIR)/*.s)
OBJS := $(patsubst $(SDIR)/%.c, $(ODIR)/%.o, $(CFILES)) $(patsubst $(SDIR)/%.s, $(ODIR)/%.o, $(SFILES))

LIBS := -lPS4

TARGET = $(shell basename "$(CURDIR)").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

$(ODIR)/%.o: $(SDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)

$(ODIR)/%.o: $(SDIR)/%.s
$(CC) -c -o $@ $< $(CFLAGS)

$(ODIR):
@mkdir $@

.PHONY: clean

clean:
rm -rf "$(TARGET)" "$(MAPFILE)" $(ODIR)
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# PS4 Sflash0 NOR Dump Payload

This payload was made for dumping NOR firmware (so called Sflash0) to USB drive instead using FTP.

The compiled PS4 payload is available for download in the [release section](https://github.com/Andryshik345/ps4-sflash0-dumper/releases/).

## How to compile for PS4

1. Set up the PS4 payload SDK from https://github.com/Scene-Collective/ps4-payload-sdk.
2. In the ps4-sflash0-dumper directory: `make clean && make` to compile.
60 changes: 60 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifdef PS4
#include "ps4.h"
#endif

int _main(struct thread *td) {


initKernel();
initLibc();
initPthread();
jailbreak();
initSysUtil();

copy_file("/dev/sflash0", "/data/sflash0.bin");
printf_notification("sflash0 copied!\nChecking file size...");

struct stat info;
int res = 0;

if (!stat("/data/sflash0.bin", &info)) {
if (info.st_size == 33554432) {
printf_notification("sflash0.bin is %d bytes\nDump is correct!", info.st_size);
res = 1;
}
else {
printf_notification("sflash0.bin is %d bytes\nDump is NOT correct!\nTry reboot and run the payload again!", info.st_size);
res = unlink("/data/sflash0.bin");
return 0;
}
}
else {
printf_notification("sflash0.bin doesn't exist!\nSomething gone wrong...");
return 0;
}

if (res == 1) {
printf_notification("Copying sflash0.bin to USB...");
int usbdir = open("/mnt/usb0/.dirtest", O_WRONLY | O_CREAT | O_TRUNC, 0777);
if (usbdir == -1) {
usbdir = open("/mnt/usb1/.dirtest", O_WRONLY | O_CREAT | O_TRUNC, 0777);
if (usbdir == -1) {
printf_notification("USB not found!\nOnly internal backup was done\n(/data/sflash0.bin)!");
}
else {
close(usbdir);
unlink("/mnt/usb1/.dirtest");
copy_file("/data/sflash0.bin", "/mnt/usb1/sflash0.bin");
printf_notification("Dump copied to USB1 successfully!");
}
}
else {
close(usbdir);
unlink("/mnt/usb0/.dirtest");
copy_file("/data/sflash0.bin", "/mnt/usb0/sflash0.bin");
printf_notification("Dump copied to USB0 successfully!");
}
}

return 0;
}

0 comments on commit 4193911

Please sign in to comment.