-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbinary2vbs.py
54 lines (40 loc) · 875 Bytes
/
binary2vbs.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
#!/usr/bin/python
#__author__ @nopernik
import sys
header = '''Function myWrite(data)
For i = 1 to Len(data) Step 2
myFile.Write Chr(CLng("&H" & Mid(data,i,2)))
Next
End Function
Dim myArray
myArray = Array( _'''
footer = '''
Dim fObject
Set fObject = CreateObject("Scripting.FileSystemObject")
Dim myFile
Dim fileName
fileName = "binary.bin.js"
Set myFile = fObject.CreateTextFile(fileName, true , false)
For each i in myArray
myWrite(i)
Next
myFile.Close
'''
if not len(sys.argv[1:]):
print 'Usage: binary2vbs file'
exit()
f = open(sys.argv[1],'rb')
infile = f.read()
f.close()
line = infile.encode('hex')
for i in range(200,300,2):
if len(line) % i != 0:
n = i
break
print header
for b in [line[i:i+n] for i in range(0, len(line), n)]:
if not len(b) < n:
print '"%s", _' % b
else:
print '"%s")' % b
print footer