diff --git a/bin/lib/Logos/Generator/Base/Group.pm b/bin/lib/Logos/Generator/Base/Group.pm index cc8105a..c07a157 100644 --- a/bin/lib/Logos/Generator/Base/Group.pm +++ b/bin/lib/Logos/Generator/Base/Group.pm @@ -14,7 +14,7 @@ sub declarations { sub initializers { my $self = shift; my $group = shift; - my $return = "{"; + my $return = "{typedef void (*LOGOS_objchookfunc_ptr_t)(Class, SEL, IMP, IMP *);void *LOGOS_TMP_MESSAGE_PTR = dlsym(((void *) 0), \"LBHookMessage\"); LOGOS_objchookfunc_ptr_t LOGOS_HOOK_FUNC = LOGOS_TMP_MESSAGE_PTR != NULL ? (LOGOS_objchookfunc_ptr_t)LOGOS_TMP_MESSAGE_PTR : &MSHookMessageEx;"; foreach(@{$group->classes}) { $return .= Logos::Generator::for($_)->initializers if $_->initRequired; } diff --git a/bin/lib/Logos/Generator/MobileSubstrate/Function.pm b/bin/lib/Logos/Generator/MobileSubstrate/Function.pm index 23a4150..420de07 100644 --- a/bin/lib/Logos/Generator/MobileSubstrate/Function.pm +++ b/bin/lib/Logos/Generator/MobileSubstrate/Function.pm @@ -6,12 +6,18 @@ sub initializers { my $self = shift; my $function = shift; - my $return = ""; - $return .= "void * ".$self->variable($function)." = ".$self->_initExpression($function).";"; + my $return = "{typedef void (*LOGOS_hookfuncs_ptr_t)(const struct LHFunctionHook *, int);LOGOS_hookfuncs_ptr_t LOGOS_C_HOOK_FUNC = (LOGOS_hookfuncs_ptr_t)dlsym(((void *)0), \"LHHookFunctions\");"; + $return .= "if(LOGOS_C_HOOK_FUNC == NULL) {void * ".$self->variable($function)." = ".$self->_initExpression($function).";"; $return .= " MSHookFunction((void *)".$self->variable($function); $return .= ", (void *)&".$self->newFunctionName($function); $return .= ", (void **)&".$self->originalFunctionName($function); - $return .= ");"; + $return .= ");}else{"; + $return .= "void * ".$self->variable($function)." = ".$self->_initExpression($function).";"; + ## TODO: Add the LHFunctionHook struct to an array and then call LHHookFunctions only once + $return .= "LHFunctionHook hook;hook.function = (void *)".$self->variable($function); + $return .= ";hook.replacement = (void *)&".$self->newFunctionName($function); + $return .= ";hook.oldptr = (void **)&".$self->originalFunctionName($function); + $return .= ";const struct LHFunctionHook *hooks = {&hook};LOGOS_C_HOOK_FUNC(hooks, 1);}}"; return $return; } diff --git a/bin/lib/Logos/Generator/MobileSubstrate/Generator.pm b/bin/lib/Logos/Generator/MobileSubstrate/Generator.pm index f822ec3..db7f48e 100644 --- a/bin/lib/Logos/Generator/MobileSubstrate/Generator.pm +++ b/bin/lib/Logos/Generator/MobileSubstrate/Generator.pm @@ -15,7 +15,7 @@ sub preamble { if ($skipIncludes) { return $self->SUPER::preamble(); } else { - return join("\n", ($self->SUPER::preamble(), "#include ")); + return join("\n", ($self->SUPER::preamble(), "#include \n#include \n#include ")); } } diff --git a/bin/lib/Logos/Generator/MobileSubstrate/Method.pm b/bin/lib/Logos/Generator/MobileSubstrate/Method.pm index 7d8ae25..0d6309a 100644 --- a/bin/lib/Logos/Generator/MobileSubstrate/Method.pm +++ b/bin/lib/Logos/Generator/MobileSubstrate/Method.pm @@ -90,7 +90,7 @@ sub initializers { my $classvar = ($method->scope eq "+" ? $cgen->metaVariable : $cgen->variable); my $r = "{ "; if(!$method->isNew) { - $r .= "MSHookMessageEx(".$classvar.", ".$self->selectorRef($method->selector).", (IMP)&".$self->newFunctionName($method).", (IMP*)&".$self->originalFunctionName($method).");"; + $r .= "LOGOS_HOOK_FUNC(".$classvar.", ".$self->selectorRef($method->selector).", (IMP)&".$self->newFunctionName($method).", (IMP*)&".$self->originalFunctionName($method).");"; } else { if(!$method->type) { $r .= "char _typeEncoding[1024]; unsigned int i = 0; ";