Ejemplo n.º 1
0
function test()
{
    define('X', 2);
    define('Y', 3);
    fb_intercept('foo', 'bar');
    var_dump(X);
    define('Y', 4);
    var_dump(Y);
}
Ejemplo n.º 2
0
function boo()
{
    fb_intercept('foo', 'bar', 'bar');
    try {
        foo();
    } catch (Exception $e) {
        var_dump("caught:" . $e->getMessage());
    }
}
Ejemplo n.º 3
0
function main()
{
    $x[] = 1;
    fb_intercept('bar', 'baz', 'fiz');
    for ($i = 0; $i < 10000; $i++) {
        test('bar', $x);
    }
    var_dump('done');
}
Ejemplo n.º 4
0
function main()
{
    $c = new C();
    for ($i = 0; $i < 3; $i++) {
        test();
        foo();
        $c->snoot();
        if ($i == 1) {
            fb_intercept('foo', 'bar', false);
            fb_intercept('C::__call', 'swizzle');
        }
    }
}
Ejemplo n.º 5
0
<?php

trait T
{
    public function m()
    {
        echo "original\n";
    }
}
class A
{
    use T;
}
class B
{
    use T;
}
T::m();
$a1 = new A();
$a1->m();
fb_intercept("T::m", function () {
    echo "new\n";
});
$a2 = new A();
$a2->m();
$b1 = new B();
$b1->m();
T::m();
 private function deregister()
 {
     fb_intercept('', false);
 }
Ejemplo n.º 7
0
function getHHVMExpirationHandler($function)
{
    return function () use($function) {
        list($class, $method) = Utils\interpretCallback($function);
        $empty = true;
        foreach (State::$patches[$class][$method] as $offset => $patch) {
            if (!empty($patch)) {
                $empty = false;
                break;
            } else {
                unset(State::$patches[$class][$method][$offset]);
            }
        }
        if ($empty) {
            fb_intercept($function, null);
        }
    };
}
Ejemplo n.º 8
0
<?php

// Make sure that we can tell which class was called for intercepted static
// methods
class A
{
    public function foo()
    {
        echo 'foo called';
    }
}
class B extends A
{
}
fb_intercept('A::foo', function ($_, $called_on) {
    var_dump($called_on);
});
A::foo();
B::foo();
// Trigger run_intercept_handler_for_invokefunc codepath
$class = 'B';
$c = 'call_user_fun';
$c .= 'c';
$c(array($class, 'foo'));
Ejemplo n.º 9
0
<?php

class A
{
    function foo()
    {
        return 1;
    }
}
function main(A $a)
{
    var_dump($a->foo());
}
main(new A());
function handler($name, $obj, $args, $data, &$done)
{
    $done = true;
    return "string!";
}
fb_intercept('A::foo', 'handler');
main(new A());
Ejemplo n.º 10
0
fb_intercept('getlastmo', '__forbidden_function');
fb_intercept('getmygid', '__forbidden_function');
fb_intercept('getmyinode', '__forbidden_function');
fb_intercept('getmypid', '__forbidden_function');
fb_intercept('getmyuid', '__forbidden_function');
fb_intercept('ini_restore', '__forbidden_function');
fb_intercept('link', '__forbidden_function');
fb_intercept('pfsockopen', '__forbidden_function');
fb_intercept('posix_getlogin', '__forbidden_function');
fb_intercept('posix_getpwnam', '__forbidden_function');
fb_intercept('posix_getpwuid', '__forbidden_function');
// for debugging only
fb_intercept('posix_getrlimit', '__forbidden_function');
fb_intercept('posix_kill', '__forbidden_function');
fb_intercept('posix_mkfifo', '__forbidden_function');
fb_intercept('posix_setpgid', '__forbidden_function');
fb_intercept('posix_setsid', '__forbidden_function');
fb_intercept('posix_setuid', '__forbidden_function');
fb_intercept('posix_ttyname', '__forbidden_function');
fb_intercept('posix_uname', '__forbidden_function');
fb_intercept('proc_get_status', '__forbidden_function');
fb_intercept('proc_nice', '__forbidden_function');
fb_intercept('proc_terminate', '__forbidden_function');
fb_intercept('show_source', '__forbidden_function');
fb_intercept('symlink', '__forbidden_function');
fb_intercept('opcache_compile_file', '__forbidden_function');
fb_intercept('opcache_get_configuration', '__forbidden_function');
fb_intercept('opcache_get_status', '__forbidden_function');
fb_intercept('opcache_invalidate', '__forbidden_function');
fb_intercept('opcache_reset', '__forbidden_function');
Ejemplo n.º 11
0
<?php

