forked from sara-nl/racktables-contribs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function-analysis.php
executable file
·54 lines (48 loc) · 1.38 KB
/
function-analysis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/php
<?php
# This script outputs a list of functions that are used in local.php
# file, but don't belong to it. It requires a working php-pecl-parsekit
# package installation.
function get_all_function_calls ($tree)
{
$self = __FUNCTION__;
$ret = array();
if (array_key_exists ('opcodes', $tree))
foreach ($tree['opcodes'] as $item)
switch ($item['opcode'])
{
case 59: // ZEND_INIT_FCALL_BY_NAME
$ret[] = $item['op2']['constant'];
break;
case 60: // ZEND_DO_FCALL
$ret[] = $item['op1']['constant'];
break;
default:
break;
}
if (array_key_exists ('function_table', $tree))
foreach ($tree['function_table'] as $item)
$ret = array_merge ($ret, $self ($item));
return $ret;
}
function get_locally_declared_functions ($tree)
{
$self = __FUNCTION__;
$ret = array();
if (array_key_exists ('function_table', $tree))
foreach ($tree['function_table'] as $funcname => $item)
$ret = array_merge ($ret, array ($funcname), $self ($item));
return $ret;
}
function get_foreign_function_calls ($tree)
{
$ret = array();
$localnames = get_locally_declared_functions ($tree);
foreach (array_unique (get_all_function_calls ($tree)) as $func_call)
if (! in_array ($func_call, $localnames) and ! function_exists ($func_call))
$ret[] = $func_call;
return $ret;
}
$tree = parsekit_compile_file ('local.php');
print_r (get_foreign_function_calls ($tree));
?>