root/eaccelerator/branches/0.9.5/dasm.php

Revision 206, 8.0 kB (checked in by bart, 2 years ago)

Included patch from Stadler from ticket #23. It adds a nice menu

and code highlighting.

  • Property svn:keywords set to svn:eol-style
Line 
1 <?php
2 /*
3    +----------------------------------------------------------------------+
4    | eAccelerator control panel                                           |
5    +----------------------------------------------------------------------+
6    | Copyright (c) 2004-2006 eAccelerator                                  |
7    | http://eaccelerator.net                                              |
8    +----------------------------------------------------------------------+
9    | This source file is subject to version 2.00 of the Zend license,     |
10    | that is bundled with this package in the file LICENSE, and is        |
11    | available through the world-wide-web at the following url:           |
12    | http://www.zend.com/license/2_00.txt.                                |
13    | If you did not receive a copy of the Zend license and are unable to  |
14    | obtain it through the world-wide-web, please send a note to          |
15    | license@zend.com so we can mail you a copy immediately.              |
16    +----------------------------------------------------------------------+
17
18    $ Id: $
19
20 /** config **/
21 $user = "admin";
22 $pw = "eAccelerator";
23 /** /config **/
24
25 /* {{{ auth */
26 if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_USER']) ||
27         $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw) {
28     header('WWW-Authenticate: Basic realm="eAccelerator control panel"');
29     header('HTTP/1.0 401 Unauthorized');
30     exit;
31 }
32 /* }}} */
33
34 ?>
35
36 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
37 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
38 <head>
39     <title>eAccelerator control panel</title>
40     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
41     <meta http-equiv="Content-Style-Type" content="text/css" />
42     <meta http-equiv="Content-Language" content="en" />
43
44     <style type="text/css" media="all">
45         body {background-color: #ffffff; color: #000000;}
46         body, td, th, h1, h2 {font-family: sans-serif;}
47         pre {margin: 0px; font-family: monospace;}
48         a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
49         a:hover {text-decoration: underline;}
50         table {border-collapse: collapse; width: 800px;}
51         .center {text-align: center;}
52         .center table { margin-left: auto; margin-right: auto; text-align: left;}
53         .center th { text-align: center !important; }
54         td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
55         td.source { background-color: #ffffff; font-size: small;}
56         h1 {font-size: 150%;}
57         h2 {font-size: 125%;}
58         .p {text-align: left;}
59         .e {background-color: #ccccff; font-weight: bold; color: #000000;}
60         .h,th {background-color: #9999cc; font-weight: bold; color: #000000;}
61         .v,td {background-color: #cccccc; color: #000000;}
62         .vr{background-color: #cccccc; text-align: right; color: #000000;}
63         img {float: right; border: 0px;}
64         hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
65         input {width: 150px}
66         h1 {width: 800px;  border: 1px solid #000000; margin-left: auto; margin-right: auto; background-color: #9999cc;}
67         .l {border: 1px solid #000000; text-align: left; width: 800px; margin: auto; font-size: 65%;}
68         .l h2 {font-size: 200%; text-align: center; }
69     </style>
70 </head>
71 <body class="center">
72 <h1>eAccelerator disassembler</h1>
73 <?php
74     if (!isset($_GET['file']) || !is_file($_GET['file'])) {
75         die('File argument not given!');
76     }
77     $file = $_GET['file'];
78
79     $asm = eaccelerator_dasm_file($file);
80     if ($asm == null) {
81         die('File not found!');
82     }
83
84     require_once('PHP_Highlight.php');
85     $h = new PHP_Highlight;
86     $h->loadFile($_GET['file']);
87     $source = $h->toArray();
88
89     /* what do we need to do ? */
90     if (!isset($_GET['show'])) {
91         $show = '';
92     } else {
93         $show = $_GET['show'];
94     }
95
96     print_layout();
97     switch ($show) {
98         case 'main':
99             print_op_array($asm['op_array']);
100             break;
101         case 'functions':
102             if (is_array($asm['functions'][$_GET['name']])) {
103                 print_function($_GET['name'], $asm['functions'][$_GET['name']]);
104             }
105             break;
106         case 'methods':
107             if (isset($_GET['method']) && is_array($asm['classes'][$_GET['name']][$_GET['method']])) {
108                 print_method($_GET['method'], $asm['classes'][$_GET['name']][$_GET['method']]);
109             }
110             break;
111     }
112
113 /* {{{ convert_string */
114     function convert_string($string, $length) {
115         if (strlen($string) > $length) {
116             $string = substr($string, 0, $length -4).' ...';
117         }
118         return htmlspecialchars($string);
119     }
120 /* }}} */
121
122 /* {{{ print_op_array */
123     function print_op_array($op_array) { ?>
124         <h2>Global file op_array</h2>
125         <table>
126             <tr>
127                 <th>N</th>
128                 <th>Line</th>
129                 <th>Opcode</th>
130                 <th>Extented value</th>
131                 <th>Op1</th>
132                 <th>Op2</th>
133                 <th>Result</th>
134             </tr>
135     <?php
136         $count = count($op_array);
137         $line = 0;
138         global $source;
139         for ($i = 0; $i < $count; ++$i) {
140             /* if the lineno is greater, than the last line displayed, then show the
141                code until that line above the opcode */
142             if ($line < $op_array[$i]['lineno'])
143             {
144                 $print = $op_array[$i]['lineno'];
145             }
146             $code = '';
147             while($line < $print) {
148                 $code .= sprintf("%03d: %s\n", ($line + 1), $source[$line]);
149                 ++$line;
150             }
151             if ($code != '') {
152                 echo "<tr>\n";
153                 echo '<td  class="source" colspan="7"><pre>' . $code . "</pre></td>\n";
154                 echo "</tr>\n";
155             }
156     ?>
157             <tr>
158                 <td class="e"><?php echo $i; ?></td>
159                 <td><nobr><?php echo $op_array[$i]['lineno']; ?></nobr></td>
160                 <td><nobr><?php echo $op_array[$i]['opcode']; ?></nobr></td>
161                 <td><nobr><?php echo $op_array[$i]['extended_value']; ?></nobr></td>
162                 <td><nobr><?php echo convert_string($op_array[$i]['op1'], 50); ?></nobr></td>
163                 <td><nobr><?php echo convert_string($op_array[$i]['op2'], 50); ?></nobr></td>
164                 <td><nobr><?php echo convert_string($op_array[$i]['result'], 50); ?></nobr></td>
165             </tr>
166     <?php
167         }
168         $count = count($source);
169         if ($line < $count) {
170             $code = '';
171             while($line < $count) {
172                 $code .= sprintf("%03d: %s\n", ($line + 1), $source[$line]);
173                 ++$line;
174             }
175             if ($code != '') {
176                 echo "<tr>\n";
177                 echo '<td  class="source" colspan="7"><pre>' . $code . "</pre></td>\n";
178                 echo "</tr>\n";
179             }
180
181         }
182     ?>
183         </table>
184     <?php
185     }
186 /* }}} */
187
188 /* {{{ print_function: print the given function */
189     function print_function($name, $op_array) {
190         echo "<h2>Function: $name</h2>";
191         print_op_array($op_array);
192     }
193 /* }}} */
194
195 /* {{{ print_method: print the given method */
196     function print_method($name, $op_array) {
197         echo "<h2>Method: $name</h2>";
198         print_op_array($op_array);
199     }
200 /* }}} */
201
202 /* {{{ print_layout: print the layout of this script */
203     function print_layout() {
204         global $asm, $file;
205         echo "<h2>Script layout</h2>\n";
206         echo "<div class=\"l\">\n";
207         echo "<ul>\n";
208         if (isset($asm['op_array'])) {
209             echo "<li><a href=\"?file=$file&show=main\">Global file op_array</a></li>";
210         }
211         if (isset($asm['functions']) && count($asm['functions']) > 0) {
212             echo "<li>Functions<ul>\n";
213             foreach ($asm['functions'] as $name => $data) {
214                 echo "<li><a href=\"?file=$file&show=functions&name=$name\">$name</a></li>";
215             }
216             echo "</ul></li>\n";
217         }
218         if (isset($asm['classes']) && count($asm['classes']) > 0) {
219             echo "<li>Classes<ul>\n";
220             foreach ($asm['classes'] as $name => $class) {
221                 echo "<li>$name<ul><li style=\"list-style-type: none\">Methods</li>\n";
222                 foreach (array_keys($class) as $method) {
223                     echo "<li><a href=\"?file=$file&amp;show=methods&amp;name=$name&amp;method=$method\">$method</a></li>\n";
224                 }
225                 echo "</ul></li>\n";
226             }
227             echo "</ul></li>\n";
228
229         }
230         echo "</ul>\n";
231         echo "</div>\n";
232     }
233 /* }}} */
234 ?>
235 </body>
236 </html>
237
238 <?php
239
240 /*
241  * Local variables:
242  * tab-width: 4
243  * c-basic-offset: 4
244  * End:
245  * vim600: noet sw=4 ts=4 fdm=marker
246  * vim<600: noet sw=4 ts=4
247  */
248
249 ?>
250
Note: See TracBrowser for help on using the browser.