Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update time hook #225

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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