Skip to content

Commit

Permalink
Do proper hooks of csops and csops_audit_token on arm64, should fix b…
Browse files Browse the repository at this point in the history
…attery section not loading and potentially camera not working
  • Loading branch information
opa334 committed Feb 23, 2024
1 parent 4152e96 commit 8f1cf90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion BaseBin/systemhook/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LDFLAGS = -dynamiclib
sign: $(TARGET)
@ldid -S $^

$(TARGET): $(wildcard src/*.c src/*.m ../libjailbreak/src/jbclient_xpc.c)
$(TARGET): $(wildcard src/*.c src/*.m ../libjailbreak/src/jbclient_xpc.c ../forkfix/src/litehook.c)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

clean:
Expand Down
5 changes: 5 additions & 0 deletions BaseBin/systemhook/src/litehook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
#include <stdbool.h>
#include <mach/mach.h>

kern_return_t litehook_hook_function(void *source, void *target);
21 changes: 13 additions & 8 deletions BaseBin/systemhook/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "objc.h"
#include <libjailbreak/jbclient_xpc.h>
#include <libjailbreak/codesign.h>
#include "litehook.h"

#define SYSCALL_CSOPS 0xA9
#define SYSCALL_CSOPS_AUDITTOKEN 0xAA

#define JBRootPath(path) ({ \
char *outPath = alloca(PATH_MAX); \
Expand Down Expand Up @@ -327,8 +331,8 @@ int daemon_hook(int __nochdir, int __noclose)
// Always set CS_VALID in csflag to avoid causing a crash when hooking a c function on arm64
int csops_hook(pid_t pid, unsigned int ops, void * useraddr, size_t usersize)
{
int rv = csops(pid, ops, useraddr, usersize);
if (rv) return rv;
int rv = syscall(SYSCALL_CSOPS, pid, ops, useraddr, usersize);
if (rv != 0) return rv;
if (ops == CS_OPS_STATUS) {
if (useraddr) {
uint32_t* csflag = (uint32_t*)useraddr;
Expand All @@ -340,8 +344,8 @@ int csops_hook(pid_t pid, unsigned int ops, void * useraddr, size_t usersize)

int csops_audittoken_hook(pid_t pid, unsigned int ops, void * useraddr, size_t usersize, audit_token_t * token)
{
int rv = csops_audittoken(pid, ops, useraddr, usersize, token);
if (rv) return rv;
int rv = syscall(SYSCALL_CSOPS_AUDITTOKEN, pid, ops, useraddr, usersize, token);
if (rv != 0) return rv;
if (ops == CS_OPS_STATUS) {
if (useraddr) {
uint32_t* csflag = (uint32_t*)useraddr;
Expand Down Expand Up @@ -402,6 +406,11 @@ __attribute__((constructor)) static void initializer(void)
dlopen_hook(JBRootPath("/basebin/watchdoghook.dylib"), RTLD_NOW);
}

#ifndef __arm64e__
litehook_hook_function(csops, csops_hook);
litehook_hook_function(csops_audittoken, csops_audittoken_hook);
#endif

if (shouldEnableTweaks()) {
const char *tweakLoaderPath = "/var/jb/usr/lib/TweakLoader.dylib";
if(access(tweakLoaderPath, F_OK) == 0) {
Expand Down Expand Up @@ -438,8 +447,4 @@ DYLD_INTERPOSE(fork_hook, fork)
DYLD_INTERPOSE(vfork_hook, vfork)
DYLD_INTERPOSE(forkpty_hook, forkpty)
DYLD_INTERPOSE(daemon_hook, daemon)
#else
/* !__arm64e__ */
DYLD_INTERPOSE(csops_hook, csops)
DYLD_INTERPOSE(csops_audittoken_hook, csops_audittoken)
#endif

0 comments on commit 8f1cf90

Please sign in to comment.