Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Jul 26, 2024
1 parent d3f9496 commit c4c3af5
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions core/popcorn/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ static int g_icon0Status;

// custom emulator config
static int has_config = 0;
static void* custom_config = NULL;
static u8 custom_config[0x400];
static int config_size = 0;
static int config_offset = 0;
static int psiso_offset = 0;

static unsigned char g_keys[16];

Expand Down Expand Up @@ -139,6 +139,11 @@ static void readCustomConfig(){

fd = sceIoOpen(ebootname, PSP_O_RDONLY, 0777);
sceIoRead(fd, &header, sizeof(PBPHeader));

psiso_offset = header.psar_offset;
sceIoLseek(fd, psiso_offset+0x400, PSP_SEEK_SET);
sceIoRead(fd, custom_config, 0x400);

sceIoClose(fd);

char* slash = strrchr(configname, '/');
Expand All @@ -151,13 +156,14 @@ static void readCustomConfig(){

config_size = sceIoLseek(fd, 0, PSP_SEEK_END);
if (config_size <= 0) goto config_end;

custom_config = oe_malloc(config_size);
if (custom_config == NULL) goto config_end;

sceIoRead(fd, custom_config, config_size);
if (config_size == 0x400){
sceIoRead(fd, custom_config, config_size);
}
else {
sceIoRead(fd, custom_config+0x20, config_size);
}
has_config = 1;
config_offset = header.psar_offset + 0x420;

config_end:
sceIoClose(fd);
Expand Down Expand Up @@ -431,26 +437,14 @@ static int myIoRead(int fd, unsigned char *buf, int size)
}

if (has_config){
if (pos == config_offset){
// trying to read POPS config
ret = MIN(size, config_size);
memcpy(buf, custom_config, ret);
goto exit;
}

if (/*fd == pbp_fd &&*/ pos > config_offset && pos+size <= config_offset+config_size){
// trying to read POPS config
int relative_offset = pos - config_offset;
memcpy(buf, (u8*)custom_config+relative_offset, size);
int lower_limit = psiso_offset+0x400;
int upper_limit = psiso_offset+0x800;
if (pos >= lower_limit && pos+size <= upper_limit){
int lower_offset = pos - lower_limit;
memcpy(buf, custom_config+lower_offset, size);
ret = size;
goto exit;
}

if (pos < config_offset && pos+size <= config_offset+config_size){
int relative_offset = config_offset - pos;
memcpy(buf+relative_offset, custom_config, size-relative_offset);
size = relative_offset;
}
}

ret = sceIoRead(fd, buf, size);
Expand Down

2 comments on commit c4c3af5

@Goatman13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is at fixed address in pops. 0x9E80000 is where per ISO header is loaded + 0x420 for config. Function that uses it is located at 0x24770 in recent PSP 01g pops.
I think it will be easier to inject it there than mess with psar where every single app uses own approach to pack iso. This should make it work per disc if needed and you will mitigate pop-fe issue where additional multidisc header is added for single disc packages.

I'm not really familiar with PSP cfw abilities, so maybe my approach is not really possible.

@JoseAaronLopezGarcia
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is at fixed address in pops. 0x9E80000 is where per ISO header is loaded + 0x420 for config. Function that uses it is located at 0x24770 in recent PSP 01g pops. I think it will be easier to inject it there than mess with psar where every single app uses own approach to pack iso. This should make it work per disc if needed and you will mitigate pop-fe issue where additional multidisc header is added for single disc packages.

I'm not really familiar with PSP cfw abilities, so maybe my approach is not really possible.

awesome information, though I already got it working using IO hooks, which also allow us to inject more things like libcrypt magic number, doing it by injecting it in RAM could work but I would have to figure out a good patch point (somewhere in between the emulator reading it and actually using it), whereas the IO hooks are already implemented and just needed to be extended.

Please sign in to comment.