Skip to content

Commit

Permalink
fix some issues (#281)
Browse files Browse the repository at this point in the history
* fix some issues

* add header for forkpty
  • Loading branch information
RootHide authored Nov 20, 2023
1 parent ee039cb commit 5d66528
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BaseBin/libjailbreak/src/kcall.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ uint64_t initPACPrimitives(uint64_t kernelAllocation)
kwrite64(actContext + offsetof(kRegisterState, x[17]), brX22);

// Use str x8, [x9] gadget to set TH_KSTACKPTR
kwrite64(actContext + offsetof(kRegisterState, x[8]), stack + 0x10ULL);
kwrite64(actContext + offsetof(kRegisterState, x[8]), stack + 0x1000ULL);
kwrite64(actContext + offsetof(kRegisterState, x[9]), threadPtr + bootInfo_getUInt64(@"TH_KSTACKPTR"));

// SP and x0 should both point to the new CPU state
Expand Down
4 changes: 4 additions & 0 deletions BaseBin/libjailbreak/src/macho.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ int64_t machoFindArch(FILE *machoFile, uint32_t subtypeToSearch)
fseek(machoFile, archOffset, SEEK_SET);
fread(&mh, sizeof(mh), 1, machoFile);
uint32_t maskedSubtype = OSSwapLittleToHostInt32(mh.cpusubtype);

if(OSSwapLittleToHostInt32(mh.filetype)==MH_EXECUTE && maskedSubtype==CPU_SUBTYPE_ARM64E)
return; //skip arm64e old ABI for executable on ios15

if (maskedSubtype == subtypeToSearch) {
outArchOffset = archOffset;
*stop = YES;
Expand Down
21 changes: 21 additions & 0 deletions BaseBin/systemhook/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sys/sysctl.h>
#include <sys/stat.h>
#include <paths.h>
#include <util.h>
#include "sandbox.h"
extern char **environ;

Expand Down Expand Up @@ -129,6 +130,12 @@ int execve_hook(const char *path, char *const argv[], char *const envp[])
if (attr) {
posix_spawnattr_destroy(&attr);
}

if(result != 0) { // posix_spawn will return errno and restore errno if it fails
errno = result; // so we need to set errno by ourself
return -1;
}

return result;
}

Expand Down Expand Up @@ -361,6 +368,18 @@ pid_t vfork_hook(void)
return vfork();
}

pid_t forkpty_hook(int *amaster, char *name, struct termios *termp, struct winsize *winp)
{
loadForkFix();
return forkpty(amaster, name, termp, winp);
}

int daemon_hook(int __nochdir, int __noclose)
{
loadForkFix();
return daemon(__nochdir, __noclose);
}

bool shouldEnableTweaks(void)
{
if (access(JB_ROOT_PATH("/basebin/.safe_mode"), F_OK) == 0) {
Expand Down Expand Up @@ -471,3 +490,5 @@ DYLD_INTERPOSE(sandbox_init_with_extensions_hook, sandbox_init_with_extensions)
DYLD_INTERPOSE(ptrace_hook, ptrace)
DYLD_INTERPOSE(fork_hook, fork)
DYLD_INTERPOSE(vfork_hook, vfork)
DYLD_INTERPOSE(forkpty_hook, forkpty)
DYLD_INTERPOSE(daemon_hook, daemon)
2 changes: 1 addition & 1 deletion Exploits/oobPCI/Sources/badRecovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool setupFugu14Kcall(void) {
kwrite64(actContext + offsetof(kRegisterState, x[17]), brX22);

// Use str x8, [x9] gadget to set TH_KSTACKPTR
kwrite64(actContext + offsetof(kRegisterState, x[8]), stack + 0x10ULL);
kwrite64(actContext + offsetof(kRegisterState, x[8]), stack + 0x1000ULL);
kwrite64(actContext + offsetof(kRegisterState, x[9]), threadPtr + THREAD_KSTACKPTR_OFFSET);

// SP and x0 should both point to the new CPU state
Expand Down

0 comments on commit 5d66528

Please sign in to comment.