-
Notifications
You must be signed in to change notification settings - Fork 2
/
postInspection.php
79 lines (60 loc) · 1.8 KB
/
postInspection.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$pi = new postInspection($argv);
class postInspection {
var $output_pattern = "Output: ";
var $pad_amount = 10;
var $do_trace = false;
var $trace_pattern = "";
function postInspection($argv) {
echo "\n\n";
echo "------------------------------ -\n";
echo "-- EVM3-ASM inspection ------ -\n";
echo "---------------------------- -\n";
$inspectfile = $argv[1];
if (!file_exists($inspectfile)) {
die("postInspection: Sorry, I don't know the file: ".$inspectfile);
}
if (isset($argv[2])) {
if (strlen($argv[2])) {
// That's our pattern for tracing.
$this->do_trace = true;
$this->trace_pattern = "/".$argv[2]."/";
}
}
// Grep the part of the file that we want.
$asm = $this->syscall("grep -P '^".$this->output_pattern."' ".$inspectfile);
$asm = trim($asm);
// Remove the piece in front of it.
$asm = preg_replace("/^".$this->output_pattern."/", "", $asm);
// Now split it into pieces by whitespace.
$bytes = preg_split("/\s+/", $asm);
$idx = 0;
foreach ($bytes as $b) {
$idx++;
$instruction = $b;
if ($this->do_trace) {
// echo $this->trace_pattern." | ".$instruction."\n\n";
if (preg_match($this->trace_pattern, $instruction)) {
// Ok, we're tracing that.
// So, let's figure out how much to pad it.
$pad = $this->pad_amount - strlen($instruction);
for ($i = 0; $i < $pad; $i++) {
$instruction .= " ";
}
$instruction .= " <-------";
}
}
echo sprintf("%04d",$idx)."\t".$instruction."\n";
}
echo "\n\n";
}
function syscall($command){
$result = "";
if ($proc = popen("($command)2>&1","r")){
while (!feof($proc)) $result .= fgets($proc, 1000);
pclose($proc);
return $result;
}
}
}
?>