function foo(&$a)
{
    var_dump('foo');
    $a = 1;
}
function bar(&$a)
{
    var_dump('bar');
    $a = 2;
}
function goo($name, $obj, $params, $data, &$done)
{
    return call_user_func_array($data, $params);
}
fb_intercept('foo', 'goo', 'bar');
$a = 0;
foo($a);
var_dump($a);
Ejemplo n.º 12
0
function main()
{
    $mc = new MagicCall();
    // Intercept static method
    fb_intercept('SubBlark2::sfrap', 'handler');
    Blark::sfrap();
    call_user_func(array('Blark', 'sfrap'));
    SubBlark::sfrap();
    call_user_func(array('SubBlark', 'sfrap'));
    SubBlark2::sfrap();
    call_user_func(array('SubBlark2', 'sfrap'));
    fb_intercept('Blark::sfrap', 'handler');
    Blark::sfrap();
    call_user_func(array('Blark', 'sfrap'));
    SubBlark::sfrap();
    call_user_func(array('SubBlark', 'sfrap'));
    SubBlark2::sfrap();
    call_user_func(array('SubBlark2', 'sfrap'));
    fb_intercept('Blark::sfrap', 'passthrough_handler');
    Blark::sfrap();
    call_user_func(array('Blark', 'sfrap'));
    fb_intercept('Blark::sfrap', array($mc, 'i_dont_exist_either'));
    Blark::sfrap();
    call_user_func(array('Blark', 'sfrap'));
    // Intercept non-static method
    $b = new Blark();
    fb_intercept('Blark::frap', 'handler');
    $b->frap();
    call_user_func(array($b, 'frap'));
    fb_intercept('Blark::frap', 'passthrough_handler');
    $b->frap();
    call_user_func(array($b, 'frap'));
    fb_intercept('Blark::frap', array($mc, 'i_dont_exist_either'));
    $b->frap();
    call_user_func(array($b, 'frap'));
    // MULTI-INTERCEPT!
    fb_intercept('frap', 'handler');
    fb_intercept('handler', 'passthrough_handler');
    frap('claptrap');
    // Reset all
    fb_intercept('', null);
    frap('claptrap');
    Blark::sfrap();
    $b->frap();
    // Intercept __call
    fb_intercept('MagicCall::__call', 'handler');
    $mc->blark('hi');
    fb_intercept('MagicCall::__call', 'passthrough_handler');
    $mc->blark('ho');
}
Ejemplo n.º 13
0
<?php

$a = 10;
$b = 20;
function &foo(&$n, $p)
{
    global $a;
    $n = 123;
    $p += 1;
    var_dump('foo');
    return $a;
}
function &bar(&$n, $p)
{
    global $b;
    $n = 456;
    $p += 2;
    var_dump('bar');
    return $b;
}
function fb_stubout_intercept_handler($name, $obj, $params, $data, $done)
{
    return call_user_func($data, $params);
}
fb_intercept('foo', 'fb_stubout_intercept_handler', 'bar');
$n = 0;
$d = 3;
$c =& foo($n, $d);
var_dump($c, $d);
$c = 30;
Ejemplo n.º 14
0
    call_user_func(array($b, 'frap'));
} catch (Exception $e) {
    echo "caught non-static call 2\n";
}
fb_intercept('Blark::frap', array($mc, 'i_dont_exist_either'));
try {
    call_user_func(array($b, 'frap'));
} catch (Exception $e) {
    echo "caught magic call 3\n";
}
// MULTI-INTERCEPT!
fb_intercept('frap', 'handler');
fb_intercept('handler', 'passthrough_handler');
try {
    call_user_func("frap", 'claptrap');
} catch (Exception $e) {
    echo "caught double intercept 1\n";
}
// Intercept __call
fb_intercept('MagicCall::__call', 'handler');
try {
    call_user_func(array($mc, "blark"), 'hi');
} catch (Exception $e) {
    echo "caught __call 1\n";
}
fb_intercept('MagicCall::__call', 'passthrough_handler');
try {
    call_user_func(array($mc, "blark"), 'ho');
} catch (Exception $e) {
    echo "caught __call 2\n";
}
Ejemplo n.º 15
0
{
    abstract function thing();
}
class D1 extends Base
{
    function thing()
    {
        return 1;
    }
}
class D2 extends Base
{
    function thing()
    {
        return 2;
    }
}
function go(Base $x)
{
    var_dump($x->thing());
}
go(new D1());
go(new D2());
function handler($name, $obj, $args, $data, &$done)
{
    $done = true;
    return "string!";
}
fb_intercept('D2::thing', 'handler');
go(new D1());
go(new D2());
Ejemplo n.º 16
0
{
    function &foo(&$n, $p)
    {
        global $a;
        $n = 123;
        $p += 1;
        var_dump('foo');
        return $a;
    }
}
class B
{
    function &bar(&$n, $p)
    {
        global $b;
        $n = 456;
        $p += 2;
        var_dump('bar');
        return $b;
    }
}
function fb_stubout_intercept_handler($name, $obj, $params, $data, $done)
{
    return call_user_func($data, $params);
}
fb_intercept('A::foo', 'fb_stubout_intercept_handler', 'B::bar');
$n = 0;
$d = 3;
$c =& A::foo($n, $d);
var_dump($c, $d);
$c = 30;
Ejemplo n.º 17
0
<?php

// Similar to nested_vm_exceptions, except throw intercepted functions
// into it also.
function error_handler()
{
    echo "Error handler\n";
    throw new Exception("unhandled exception");
}
set_error_handler('error_handler');
function unary_function($x)
{
    // Cause an undefined variable warning, and throw from the user
    // error handler.
    $x = $z;
}
function binary_function($x, $y)
{
}
fb_intercept('binary_function', 'unary_function', 'unary_function');
try {
    call_user_func_array('binary_function', array(12));
} catch (Exception $x) {
    echo "We hit our handler.\n";
    throw new Exception("Sup");
}
// Try it with no catch also.
call_user_func_array('binary_function', array(12));
Ejemplo n.º 18
0
function test()
{
    X::foo();
    fb_intercept('X::foo', 'bar', 'bar');
    X::foo();
}