Skip to content

Commit

Permalink
Update time hook (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Feb 4, 2025
1 parent a90510d commit dc8c05c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/swhitty/FlyingFox.git", exact: "0.16.0"),
.package(url: "https://github.com/EmergeTools/AccessibilitySnapshot.git", exact: "1.0.2"),
.package(url: "https://github.com/EmergeTools/SimpleDebugger.git", branch: "main"),
.package(url: "https://github.com/EmergeTools/SimpleDebugger.git", exact: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
13 changes: 2 additions & 11 deletions Sources/SnapshottingTestsObjc/EMGInvocationCreator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,18 @@ int gettimeofday_new(struct timeval *t, void *a) {
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();
handler->hookFunction((void *) &gettimeofday, (void *) &gettimeofday_new);
#endif
}

+ (void)load {
NSDictionary<NSString *, NSString *> *env = [[NSProcessInfo processInfo] environment];
if ([[env objectForKey:@"EMERGE_SHOULD_FIX_TIME"] isEqualToString:@"1"]) {
if (![[env objectForKey:@"EMERGE_DISABLE_FIX_TIME"] isEqualToString:@"1"]) {
[self hookTime];
}
id previewBaseTest = NSClassFromString(@"EMGPreviewBaseTest");
Expand Down

0 comments on commit dc8c05c

Please sign in to comment.