Skip to content

Commit

Permalink
Merge pull request #11 from Cryptiiiic/dev
Browse files Browse the repository at this point in the history
Add return values for kern rw functions
  • Loading branch information
opa334 authored Apr 12, 2023
2 parents a9752a6 + 314c720 commit 22bbabe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 43 deletions.
27 changes: 14 additions & 13 deletions BaseBin/libjailbreak/src/pplrw.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ extern PPLRWStatus gPPLRWStatus;
void *mapInRange(uint64_t pageStart, uint32_t pageCount, uint8_t** mappingStart);
void mappingDestroy(void* ctx);

void physreadbuf(uint64_t physaddr, void* output, size_t size);
void physwritebuf(uint64_t physaddr, const void* input, size_t size);
int physreadbuf(uint64_t physaddr, void* output, size_t size);
int physwritebuf(uint64_t physaddr, const void* input, size_t size);

uint64_t physread64(uint64_t pa);
uint64_t physread_ptr(uint64_t va);
uint32_t physread32(uint64_t pa);
uint16_t physread16(uint64_t pa);
uint8_t physread8(uint64_t pa);

void physwrite64(uint64_t pa, uint64_t v);
void physwrite32(uint64_t pa, uint32_t v);
void physwrite16(uint64_t pa, uint16_t v);
void physwrite8(uint64_t pa, uint8_t v);
int physwrite64(uint64_t pa, uint64_t v);
int physwrite32(uint64_t pa, uint32_t v);
int physwrite16(uint64_t pa, uint16_t v);
int physwrite8(uint64_t pa, uint8_t v);

void kreadbuf(uint64_t kaddr, void* output, size_t size);
void kwritebuf(uint64_t kaddr, const void* input, size_t size);
int kreadbuf(uint64_t kaddr, void* output, size_t size);
int kwritebuf(uint64_t kaddr, const void* input, size_t size);

uint64_t kread64(uint64_t va);
uint64_t kread_ptr(uint64_t va);
uint32_t kread32(uint64_t va);
uint16_t kread16(uint64_t va);
uint8_t kread8(uint64_t va);

void kwrite64(uint64_t va, uint64_t v);
void kwrite32(uint64_t va, uint32_t v);
void kwrite16(uint64_t va, uint16_t v);
void kwrite8(uint64_t va, uint8_t v);
int kwrite64(uint64_t va, uint64_t v);
int kwrite32(uint64_t va, uint32_t v);
int kwrite16(uint64_t va, uint16_t v);
int kwrite8(uint64_t va, uint8_t v);

void initPPLPrimitives(uint64_t magicPage);

void initPPLPrimitives(uint64_t magicPage);
56 changes: 30 additions & 26 deletions BaseBin/libjailbreak/src/pplrw.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ void mappingDestroy(void* ctx)

// Physical read / write

void physreadbuf(uint64_t physaddr, void* output, size_t size)
int physreadbuf(uint64_t physaddr, void* output, size_t size)
{
if(gPPLRWStatus == kPPLRWStatusNotInitialized) {
bzero(output, size);
return;
return -1;
}

JBLogDebug("before physread of 0x%llX (size: %zd)", physaddr, size);
Expand All @@ -286,12 +286,13 @@ void physreadbuf(uint64_t physaddr, void* output, size_t size)
}

JBLogDebug("after physread of 0x%llX", physaddr);
return 0;
}

void physwritebuf(uint64_t physaddr, const void* input, size_t size)
int physwritebuf(uint64_t physaddr, const void* input, size_t size)
{
if(gPPLRWStatus == kPPLRWStatusNotInitialized) {
return;
return -1;
}

JBLogDebug("before physwrite at 0x%llX (size: %zd)", physaddr, size);
Expand All @@ -316,15 +317,16 @@ void physwritebuf(uint64_t physaddr, const void* input, size_t size)
}

JBLogDebug("after physwrite at 0x%llX", physaddr);
return 0;
}

// Virtual read / write

void kreadbuf(uint64_t kaddr, void* output, size_t size)
int kreadbuf(uint64_t kaddr, void* output, size_t size)
{
bzero(output, size);
if(gPPLRWStatus == kPPLRWStatusNotInitialized) {
return;
return -1;
}

JBLogDebug("before virtread of 0x%llX (size: %zd)", kaddr, size);
Expand All @@ -343,7 +345,7 @@ void kreadbuf(uint64_t kaddr, void* output, size_t size)
if (failure)
{
JBLogError("[kreadbuf] Lookup failure when trying to read %zu bytes at 0x%llX, aborting", size, kaddr);
return;
return -1;
}

PPLWindow window = getWindow();
Expand All @@ -357,12 +359,13 @@ void kreadbuf(uint64_t kaddr, void* output, size_t size)
}

