root/eaccelerator/tags/0.9.5-beta2/dasm.php

Revision 198, 8.4 kB (checked in by bart, 3 years ago)

* Patch for dasm.php form Stadler, see #23

  • 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     </style>
68 </head>
69 <body class="center">
70 <h1>eAccelerator disassembler</h1>
71 <?php
72     if (!isset($_GET['file']) || !is_file($_GET['file'])) {
73         die('File argument not given!');
74     }
75     $file = $_GET['file'];
76
77     $asm = eaccelerator_dasm_file($file);
78     if ($asm == null) {
79         die('File not found!');
80     }
81
82     $source = explode("\n", htmlentities(file_get_contents($_GET['file']), ENT_QUOTES, 'UTF-8'));
83 //    $source = explode("\n", file_get_contents($_GET['file']));
84
85     /* what do we need to do ? */
86     if (!isset($_GET['show'])) {
87         $show = '';
88     } else {
89         $show = $_GET['show'];
90     }
91     switch ($show) {
92         case 'main':
93             print_op_array($asm['op_array']);
94             break;
95         case 'functions':
96             if (is_array($asm['functions'][$_GET['name']])) {
97                 print_function($_GET['name'], $asm['functions'][$_GET['name']]);
98             }
99             break;
100         case 'classes':
101             if (is_array($asm['classes'][$_GET['name']])) {
102                 print_class($_GET['name'], $asm['classes'][$_GET['name']]);
103             }
104             if (isset($_GET['method']) && is_array($asm['classes'][$_GET['name']][$_GET['method']])) {
105                 print_method($_GET['method'], $asm['classes'][$_GET['name']][$_GET['method']]);
106             }
107             break;
108         default:
109             print_layout();
110     }
111
112 /* {{{ convert_string */
113     function convert_string($string, $length) {
114         if (strlen($string) > $length) {
115             $string = substr($string, 0, $length -4).' ...';
116         }
117         return htmlspecialchars($string);
118     }
119 /* }}} */
120
121 /* {{{ print_op_array */
122     function print_op_array($op_array) { ?>
123         <table>
124             <tr>
125                 <th>N</th>
126                 <th>Line</th>
127                 <th>Opcode</th>
128                 <th>Extented value</th>
129                 <th>Op1</th>
130                 <th>Op2</th>
131                 <th>Result</th>
132             </tr>
133     <?php
134         $count = count($op_array);
135         $line = 0;
136         global $source;
137         for ($i = 0; $i < $count; ++$i) {
138             /* if the lineno is greater, than the last line displayed, then show the
139                code until that line above the opcode */
140             if ($line < $op_array[$i]['lineno'])
141             {
142                 $print = $op_array[$i]['lineno'];
143             }
144             $code = '';
145             while($line < $print) {
146                 $code .= sprintf("%03d: %s\n", ($line + 1), $source[$line]);
147                 ++$line;
148             }
149             if ($code != '') {
150                 echo "<tr>\n";
151 //                echo '<td  class="source" colspan="7"><pre>' . highlight_string($code, true) . "</pre></td>\n";
152                 echo '<td  class="source" colspan="7"><pre>' . $code . "</pre></td>\n";
153                 echo "</tr>\n";
154             }
155     ?>
156             <tr>
157                 <td class="e"><?php echo $i; ?></td>
158                 <td><nobr><?php echo $op_array[$i]['lineno']; ?></nobr></td>
159                 <td><nobr><?php echo $op_array[$i]['opcode']; ?></nobr></td>
160                 <td><nobr><?php echo $op_array[$i]['extended_value']; ?></nobr></td>
161                 <td><nobr><?php echo convert_string($op_array[$i]['op1'], 50); ?></nobr></td>
162                 <td><nobr><?php echo convert_string($op_array[$i]['op2'], 50); ?></nobr></td>
163                 <td><nobr><?php echo convert_string($op_array[$i]['result'], 50); ?></nobr></td>
164             </tr>
165     <?php
166         }
167         $count = count($source);
168         if ($line < $count) {
169             $code = '';
170             while($line < $count) {
171                 $code .= sprintf("%03d: %s\n", ($line + 1), $source[$line]);
172                 ++$line;
173             }
174             if ($code != '') {
175                 echo "<tr>\n";
176 //                echo '<td  class="source" colspan="7"><pre>' . highlight_string($code, true) . "</pre></td>\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 style=\"text-align: left; width: 800px\">\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 => $data) {
221                 echo "<li><a href=\"?file=$file&show=classes&name=$name\">$name</a></li>";
222             }
223             echo "</ul></li>\n";
224
225         }
226         echo "</ul>\n";
227         echo "</div>\n";
228     }
229 /* }}} */
230
231 /* {{{ print a the class layout */
232     function print_class($name, $class) {
233         global $file;
234         echo "<h2>Class $name</h2>";
235         echo "<div style=\"text-align: left; width: 800px\"><ul>\n";
236         foreach($class as $method => $data) {
237             echo "<li><a href=\"?file=$file&amp;show=classes&amp;name=$name&amp;method=$method\">$method</a></li>\n";
238         }
239         echo "</ul></div>";
240     }
241 /* }}} */
242 ?>
243 </body>
244 </html>
245
246 <?php
247
248 /*
249  * Local variables:
250  * tab-width: 4
251  * c-basic-offset: 4
252  * End:
253  * vim600: noet sw=4 ts=4 fdm=marker
254  * vim<600: noet sw=4 ts=4
255  */
256
257 ?>
258
Note: See TracBrowser for help on using the browser.