XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

131 lines
2.6 KiB

  1. #! /usr/bin/php
  2. <?php
  3. $srcdir = dirname(__FILE__);
  4. require_once("$srcdir/../lib/Decompiler.class.php");
  5. if (file_exists("$srcdir/phpdc.debug.php")) {
  6. include("$srcdir/phpdc.debug.php");
  7. }
  8. function get_op($op)
  9. {
  10. switch ($op['op_type']) {
  11. case 1: // CONST
  12. return var_export($op['constant'], true);
  13. case 2: // IS_TMP_VAR
  14. return 't@' . $op['var'];
  15. case 4:
  16. return 'v$' . $op['var'];
  17. case 8: // UNUSED
  18. if (isset($op['opline_num'])) {
  19. return 'l#' . $op['opline_num'];
  20. }
  21. else {
  22. return '-';
  23. }
  24. default:
  25. return $op['op_type'] . $op['var'];
  26. }
  27. }
  28. function dump_opcodes($opcodes, $indent = '')
  29. {
  30. global $decompiler;
  31. $types = array('result' => 5, 'op1' => 20, 'op2' => 20);
  32. foreach ($decompiler->fixOpcode($opcodes) as $line => $op) {
  33. echo $indent;
  34. echo sprintf("%3d ", $op['lineno']);
  35. echo sprintf("%3x ", $line);
  36. $name = xcache_get_opcode($op['opcode']);
  37. if (substr($name, 0, 5) == 'ZEND_') {
  38. $name = substr($name, 5);
  39. }
  40. echo str_pad($name, 25);
  41. foreach ($types as $t => $len) {
  42. echo str_pad(isset($op[$t]) ? get_op($op[$t]) : "", $len);
  43. }
  44. printf("%5s", isset($op['extended_value']) ? $op['extended_value'] : "");
  45. echo "\n";
  46. }
  47. }
  48. function dump_function($name, $func, $indent = '')
  49. {
  50. if (isset($func['op_array'])) {
  51. $op_array = $func['op_array'];
  52. unset($func['op_array']);
  53. }
  54. else {
  55. $op_array = null;
  56. }
  57. var_dump($func);
  58. echo $indent, 'function ', $name, "\n";
  59. if (isset($op_array)) {
  60. dump_opcodes($op_array['opcodes'], " " . $indent);
  61. }
  62. }
  63. function dump_class($name, $class, $indent = '')
  64. {
  65. if (isset($class['function_table'])) {
  66. $funcs = $class['function_table'];
  67. unset($class['function_table']);
  68. }
  69. else {
  70. $funcs = null;
  71. }
  72. echo $indent, 'class ', $name, "\n";
  73. if (isset($funcs)) {
  74. foreach ($funcs as $name => $func) {
  75. dump_function($name, $func, " " . $indent);
  76. }
  77. }
  78. }
  79. if (!isset($argv[1])) {
  80. die("Usage: $argv[0] <file>\n");
  81. }
  82. $decompiler = new Decompiler();
  83. if (isset($argv[2])) {
  84. eval('$pk = ' . file_get_contents($argv[2]) . ';');
  85. }
  86. else {
  87. $pk = xcache_dasm_file($argv[1]);
  88. }
  89. $op_array = $funcs = $classes = null;
  90. if (isset($pk['op_array'])) {
  91. $op_array = $pk['op_array'];
  92. unset($pk['op_array']);
  93. }
  94. if (isset($pk['function_table'])) {
  95. $funcs = $pk['function_table'];
  96. unset($pk['function_table']);
  97. }
  98. if (isset($pk['class_table'])) {
  99. $classes = $pk['class_table'];
  100. unset($pk['class_table']);
  101. }
  102. var_dump($pk);
  103. if (isset($classes)) {
  104. foreach ($classes as $name => $class) {
  105. dump_class($name, $class);
  106. }
  107. }
  108. if (isset($funcs)) {
  109. foreach ($funcs as $name => $func) {
  110. dump_function($name, $func);
  111. }
  112. }
  113. if (isset($op_array)) {
  114. dump_opcodes($op_array['opcodes']);
  115. }