JBLogDebug("after virtread of 0x%llX", kaddr);
return 0;
}

void kwritebuf(uint64_t kaddr, const void* input, size_t size)
int kwritebuf(uint64_t kaddr, const void* input, size_t size)
{
if(gPPLRWStatus == kPPLRWStatusNotInitialized) {
return;
return -1;
}

JBLogDebug("before virtwrite at 0x%llX (size: %zd)", kaddr, size);
Expand All @@ -381,7 +384,7 @@ void kwritebuf(uint64_t kaddr, const void* input, size_t size)
if (failure)
{
JBLogError("[kwritebuf] Lookup failure when trying to write %zu bytes to 0x%llX, aborting", size, kaddr);
return;
return -1;
}

PPLWindow window = getWindow();
Expand All @@ -395,6 +398,7 @@ void kwritebuf(uint64_t kaddr, const void* input, size_t size)
}

JBLogDebug("after virtwrite at 0x%llX", kaddr);
return 0;
}


Expand Down Expand Up @@ -434,24 +438,24 @@ uint8_t physread8(uint64_t pa)
}


void physwrite64(uint64_t pa, uint64_t v)
int physwrite64(uint64_t pa, uint64_t v)
{
physwritebuf(pa, &v, sizeof(v));
return physwritebuf(pa, &v, sizeof(v));
}

void physwrite32(uint64_t pa, uint32_t v)
int physwrite32(uint64_t pa, uint32_t v)
{
physwritebuf(pa, &v, sizeof(v));
return physwritebuf(pa, &v, sizeof(v));
}

void physwrite16(uint64_t pa, uint16_t v)
int physwrite16(uint64_t pa, uint16_t v)
{
physwritebuf(pa, &v, sizeof(v));
return physwritebuf(pa, &v, sizeof(v));
}

void physwrite8(uint64_t pa, uint8_t v)
int physwrite8(uint64_t pa, uint8_t v)
{
physwritebuf(pa, &v, sizeof(v));
return physwritebuf(pa, &v, sizeof(v));
}


Expand Down Expand Up @@ -489,24 +493,24 @@ uint8_t kread8(uint64_t va)
}


void kwrite64(uint64_t va, uint64_t v)
int kwrite64(uint64_t va, uint64_t v)
{
kwritebuf(va, &v, sizeof(v));
return kwritebuf(va, &v, sizeof(v));
}

void kwrite32(uint64_t va, uint32_t v)
int kwrite32(uint64_t va, uint32_t v)
{
kwritebuf(va, &v, sizeof(v));
return kwritebuf(va, &v, sizeof(v));
}

void kwrite16(uint64_t va, uint16_t v)
int kwrite16(uint64_t va, uint16_t v)
{
kwritebuf(va, &v, sizeof(v));
return kwritebuf(va, &v, sizeof(v));
}

void kwrite8(uint64_t va, uint8_t v)
int kwrite8(uint64_t va, uint8_t v)
{
kwritebuf(va, &v, sizeof(v));
return kwritebuf(va, &v, sizeof(v));
}

void initPPLPrimitives(uint64_t magicPage)
Expand Down
4 changes: 2 additions & 2 deletions BaseBin/libjailbreak/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void proc_set_csflags(uint64_t proc, uint32_t csflags);
uint64_t self_proc(void);

uint32_t ucred_get_svuid(uint64_t ucred_ptr);
void ucred_set_svuid(uint64_t ucred_ptr, uint32_t svuid);
int ucred_set_svuid(uint64_t ucred_ptr, uint32_t svuid);
uint64_t ucred_get_cr_label(uint64_t ucred_ptr);

uint64_t task_get_first_thread(uint64_t task_ptr);
Expand Down Expand Up @@ -69,4 +69,4 @@ void proc_replace_entitlements(uint64_t proc_ptr, NSDictionary *entitlements);

bool proc_set_debugged(pid_t pid);
NSString *proc_get_path(pid_t pid);
int64_t proc_fix_setuid(pid_t pid);
int64_t proc_fix_setuid(pid_t pid);
4 changes: 2 additions & 2 deletions BaseBin/libjailbreak/src/util.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ uint32_t ucred_get_svuid(uint64_t ucred_ptr)
return kread32(cr_posix_ptr + 0x8);
}

void ucred_set_svuid(uint64_t ucred_ptr, uint32_t svuid)
int ucred_set_svuid(uint64_t ucred_ptr, uint32_t svuid)
{
uint64_t cr_posix_ptr = ucred_ptr + 0x18;
return kwrite32(cr_posix_ptr + 0x8, svuid);
Expand Down Expand Up @@ -655,4 +655,4 @@ int64_t proc_fix_setuid(pid_t pid)
else {
return 5;
}
}
}

0 comments on commit 22bbabe

Please sign in to comment.