Skip to content

Commit

Permalink
[logos] Add support for dynamic lookup of functions in %hookf. (#214)
Browse files Browse the repository at this point in the history
Functions passed to `%hookf` as literal strings will be dynamically looked up when applying the hook.
  • Loading branch information
uroboro committed Dec 18, 2016
1 parent 11b5754 commit dd5477a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 9 additions & 2 deletions bin/lib/Logos/Generator/Base/Function.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ use strict;
use Logos::Generator;
use Logos::Util;

sub getLiteralOrLookupFunctionName {
my $self = shift;
my $name = shift;
return "lookup\$".substr($name, 1, -1) if (substr($name, 0, 1) eq "\"" && substr($name, -1, 1) eq "\"");
return $name;
}

sub originalFunctionName {
my $self = shift;
my $function = shift;
return Logos::sigil("orig").$function->group->name."\$".$function->name;
return Logos::sigil("orig").$function->group->name."\$".$self->getLiteralOrLookupFunctionName($function->name);
}

sub newFunctionName {
my $self = shift;
my $function = shift;
return Logos::sigil("function").$function->group->name."\$".$function->name;
return Logos::sigil("function").$function->group->name."\$".$self->getLiteralOrLookupFunctionName($function->name);
}

sub originalFunctionCall {
Expand Down
7 changes: 6 additions & 1 deletion bin/lib/Logos/Generator/MobileSubstrate/Function.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ sub initializers {
my $function = shift;

my $return = "";
$return .= " MSHookFunction((void *)".$function->name;
$return .= " MSHookFunction((void *)";
if (substr($function->name, 0, 1) eq "\"") {
$return .= "MSFindSymbol(NULL, ".$function->name.")";
} else {
$return .= $function->name;
}
$return .= ", (void *)&".$self->newFunctionName($function);
$return .= ", (void **)&".$self->originalFunctionName($function);
$return .= ");";
Expand Down
2 changes: 1 addition & 1 deletion bin/logos.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package main;
use aliased 'Logos::Method';
use aliased 'Logos::Class';
use aliased 'Logos::Subclass';
use aliased 'Logos::StaticClassGroup' ;
use aliased 'Logos::StaticClassGroup';
use aliased 'Logos::Property';
use aliased 'Logos::Function';

Expand Down

0 comments on commit dd5477a

Please sign in to comment.