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

Fixing location of mach_override project #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 mach_override_example.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions objc_runtime_hooker/objc_runtime_hooker/objc_runtime_hooker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,34 @@
// looking at the order of the 'link binary with libraries' phase.
__attribute__((constructor))
static void _hook_objc_runtime() {
kern_return_t err;
MACH_OVERRIDE(void, method_exchangeImplementations, (Method m1, Method m2), &err) {
printf("Exchanging implementations for method %s and %s.\n", sel_getName(method_getName(m1)), sel_getName(method_getName(m2)));
kern_return_t err;
MACH_OVERRIDE(void, method_exchangeImplementations, (Method m1, Method m2), &err) {
printf("Exchanging implementations for method %s and %s.\n", sel_getName(method_getName(m1)), sel_getName(method_getName(m2)));

method_exchangeImplementations_reenter(m1, m2);
}
END_MACH_OVERRIDE(method_exchangeImplementations);

MACH_OVERRIDE(void, method_setImplementation, (Method method, IMP imp), &err) {
printf("Setting new implementation for method %s.\n", sel_getName(method_getName(method)));

method_setImplementation_reenter(method, imp);
}
END_MACH_OVERRIDE(method_setImplementation);

MACH_OVERRIDE(void, class_replaceMethod, (Class cls, SEL name, IMP imp, const char *types), &err) {
printf("Setting new implementation for method %s of class%s.\n", sel_getName(name), class_getName(cls));

class_replaceMethod_reenter(cls, name, imp, types);
}
END_MACH_OVERRIDE(class_replaceMethod);

MACH_OVERRIDE(void, class_addMethod, (Class cls, SEL name, IMP imp, const char *types), &err) {
printf("Adding new for method %s of class%s.\n", sel_getName(name), class_getName(cls));

class_addMethod_reenter(cls, name, imp, types);
}
END_MACH_OVERRIDE(class_addMethod);


method_exchangeImplementations_reenter(m1, m2);
}
END_MACH_OVERRIDE(method_exchangeImplementations);

MACH_OVERRIDE(void, method_setImplementation, (Method method, IMP imp), &err) {
printf("Setting new implementation for method %s.\n", sel_getName(method_getName(method)));

method_setImplementation_reenter(method, imp);
}
END_MACH_OVERRIDE(method_setImplementation);
}
}