-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
694bec0
commit a90510d
Showing
7 changed files
with
83 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// EMGInvocationCreator.m | ||
// | ||
// | ||
// Created by Noah Martin on 8/9/24. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface EMGInvocationCreator: NSObject | ||
|
||
+ (NSInvocation *)create:(NSString *)selectorName; | ||
|
||
@end | ||
|
||
@implementation EMGInvocationCreator | ||
|
||
+ (NSInvocation *)create:(NSString *)selectorName { | ||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:"v@:"]]; | ||
invocation.selector = NSSelectorFromString(selectorName); | ||
return invocation; | ||
} | ||
|
||
#if TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION || !(defined(__arm64__) || defined(__aarch64__)) | ||
#define EMG_ENABLE_FIX_TIME 0 | ||
#else | ||
#define EMG_ENABLE_FIX_TIME 1 | ||
#endif | ||
|
||
#if EMG_ENABLE_FIX_TIME | ||
|
||
#import <sys/time.h> | ||
#import <mach/thread_status.h> | ||
#import <mach/vm_types.h> | ||
#import <SimpleDebugger.h> | ||
|
||
SimpleDebugger *handler; | ||
|
||
int gettimeofday_new(struct timeval *t, void *a) { | ||
t->tv_sec = 1723532400; | ||
t->tv_usec = 0; | ||
return 0; | ||
} | ||
|
||
void callback(mach_port_t thread, arm_thread_state64_t state, std::function<void(bool removeBreak)> a) { | ||
state.__pc = (__uint64_t) &gettimeofday_new; | ||
thread_set_state(thread, ARM_THREAD_STATE64, (thread_state_t) &state, ARM_THREAD_STATE64_COUNT); | ||
a(false); | ||
} | ||
|
||
#endif | ||
|
||
+ (void)hookTime { | ||
#if EMG_ENABLE_FIX_TIME | ||
vm_address_t a = (vm_address_t) &gettimeofday; | ||
handler = new SimpleDebugger(); | ||
handler->setBreakpoint(a); | ||
handler->setExceptionCallback(&callback); | ||
handler->startDebugging(); | ||
#endif | ||
} | ||
|
||
+ (void)load { | ||
NSDictionary<NSString *, NSString *> *env = [[NSProcessInfo processInfo] environment]; | ||
if ([[env objectForKey:@"EMERGE_SHOULD_FIX_TIME"] isEqualToString:@"1"]) { | ||
[self hookTime]; | ||
} | ||
id previewBaseTest = NSClassFromString(@"EMGPreviewBaseTest"); | ||
[previewBaseTest performSelector:@selector(swizzle:) withObject:[self class]]; | ||
} | ||
|
||
@end |