Skip to content

Commit

Permalink
fix the issue that xcode cannot view the device process list, also "f…
Browse files Browse the repository at this point in the history
…rida-ps -U"
  • Loading branch information
roothider committed Sep 18, 2024
1 parent 09c030a commit ac14279
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion BaseBin/launchdhook/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif
sign: $(TARGET)
@ldid -S $^

$(TARGET): $(wildcard src/*.m src/*.c src/jbserver/*.c ../systemhook/src/common.c ../systemhook/src/envbuf.c)
$(TARGET): $(wildcard src/*.m src/*.c src/jbserver/*.c ../systemhook/src/common.c ../systemhook/src/envbuf.c ../systemhook/src/syscall.S)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

clean:
Expand Down
6 changes: 5 additions & 1 deletion BaseBin/launchdhook/src/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "boomerang.h"
#import "update.h"
#import "exec_patch.h"
#include "../systemhook/src/common.h"

char HOOK_DYLIB_PATH[PATH_MAX] = {0};

Expand Down Expand Up @@ -193,7 +194,10 @@ void lockAllDSCText(void)
initJetsamHook();
initSpawnExecPatch();


void* __sysctl_orig = NULL;
void* __sysctlbyname_orig = NULL;
MSHookFunction(&__sysctl, (void *) __sysctl_hook, &__sysctl_orig);
MSHookFunction(&__sysctlbyname, (void *) __sysctlbyname_hook, &__sysctlbyname_orig);

// This will ensure launchdhook is always reinjected after userspace reboots
// As this launchd will pass environ to the next launchd...
Expand Down
44 changes: 44 additions & 0 deletions BaseBin/systemhook/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,47 @@ int spawn_hook_common(pid_t *restrict pid, const char *restrict path,

return retval;
}


#include <sys/sysctl.h>
int cached_namelen = 0;
int cached_name[CTL_MAXNAME+2]={0};
int syscall__sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctl_hook(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
int mib[] = {0, 3}; //https://github.com/apple-oss-distributions/Libc/blob/899a3b2d52d95d75e05fb286a5e64975ec3de757/gen/FreeBSD/sysctlbyname.c#L24
size_t namelen = sizeof(cached_name);
const char* query = "security.mac.amfi.developer_mode_status";
if(syscall__sysctl(mib, sizeof(mib)/sizeof(mib[0]), cached_name, &namelen, (void*)query, strlen(query))==0) {
cached_namelen = namelen / sizeof(cached_name[0]);
}
});

if(name && namelen && cached_namelen &&
namelen==cached_namelen && memcmp(cached_name, name, namelen)==0) {
if(oldp && oldlenp && *oldlenp>=sizeof(int)) {
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;
}
}

return syscall__sysctl(name,namelen,oldp,oldlenp,newp,newlen);
}

int syscall__sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
int __sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
int __sysctlbyname_hook(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
if(name && namelen && strncmp(name, "security.mac.amfi.developer_mode_status", namelen)==0) {
if(oldp && oldlenp && *oldlenp>=sizeof(int)) {
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;
}
}
return syscall__sysctlbyname(name,namelen,oldp,oldlenp,newp,newlen);
}
7 changes: 6 additions & 1 deletion BaseBin/systemhook/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ int spawn_hook_common(pid_t *restrict pid, const char *restrict path,
char *const envp[restrict],
void *orig,
int (*trust_binary)(const char *path, xpc_object_t preferredArchsArray),
int (*set_process_debugged)(uint64_t pid, bool fullyDebugged));
int (*set_process_debugged)(uint64_t pid, bool fullyDebugged));

int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctl_hook(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
int __sysctlbyname_hook(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
46 changes: 0 additions & 46 deletions BaseBin/systemhook/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,52 +685,6 @@ void loadPathFix(void)
});
}

int syscall__sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
int __sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
int __sysctlbyname_hook(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
if(name && strncmp(name, "security.mac.amfi.developer_mode_status", namelen)==0) {
if(oldp && oldlenp && *oldlenp>=sizeof(int)) {
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;
}
}
return syscall__sysctlbyname(name,namelen,oldp,oldlenp,newp,newlen);
}

#include <sys/sysctl.h>
int cached_namelen = 0;
int cached_name[CTL_MAXNAME+2]={0};
int syscall__sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
int __sysctl_hook(int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen)
{
//https://github.com/apple-oss-distributions/Libc/blob/899a3b2d52d95d75e05fb286a5e64975ec3de757/gen/FreeBSD/sysctlbyname.c#L24
if(name && namelen==2 && name[0]==0 && name[1]==3) {
if(newp && newlen && strncmp(newp,"security.mac.amfi.developer_mode_status",newlen)==0) {
if(syscall__sysctl(name,namelen,oldp,oldlenp,newp,newlen)==0) {
if(oldp && oldlenp && *oldlenp<=sizeof(cached_name)) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
memcpy(cached_name, oldp, *oldlenp);
cached_namelen = *oldlenp / sizeof (int);
});
}
}
}
}
if(name && namelen && cached_namelen &&
namelen==cached_namelen && memcmp(cached_name, name, namelen)==0) {
if(oldp && oldlenp && *oldlenp>=sizeof(int)) {
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;
}
}
return syscall__sysctl(name,namelen,oldp,oldlenp,newp,newlen);
}

char HOOK_DYLIB_PATH[PATH_MAX] = {0};

__attribute__((constructor)) static void initializer(void)
Expand Down

0 comments on commit ac14279

Please sign in to comment.