-
Notifications
You must be signed in to change notification settings - Fork 1
/
transform.py
executable file
·152 lines (139 loc) · 4.03 KB
/
transform.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
import subprocess
import struct
rootdir = './'
files = os.listdir(rootdir)
files.sort()
prefix = '''
var importObject = {
env: {
i: function (arg1, arg2) {
arg1 -= arg2;
var a = arguments.length;
var b = arguments[2];
var c = b.__proto__.slice([...b]);
print('[+] imported function executed.');
},
}
};
var wasmCode = new Uint8Array(['''
postfix = ''']);
//////////////////////////////////////////////////////////////INIT
try {
var wasmModule = new WebAssembly.Module(wasmCode);
var wasmInstance = new WebAssembly.Instance(wasmModule, importObject);
print('[+] wasmCode validate.');
print(WebAssembly.validate(wasmCode));
}
catch (e) { print(e); }
////////////////////////////////////////////////////////////EXPORTS
try {
var wasmInstanceExported = wasmInstance.exports;
print('[+] wasmInstanceExported.');
try {
var wasmInstanceExportedTable = wasmInstance.exports.table;
for (var i = 0; i < 100; i++) {
print(wasmInstanceExportedTable.get(i));
var f = wasmInstanceExportedTable.get(i);
try {
var res = f(i);
res = f(5.40900887767170327461014974881E-315);
res = f({});
}
catch (e) { print(e); }
}
}
catch (e) { print(e); }
try {
print(wasmInstanceExported.main(0));
}
catch (e) { print(e); }
try {
for (var i in wasmInstanceExported) {
try {
print(eval('wasmInstanceExported.' + i + ';'));
}
catch (e) { print(e); }
try {
print(eval('wasmInstanceExported.' + i + '(0);'));
}
catch (e) { print(e); }
}
}
catch (e) { print(e); }
var wasmModuleExports = WebAssembly.Module.exports(wasmModule);
var varExports = [];
print('[+] wasmModuleExported.')
for (var i of wasmModuleExports) {
print(i + ' : ' + i.kind + ' : ' + i.name);
varExports.push(i.name);
}
for (var i of varExports) {
try {
print(eval('wasmInstanceExported.' + i + ';'));
}
catch (e) { print(e); }
try {
print(eval('wasmInstanceExported.' + i + '(0);'));
}
catch (e) { print(e); }
}
}
catch (e) { print(e) };
//////////////////////////////////////////////////////////////IMPORTS
try {
var wasmModuleImports = WebAssembly.Module.imports(wasmModule);
var varImports = [];
print('[+] wasmModuleImported.');
for (var i of wasmModuleImports) {
print(i + ' : ' + i.kind + ' : ' + i.name + ' : ' + i.module);
varImports.push(i.name);
}
for(var scalar of varImports){
print(scalar);
}
}
catch (e) { print(e) };
///////////////////////////////////////////////////////////////CUSTOM
try {
var sections = WebAssembly.Module.customSections(wasmModule, 'custom');
for(var i in sections){
print(sections[i]);
}
sections = WebAssembly.Module.customSections(wasmModule, 'name');
for(var i in sections){
print(sections[i]);
}
sections = WebAssembly.Module.customSections(wasmModule, 'unknown');
for(var i in sections){
print(sections[i]);
}
sections = WebAssembly.Module.customSections(wasmModule, '');
for(var i in sections){
print(sections[i]);
}
}
catch (e) { print(e); }
//////////////////////////////////////////////////////////////END
print('[+] End.');
'''
count = -1
for i in range(0, len(files)):
if (files[i].find('id:')!=-1) and (os.path.isdir(files[i])==False):
count = count + 1
print files[i]
file_object = open(files[i])
try:
content = file_object.read()
new_content = prefix
for c in content:
byte, = struct.unpack('B',c)
new_content += hex(byte) + ','
new_content += postfix
print new_content
new_file = 'id' + str(count)
with open(new_file, 'w') as f:
f.write(new_content)
finally:
file_object.close()
print '------------------------------'