-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasObfuscator.py
86 lines (73 loc) · 2.59 KB
/
PasObfuscator.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
import os
import io
import codecs
def getrandomdata(n):
import random
data=''
for x in range(0,n):
data+=chr(random.randint(1,100))
if ((data.__contains__('{')) or data.__contains__('}') or data.__contains__('$')):
return getrandomdata(n)
return data
def Encrypt(folderpath):
pasFiles = [f for f in os.listdir(folderpath) if f.endswith('.pas')]
for filename in pasFiles:
file = codecs.open(folderpath+'\\'+filename,'r','1251')
data=file.read()
file.close()
while (data.__contains__('\n\n')):
data=data.replace('\n\n','\n')
templst = data.split(' ')
dataa=''
for x in templst:
dataa+=x+'{'+getrandomdata(50)+'}'
dataa=dataa.replace(';','; \n \n \n \n \n \n ')
lstofdata = dataa.split('\n')
counter = 1
data=''
for x in lstofdata:
counter+=len(x)
if(counter>300):
data+=' \n'+x
counter=1
else:
data+=' '+x
output = codecs.open(f'{folderpath}\\{filename}','w','1251')
output.write(data)
print(f'{filename} | Encrypted')
def Decrypt(folderpath):
pasFiles = [f for f in os.listdir(folderpath) if f.endswith('.pas')]
for filename in pasFiles:
input = io.open(folderpath+'\\'+filename,'r',encoding='1251')
encData=input.read()
decData=''
write=True
for i in range(0,len(encData)):
if (encData[i]=='{'):
if (encData[i+1]=='$'):
decData+=encData[i]
continue
write= False
elif(encData[i-1]=='}'):
write=True
if (write):
decData+=encData[i]
while (decData.__contains__(' ')):
decData=decData.replace(' ',' ')
while (decData.__contains__('\n\n')):
decData=decData.replace('\n\n','\n')
decData=decData.replace(';',';\n')
output = open(f'{folderpath}\\{filename}','w',encoding='1251')
output.write(decData)
print(f'{filename} | Decrypted')
def main():
filename = input('Путь проекта: ')
print('Внимание, рекурсивное использование обфускатора приведет к порче проекта.')
answer = input('1 - Encrypt | 2 - Decrypt :')
if (answer=='1'):
Encrypt(filename)
elif (answer=='2'):
Decrypt(filename)
input()
if __name__=='__main__':
main()