-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchfuscation.py
59 lines (55 loc) · 1.99 KB
/
batchfuscation.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
# batchfuscation
# Make sure that this is in the same folder as batchfuscation file
import os,subprocess
prevLine=''
def compare_files(file1, file2):
with open(file1, 'rb') as file1, open(file2, 'rb') as file2:
content1 = file1.read()
content2 = file2.read()
if content1 == content2:
return True
else:
return False
def __updateFile__(f, replaceWord, replaceWith):
for j in f:
if replaceWord in j:
f2.write(j.replace(replaceWord, str(replaceWith)))
else:
f2.write(j)
while True:
f = open('batchfuscation', 'r')
f2 = open('batchfuscation.txt', 'w')
for i in f:
if 'set' in i and "exitcodeAscii" not in i and 'rem' not in i:
if i.split()[1] == '/a':
index = i.find('=')
num1 = i.split(i[index])[1].split()[0]
num2 = i.split(i[index])[1].split()[2]
replaceWord = '%' + i.split('=')[0].split()[2] + '%'
replaceWith = (int(num1)%int(num2))
__updateFile__(f, replaceWord, replaceWith)
elif 'flag' in i:
f2.write(i)
else:
index = i.find('=')
replaceWord = '%' + i.split('=')[0].split()[1] + '%'
replaceWith = i[index+1:-1]
__updateFile__(f, replaceWord, replaceWith)
elif 'exitcodeAscii' in i:
replaceWord = "%" + i.split('=')[0].split()[1] + "%"
replaceWith = chr(int(prevLine.split()[3]))
__updateFile__(f, replaceWord, replaceWith)
elif '@echo' in i:
f2.write(i)
else:
f2.write(i)
prevLine=i
f2.close()
f.close()
if compare_files('batchfuscation', 'batchfuscation.txt') == True:
os.system('rm batchfuscation')
os.system('mv batchfuscation.txt batchfuscation')
exit()
else:
os.system('rm batchfuscation')
os.system('mv batchfuscation.txt batchfuscation')