-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmake.php
More file actions
executable file
·82 lines (60 loc) · 1.33 KB
/
make.php
File metadata and controls
executable file
·82 lines (60 loc) · 1.33 KB
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
80
81
#!/usr/bin/env php
<?php
if (!$lines = file('index-mac.html')) {
fail('could not read index-mac.html');
}
$buf = '';
$script = '';
$marker = false;
foreach ($lines as $line) {
if (strpos($line, '<script src="') === 0) {
$c = substr($line, strpos($line, '"') + 1);
$c = substr($c, 0, strpos($c, '"'));
$script .= file_get_contents($c);
if (!$marker) {
$buf .= '<script>$SCRIPT$</script>';
$marker = true;
}
continue;
}
$buf .= $line;
}
if (!file_put_contents('/tmp/script.js', $script)) {
fail('could not write script.js');
}
@unlink('/tmp/script.min.js');
run('cat /tmp/script.js | java -jar yuicompressor-2.4.6.jar --type js > /tmp/script.min.js');
$buf = str_replace('$SCRIPT$', file_get_contents('/tmp/script.min.js'), $buf);
$origBuf = $buf;
/* obfuscate xor */
for ($i = 0; $i < strlen($buf); $i++) {
$buf[$i] = $buf[$i] ^ 'A';
}
/* verify xor */
$v = $buf;
for ($i = 0; $i < strlen($v); $i++) {
$v[$i] = $v[$i] ^ 'A';
}
if ($v !== $origBuf) {
fail('xor verify failed');
}
if (!file_put_contents('game.dat', $buf)) {
fail('could not write game.dat');
}
unlink('/tmp/script.js');
unlink('/tmp/script.min.js');
echo "\nDONE\n";
function run($cmd)
{
echo "$cmd\n";
@system($cmd, $r);
if ($r != 0) {
echo "FAILED: cmd returned $r\n";
exit(1);
}
}
function fail($msg)
{
echo "FAILED $msg\n";
exit(1);
}