This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcps.py
323 lines (321 loc) · 17.4 KB
/
fcps.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import os.path
import datetime
import subprocess
from os import system,remove,rmdir,listdir,path,mkdir
from shutil import copy
current_year = datetime.datetime.now().year
import cryptography.fernet
from tkinter import messagebox
import tkinter as tk
from PIL import Image,ImageTk
key = cryptography.fernet.Fernet.generate_key()
x = cryptography.fernet.Fernet
#calling remove function from os module
gui = tk.Tk()
gui.title("FCP file creator")
gui.geometry('300x300')
gui.resizable(False, False)
try:
imagepath = Image.open('./FCPlogo.png')
image = ImageTk.PhotoImage(imagepath)
gui.iconphoto(False, image)
except FileNotFoundError:
pass
tk.Label(gui,text='*enter the filepath of the FCPSF').pack()
filepath = tk.StringVar()
entry = tk.Entry(gui,width=42,textvariable=filepath).pack()
tk.Label(gui,text='*enter the files list which would be contained in FCPSF').pack()
filelist = tk.StringVar()
entry = tk.Entry(gui,width=42,textvariable=filelist).pack()
def exitto(cool=True):
gui.destroy()
if cool == True:
messagebox.showinfo(title="good news",message=r"the creation process has been 100% completed")
else:
pass
exit()
def ask(file):
ask = tk.messagebox.askyesno(title="Confirm Deletion", message="""can the FCPDA delete the output folder if the app
made this folder allow to it to delete the folder but if you made this folder you should know that you must to change it's name because
names for folders(output,build,DSA) would make problems to the system""")
if ask:
try:
remove(f'./{file}')
remove('./FCPlogo.png')
except (FileNotFoundError,OSError):
for k in range(len(listdir('./output'))):
try:
remove(f'./{listdir("./output")[k]}')
except PermissionError:
pass
rmdir('./output')
exitto(False)
class filecontainer():
#the class start
def __init__(self):
#just make this function for the "self" of the class
pass#pass it because it does nothing
#no goal __inti__ function
def find_between(self,code:str,first_word:str, second_word:str, occurrence:int):
#this function is an important in-system function found in a lot of wedu programs
#-----------------------------------------------------------------------
#THE OCCURRENCE VAR IS THE SAME AS SAYING 'THE OCCURRENCE PARAMETER'
#-----------------------------------------------------------------------
lines = code.strip().split("\n")
#takes the main code and strip it and split \n
first_line_number = None
second_line_number = None
count = 0
"""it's important to set it 0 for this line(*1) which will increase it by 1
with each circle of a loop"""
for i, line in enumerate(lines):#i*0.5 is the same i in the line
#a for loop which will the value of i and line vars. by enumerate the lines var.
if first_word in line:
#if the first_word var. is found in line var increase the count var.
count += 1#*1 the line
if count == occurrence:
"""if the count var. has the same value as the occurrence var set
first_line_number as the same value as i"""
first_line_number = i#set first_line_number as the same value as i
if second_word in line and count == occurrence:
"""if the second_word var. is found in line var and count var.
has the same value as the occurrence var set second_line_number
as the same value as i"""
second_line_number = i#set second_line_number as the same value as i
break
#break the loop if the case for this if statement applyed after it's operations are completed
if first_line_number is not None and second_line_number is not None:
"""if these two doesn't have the value of None(they are having the same value
as i*0.5) that means (first and second word vars. must be found in line
and the count var has the same vaule as the occurrence var)"""
words_between = []#setting the words_between var as a plank list
for i in range(first_line_number + 1, second_line_number):
#a loop that it's range starts at(first_line_number + 1, second_line_number)
line = lines[i].strip()
"""the line var which is mostly a part from the lines var
and the part is special part identified from others by having the same
index as the value of i var. and after all of that it's all striped out"""
words_between.append(lines[i])
#this will add lines[i] to the word_between var. which is a list
return words_between#this will return the word_between var
else:#if first or second line_number is or both None
return [] # If either first_word or second_word is not found in the file or occurrence is not found
def list_to_string(self,lst):
#the same as the find_between function it will turn a list to a string
string = '\n'.join(lst)
#this var. the list after it's converted to a list
#----------------------------------------------------------
"""this is info about the return functiob but I can't but it after it because the
return line is the last line of any function that contains it"""
#----------------------------------------------------------
"""this function will return the value of the string var. and it will
replace \n with \\n inside(r'') as part to solve the PSRP"""
#----------------------------------------------------------
return string.replace(r'\\n',r'\n')
def FCmaker(self,file_path:str,filespatho_list:list,modepass):
self.mode = modepass
if file_path != f'{file_path[:-3]}.py':
messagebox.showerror(title="bad news", message=r"""an error because of filepath has no fileformat or it's not the .py file format
note:you must write the file name like this: 'name.py' no folder at the back or front of it and you must to write the .py file format""")
exitto(False)
try:
mkdir('./output')
except FileExistsError:
messagebox.showinfo(title="bad news you might get an error",message=r"""an error happened because you have folder with the name output
which the system automatically creates it so if it exists already that would cases an error now the system would ignore that for you but if there is any
thing in that folder had the same name as any of the automatically generated temp files and etc... you would get an error""")
"""this function will put data into any fc file
parameters:
file_path:str :the fc file path with file format off course
filespatholist:list : the files that you want to put in the fc file"""
#-----------------------------------------------------
self.filepath = file_path
#setting the file_path parameter to self.filepath
self.fileslist = filespatho_list
#setting the filespatho_list parameter to self.fileslist
#-----------------------------------------------------
"""setting the parameter as vars. to make them easier and better for both inside and
outside this function"""
#-----------------------------------------------------
self.i = 0
"""this is the first value for the self.i which is 0 and it will get higher by 1
each time it's being used in the and _extracted_from_FCmaker_9 it's important
because it's used as indentifier for each chank"""
#------------------------------------------------------
try:
self.delfile = open(f'./{self.filepath}', 'w')
self.delfile.write('')
self.delfile.close()#clear all data of the file in self.filepath
self.base = open(f'./{self.filepath}','w')
self.base.write(f"""import cryptography.fernet
import tkinter as tk
import os
from tkinter import messagebox
from PIL import Image,ImageTk
gui = tk.Tk()
gui.title("FCP file opener")
gui.geometry('300x300')
gui.resizable(False, False)
mode = {self.mode}
try:
imagepath = Image.open('./FCPlogo.png')
image = ImageTk.PhotoImage(imagepath)
gui.iconphoto(False, image)
except FileNotFoundError:
pass
tk.Label(gui,width=23,height=14,background='light grey').place(x=0,y=0)
tk.Label(gui,text='file path: {self.filepath[:-3]}.exe',background='light grey').place(x=0,y=0)
tk.Label(gui,text='number of files: {len(self.fileslist)}',background='light grey').place(x=0,y=30)
tk.Label(gui,text='FCP file version: 2.0 BETA',background='light grey').place(x=0,y=60)
tk.Label(gui,text="THE HEAVY DRAGON EDITION",background='light grey').place(x=0,y=90)
tk.Label(gui,text="FCP program mark type: -ODS",background='light grey').place(x=0,y=120)
tk.Label(gui,text="COPYRIGHT {current_year} WEDU",background='light grey').place(x=0,y=150)
tk.Label(gui,text="All RIGHTS RESERVED",background='light grey').place(x=0,y=180)
if mode == True:
tk.Label(gui,text='Enter the password').place(x=180,y=0)
PASSWORD = tk.StringVar()
entry = tk.Entry(gui,width=21,textvariable=PASSWORD).place(x=168,y=20)
else:
tk.Label(gui,text='this file is password free').place(x=168,y=0)
PASSWORD = {key}
def exito(case=True):
gui.destroy()
if case == True:
messagebox.showinfo(title="good news",message=r"the extracting process has been 100% completed")
else:
pass
exit()
def openfile(PASSWORD):\n""")
self.base.close()
for i2 in range(len(self.fileslist)):
#a loop that it's length is how many items in the self.fileslist var.
self._extracted_from_FCmaker_9(i2, self.fileslist)#calling the _extracted_from_FCmaker_9
self.base2 = open(f'./{self.filepath}','a')
print(f""" ORG_PASSWORD = {key}
if PASSWORD == ORG_PASSWORD:
try:
os.mkdir('./extracted_data')
except FileExistsError:
messagebox.showerror(title="bad news",message='''so this error happened because of the system wanted to make a folder with the name
extracted_data but a folder with the same name existed before the system would try make to the extracted_data folder''')
aska = tk.messagebox.showinfo(title="you should do something", message='''can the you delete the extracted_Data folder if the app
made this folder delete the folder but if you made this folder you should know that you must to change it's name because
names for folders(extracted_data,output,build,..._build,dist,DSA) would make problems to the FCP topic apps because these apps
would make folders with the same as these name to store or do operations and things like that but when they exist already the system would be in problem''')
exito(False)
else:
messagebox.showerror(title="wrong password",message='''you wrote a wrong password so you can't extract
the data expect if you wrote a correct password''')
exito(False)
""",file=self.base2)
self.base2.close()
self.base3 = open(f'./{self.filepath}','a')
for i3 in range(len(self.fileslist)):
print(f""" FREE{i3 + 1} = cryptography.fernet.Fernet(PASSWORD).decrypt(cryptography.fernet.Fernet(ORG_PASSWORD).encrypt(d{i3 + 1}[3:-2]))
FREEPATH{i3 + 1} = str(cryptography.fernet.Fernet(PASSWORD).decrypt(cryptography.fernet.Fernet(ORG_PASSWORD).encrypt(p{i3 + 1}[1:-1])),'utf-8')
open(f'./extracted_data/""" + '{FREEPATH' + f'{i3 + 1}' + "}'" + """,'x').close()
w""" + f"""{i3 + 1} = open(f'./extracted_data/""" + '{FREEPATH' + f'{i3 + 1}' + "}'" + """,'wb')
w""" + f"""{i3 + 1}.write(FREE""" + f'''{i3 + 1}''' + """)
w""" + f"""{i3 + 1}.close()""", file=self.base3)
print(""" exito()
if mode == True:
def openfiles():
print(bytes(PASSWORD.get()[2:-1],'utf-8'))
openfile((bytes(PASSWORD.get()[2:-1],'utf-8')))
button = tk.Button(gui,text='send',command=openfiles).place(x=213,y=42)
else:
def openfiles():
openfile(PASSWORD)
button = tk.Button(gui,text='extract',command=openfiles,width=10,borderwidth=7,background='blue',foreground='yellow').place(x=190,y=22)
gui.mainloop()""", file=self.base3)
self.base3.close()
except (PermissionError,AttributeError,OSError):
messagebox.showerror(title="bad news", message=r"an error because of wrong info or it's just Permission denied")
ask(self.filepath)
self.flo = True
print('starting py to exe')
try:
subprocess.run(f'cd {path.dirname(path.abspath(__file__))}/venv/Scripts & python -m nuitka --standalone --output-dir={path.dirname(path.abspath(__file__))} --enable-plugin=tk-inter --windows-console-mode=disable {path.dirname(path.abspath(__file__))}/{self.filepath}',shell=True, check=True)
except subprocess.CalledProcessError:
exitto(False)
while (0==0):
if os.path.exists(f'./omg.dist/{self.filepath[:-3]}.exe'):
os.system(f'''powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c cd {path.dirname(path.abspath(__file__))} & MOVE {self.filepath[:-3]}.dist {self.filepath[:-3]} & MOVE {self.filepath[:-3]}.build {self.filepath[:-3]}_build'"''')
while (0==0):
if os.path.exists(f'./{self.filepath[:-3]}/{self.filepath[:-3]}.exe'):
copy('./FCPlogo.png', f'./{self.filepath[:-3]}/FCPlogo.png')
break
break
try:
try:
if self.mode:
open(f'./output/{file_path[:-3]}_password.txt','x').close()
passfile = open(f'./output/{file_path[:-3]}_password.txt', 'w')
passfile.write(f'{key}')
passfile.close()
else:
pass
except FileExistsError:
ask(self.filepath)
remove(f"./{self.filepath}")
if not self.mode:
try:
rmdir('./output')
except (OSError,PermissionError):
pass
except (FileNotFoundError,PermissionError):
messagebox.showerror(title="bad news",message="an error happened because you wrote a name of folder before the file name\n or a Permisstion error but it's mostly because you wrote folder name you must to write filename with .py extension nothing more or less")
exitto(False)
if self.mode:
messagebox.showinfo(title="the password it's found in...",message=f"we sent it in a text file called\n'./{file_path[:-3]}_password.txt'")
else:
pass
exitto(True)
def _extracted_from_FCmaker_9(self, i2, fileslist):
self.i += 1
'''important var. that gives the number for each chank to make it diffrent from the
other chanks in the chank-base'''
try:
self.makefilechank = f""" d{self.i} = b'''"{open(fileslist[i2],'rb').read()}"'''\n"""
except FileNotFoundError:
messagebox.showerror(title="bad news",message=r"an error happened because one of the files in the filelist wasn't found")
remove(f'./{self.filepath}')
ask(self.filepath)
exitto(False)
#this is the part that makes the place for files data(data chank)
self.makepathchank = f""" p{self.i} = b'''"{fileslist[i2]}"'''\n"""
#this is the part that makes the place for files paths(path chank)
#--------------------------------------------------------
self.writingfile = open(f'{self.filepath}','a')
#start I/O operations for the fc file with the append mode
print(self.makefilechank, file=self.writingfile)#writing the data chank in the fc file
print(self.makepathchank, file=self.writingfile)#writing the path chank in the fc file
#writing both chanks into the fc file
self.writingfile.close()#close all file operations
FC = filecontainer()
class do():
def __init__(self):
self.modepass = False
def ch1(self):
self.modepass = True
def ch2(self):
self.modepass = False
def do_it(self):
print(filepath.get())
temp1 = filelist.get()
thelist = []
for i in range(len(temp1.split(','))):
thelist.append(temp1.split(',')[i])
print(thelist)
FC.FCmaker(filepath.get(),thelist,self.modepass)
dovar = do()
tk.Button(gui,text='password',command=dovar.ch1,background='red',foreground='yellow',borderwidth='4',font=("Arial", 10, "bold"),width=8).place(x=5,y=85)
tk.Button(gui,text='no password',command=dovar.ch2,background='red',foreground='yellow',borderwidth='4',font=("Arial", 10, "bold"),width=10).place(x=103,y=85)
tk.Button(gui,text='create',command=dovar.do_it,background='blue',foreground='yellow',borderwidth='4',font=("Arial", 10, "bold"),width=8).place(x=217,y=85)
tk.Label(gui,width=50,height=100,background='light gray').place(x=0,y=120)
tk.Label(gui,text='FCP file creator version: 2.0 BETA',background='light gray').place(x=0,y=130)
tk.Label(gui,text="THE HEAVY DRAGON EDITION",background='light gray').place(x=0,y=160)
tk.Label(gui,text="FCPFC mark type: -ODS",background='light gray').place(x=0,y=190)
tk.Label(gui,text=f"COPYRIGHT {current_year} WEDU",background='light gray').place(x=0,y=220)
tk.Label(gui,text="All RIGHTS RESERVED",background='light gray').place(x=0,y=250)
gui.mainloop()