Publishes the project

This commit is contained in:
Putta Khunchalee 2024-01-27 14:13:59 +07:00
commit 71544e7cf2
4 changed files with 196 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build/

17
COPYING Normal file
View File

@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

37
Makefile Normal file
View File

@ -0,0 +1,37 @@
LIBPS4 := $(PS4SDK)/libPS4
CC := gcc
OBJCOPY := objcopy
ODIR := build
SDIR := source
IDIRS := -I$(LIBPS4)/include -Iinclude
LDIRS := -L$(LIBPS4)
MAPFILE := $(shell basename "$(CURDIR)").map
CFLAGS := $(IDIRS) -Os -std=c11 -ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nostdlib -Wall -Wextra -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)

141
source/main.c Normal file
View File

@ -0,0 +1,141 @@
#include <ps4.h>
struct fsid {
int val[2];
};
struct statfs {
unsigned f_version;
unsigned f_type;
long field2_0x8;
long field3_0x10;
long field4_0x18;
long field5_0x20;
long field6_0x28;
long field7_0x30;
long field8_0x38;
long field9_0x40;
long field10_0x48;
long field11_0x50;
long field12_0x58;
long field13_0x60;
long field14_0x68;
long field15_0x70;
long field16_0x78;
long field17_0x80;
long field18_0x88;
long field19_0x90;
long field20_0x98;
long field21_0xa0;
long field22_0xa8;
long field23_0xb0;
char field24_0xb8;
char field25_0xb9;
char field26_0xba;
char field27_0xbb;
int f_owner;
struct fsid f_fsid;
long field30_0xc8;
long field31_0xd0;
long field32_0xd8;
long field33_0xe0;
long field34_0xe8;
long field35_0xf0;
long field36_0xf8;
long field37_0x100;
long field38_0x108;
long field39_0x110;
char f_fstypename[16];
char f_mntfromname[88];
char f_mntonname[88];
};
struct get_mounts_req {
struct statfs *buf;
size_t len;
};
struct get_mounts_args {
void *h;
struct get_mounts_req *r;
};
typedef int (*getfsstat_t) (struct thread *, struct statfs **, size_t , int, int);
static int get_mounts(struct thread *td, struct get_mounts_args *args) {
void *base;
getfsstat_t getfsstat;
base = &((uint8_t *)__readmsr(0xC0000082))[-K900_XFAST_SYSCALL];
getfsstat = (getfsstat_t)(base + 0x1D90A0);
return getfsstat(td, &args->r->buf, args->r->len, 0, 1);
}
int _main(struct thread *td) {
struct get_mounts_req req;
int res, i, fd;
FILE *fp;
initKernel();
initLibc();
jailbreak();
initSysUtil();
// allocate buffer
req.len = sizeof(struct statfs) * 8192;
req.buf = malloc(req.len);
if (!req.buf) {
printf_notification("Failed to allocate %u bytes of memory.", req.len);
return 0;
}
// get mount list
res = kexec(get_mounts, &req);
if (res < 0) {
free(req.buf);
printf_notification("Failed to get mount list.");
return 0;
}
// create an output file
fd = open("/mnt/usb0/mount-list.txt", O_WRONLY | O_CREAT | O_TRUNC, 0777);
if (fd < 0) {
printf_notification("Failed to create /mnt/usb0/mount-list.txt.");
free(req.buf);
return 0;
}
// write to usb drive
for (i = 0; i < res; i++) {
struct statfs *s = req.buf + i;
if (write(fd, s->f_fstypename, strlen(s->f_fstypename)) < 0 || write(fd, "\t", 1) < 0) {
printf_notification("Failed to write /mnt/usb0/mount-list.txt.");
close(fd);
free(req.buf);
return 0;
}
if (write(fd, s->f_mntfromname, strlen(s->f_mntfromname)) < 0 || write(fd, "\t", 1) < 0) {
printf_notification("Failed to write /mnt/usb0/mount-list.txt.");
close(fd);
free(req.buf);
return 0;
}
if (write(fd, s->f_mntonname, strlen(s->f_mntonname)) < 0 || write(fd, "\r\n", 2) < 0) {
printf_notification("Failed to write /mnt/usb0/mount-list.txt.");
close(fd);
free(req.buf);
return 0;
}
}
printf_notification("Mount list dump complete!");
return 0;
}