Skip to content

Commit dc8c05c

Browse files
authored
Update time hook (#225)
1 parent a90510d commit dc8c05c

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let package = Package(
3737
dependencies: [
3838
.package(url: "https://github.com/swhitty/FlyingFox.git", exact: "0.16.0"),
3939
.package(url: "https://github.com/EmergeTools/AccessibilitySnapshot.git", exact: "1.0.2"),
40-
.package(url: "https://github.com/EmergeTools/SimpleDebugger.git", branch: "main"),
40+
.package(url: "https://github.com/EmergeTools/SimpleDebugger.git", exact: "1.0.0"),
4141
],
4242
targets: [
4343
// Targets are the basic building blocks of a package, defining a module or a test suite.

Sources/SnapshottingTestsObjc/EMGInvocationCreator.mm

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,18 @@ int gettimeofday_new(struct timeval *t, void *a) {
4242
return 0;
4343
}
4444

45-
void callback(mach_port_t thread, arm_thread_state64_t state, std::function<void(bool removeBreak)> a) {
46-
state.__pc = (__uint64_t) &gettimeofday_new;
47-
thread_set_state(thread, ARM_THREAD_STATE64, (thread_state_t) &state, ARM_THREAD_STATE64_COUNT);
48-
a(false);
49-
}
50-
5145
#endif
5246

5347
+ (void)hookTime {
5448
#if EMG_ENABLE_FIX_TIME
55-
vm_address_t a = (vm_address_t) &gettimeofday;
5649
handler = new SimpleDebugger();
57-
handler->setBreakpoint(a);
58-
handler->setExceptionCallback(&callback);
59-
handler->startDebugging();
50+
handler->hookFunction((void *) &gettimeofday, (void *) &gettimeofday_new);
6051
#endif
6152
}
6253

6354
+ (void)load {
6455
NSDictionary<NSString *, NSString *> *env = [[NSProcessInfo processInfo] environment];
65-
if ([[env objectForKey:@"EMERGE_SHOULD_FIX_TIME"] isEqualToString:@"1"]) {
56+
if (![[env objectForKey:@"EMERGE_DISABLE_FIX_TIME"] isEqualToString:@"1"]) {
6657
[self hookTime];
6758
}
6859
id previewBaseTest = NSClassFromString(@"EMGPreviewBaseTest");

0 commit comments

Comments
 (0)