This repository was archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdiff.php
More file actions
113 lines (102 loc) · 1.96 KB
/
diff.php
File metadata and controls
113 lines (102 loc) · 1.96 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
if ($argc < 3) {
die("Usage: diff.php <xLua DLL> <Original Lua DLL>");
}
chdir('x64\Debug');
// Lua 5.3
$ops = array(
'MOVE',
'LOADK',
'LOADKX',
'LOADBOOL',
'LOADNIL52',
'GETUPVAL',
'GETTABUP',
'GETTABLE',
'SETTABUP',
'SETUPVAL',
'SETTABLE',
'NEWTABLE',
'SELF',
'ADD',
'SUB',
'MUL',
'MOD',
'POW',
'DIV',
'IDIV',
'BAND',
'BOR',
'BXOR',
'SHL',
'SHR',
'UNM',
'BNOT',
'NOT',
'LEN',
'CONCAT',
'JMP52',
'EQ',
'LT',
'LE',
'TEST',
'TESTSET',
'CALL',
'TAILCALL',
'RETURN',
'FORLOOP',
'FORPREP',
'TFORCALL',
'TFORLOOP52',
'SETLIST52',
'CLOSURE',
'VARARG',
'EXTRAARG'
);
function callDumper($dll)
{
passthru('xLuaDumper.exe ' . $dll, $ret);
if ($ret) {
die('Failed to call dumper on ' . $dll);
}
return file_get_contents('out.luac');
}
function loadOps($lua)
{
$ops = unpack('I', $lua)[1];
if ($ops * 4 >= strlen($lua)) {
die('Bad opcodes');
}
$result = array();
for ($i = 1; $i <= $ops; $i++) {
$result[] = ord($lua[$i * 4]) & 0b111111;
}
return $result;
}
// 45 为 xLua 兼容模式下的头部长度
$xlua = loadOps(substr(callDumper($argv[1]), 45));
$default = loadOps(substr(callDumper($argv[2]), 46));
$mapping = array();
for ($i = 0; $i < count($xlua); $i++) {
$mapping[$xlua[$i]] = $default[$i];
}
ksort($mapping);
$out = '';
foreach ($mapping as $k => $v) {
$out .= 'map[' . $k . '] = Op.' . $ops[$v] . ";\n";
}
for ($i = 0; $i < count($ops); $i++) {
if (!isset($mapping[$i])) {
$out .= '// map[' . $i . "] = Op.;\n";
}
}
$out .= "// ----\n";
$counter = 0;
for ($i = 0; $i < count($ops); $i++) {
if (!in_array($i, $mapping)) {
$out .= '// Unknown: ' . $i . ' - ' . $ops[$i] . "\n";
$counter++;
}
}
$out .= "// Total: " . count($ops) . ', Unknown: ' . $counter . "\n";
echo ($out);