-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
C function Logos directives #106
Conversation
Added %hookf and %origf directives for hooking C functions while supporting groups and using a variant of %orig. %hookf takes a variadic number of arguments: the function return type, the function name, the function argument list. It generates the original function function pointer from these values and the current group. %hookf takes a variadic number to pass to the original function, which is calculated from saving the current function name in %hookf and the current group.
Example code: #import <notify.h>
%hook NSNotificationCenter
- (void)postNotification:(NSNotification *)notification {
%orig;
}
%end
// notify_*
%hookf(uint32_t, notify_post, const char *name) {
uint32_t r = %origf(name);
return r;
}
%group gNSNotificationCenter
%hook NSNotificationCenter
- (void)postNotification:(NSNotification *)notification {
%orig;
}
%end
// notify_*
%hookf(uint32_t, notify_post, const char *name) {
uint32_t r = %origf(name);
return r;
}
%end /* gNSNotificationCenter */
%ctor {
if (someCondition) {
%init(gNSNotificationCenter);
} else {
%init();
}
} |
my $self = shift; | ||
my $function = shift; | ||
my $return = ""; | ||
$return .= "MSHookFunction(".$function->name.", &_logos_function\$".$function->group->name."\$_".$function->name.", &_logos_orig_function\$".$function->group->name."\$_".$function->name.")); "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is substrate-only, unfortunately. It should be in Logos::Generator::MobileSubstrate
. Maybe Logos::Generator::internal::Function
should throw an error.
From: Dustin L. Howett <dustin@howett.net> git-svn-id: http://svn.howett.net/svn/theos/trunk@643 4410221e-0ddf-4ce3-99c0-2db6c0dbc727 (cherry picked from commit 330c790)
bin/lib/Logos/Function.pm * added addArg function to modify the function arguments array. bin/lib/Logos/Generator/Base/Function.pm * added dummy functions from which to override in internal/MobileSubstrate Generators. bin/lib/Logos/Generator/MobileSubstrate/Function.pm * added functions from Base::Function: originalFunctionName, newFunctionName, declaration, initializers. * added originalFunctionCall for %orig directive. Uses new function getArgumentName. * added helper functions getArgumentName, escapeFunctionPointer and notSoSmartSplit. * escapeFunctionPointer uses Logos::Method::declarationForTypeWithName as code base to get the function pointer name starting offset to extract the argument name for %orig directive with original arguments.* notSoSmartSplit splits a string given a delimiter string. bin/lib/Logos/Group.pm * understood how arguments are received by perl functions and now addFunction parses them correctly, adding the function arguments using the new Function::addArg function. bin/logos.pl * added %orig overload allowing function hooks to call the original function using the same directive that methods use. * removed unnceessary %origf directive now obsolete due to %orig overload. * added &%orig overload allowing function hooks to get the function pointer to the original function using the same directive that methods use. * updated %hookf to use Logos::Patch logic so it supports grouping. * removed unnecessary helper functions mshookParse, mshookGetFunctionRetval, mshookGetFunctionName, mshookGetFunctionArgs.
New example code to test newer additions: %config(generator=MobileSubstrate);
//%config(generator=internal); //uncomment to break everything
%group _regrouped
%hookf(int, cool, int n, int(*(*fp)(int x))(int (*y)(int m)), const char *name, int sizes[10], struct {int x;} (*fp1)(struct{int y;} w), int(*fp2[10])(void)) {
otherfp = &%orig;
return %orig(0, fp, "int(*(*fp)(int x))(int (*y)(int m))", NULL, NULL);
}
%end
%hookf(int, cool, int n, int(*(*fp)(int x))(int (*y)(int m)), const char *name, int sizes[10], struct {int x;} (*fp1)(struct{int y;} w), int(*fp2[10])(void)) {
return %orig();
}
%ctor {
if (someCondition) {
%init(_regrouped);
} else {
%init();
}
} |
Maybe add support for other functions than Both of the functions they provide takes the same arguments in the same order as |
And has "better performance" (According to https://www.gnu.org/software/make/manual/html_node/Text-Functions.html regarding $(lastword ...) )
Would be great to see this merged soon. |
Also changed spaces to tabs.
Why has this not been merged? Is there another way to hook C functions or something? |
Cool feature |
It's `_theos_TRUE` but doesn't support "true"? ლ(ಠ益ಠლ)
While Generator::internal still does not support %hookf, it will not break logos anymore; instead it will print a C comment in the initializer. This change will allow using other function hooking mechanisms other than CydiaSubstrate's MSHookFunction.
Added %hookf and %origf directives for hooking C functions while supporting groups and using a variant of %orig.
%hookf takes a variadic number of arguments: the function return type, the function name, the function argument list. It generates the original function function pointer from these values and the current group.
%hookf takes a variadic number to pass to the original function, which is calculated from saving the current function name in %hookf and the current group.