Compare commits

..

No commits in common. "f329f83ec087a8efca4abd1e6e5dec4f759a71f8" and "eac7311e451c41c4cefafec67d25de9b1a3f9126" have entirely different histories.

11 changed files with 50 additions and 276 deletions

11
.vscode/launch.json vendored
View File

@ -9,16 +9,7 @@
"type": "debugpy", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "main.py", "program": "main.py",
"args": "--debug",
"console": "integratedTerminal" "console": "integratedTerminal"
}, }
{
"name": "Python 包含参数",
"type": "debugpy",
"request": "launch",
"program": "main.py",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
},
] ]
} }

View File

@ -1,4 +1,4 @@
{ {
"python.analysis.typeCheckingMode": "off", "python.analysis.typeCheckingMode": "off",
"python.analysis.autoImportCompletions": false "python.analysis.autoImportCompletions": true
} }

View File

@ -1 +0,0 @@
0.0.1

View File

@ -2,9 +2,7 @@ UnsupportedSystem = "当前操作系统不受支持"
PermissionDeniedLinux = "在 linux 操作系统系统下,请使用 root 权限进行安装" PermissionDeniedLinux = "在 linux 操作系统系统下,请使用 root 权限进行安装"
PermissionDeniedWin = "权限不足,请以管理员身份运行此程序" PermissionDeniedWin = "权限不足,请以管理员身份运行此程序"
InstallWelcome = "欢迎安装 PEInjector" InstallWelcome = "欢迎安装 PEInjector"
UpgradeWelcome = "更新 PEInjector"
InstallInfo = "PEinjector 是增强 WindowsPE 的一个工具和平台" InstallInfo = "PEinjector 是增强 WindowsPE 的一个工具和平台"
UpgradeInfo = "接下来将更新 PEinjector 和 ventoy"
DownloadInstallTitle = "下载必要文件" DownloadInstallTitle = "下载必要文件"
DownloadInstall = "在开始之前,我们需要下载一些依赖文件\n如果您的网络状况不佳请手动下载 peinjector 和 ventoy 并解压到 software 文件夹" DownloadInstall = "在开始之前,我们需要下载一些依赖文件\n如果您的网络状况不佳请手动下载 peinjector 和 ventoy 并解压到 software 文件夹"
StartInstall = "开始安装" StartInstall = "开始安装"
@ -19,7 +17,5 @@ InstallIjTitle = "安装 PEinjector"
InstallIjInfo = "PEinjector主程序正在安装中请稍等" InstallIjInfo = "PEinjector主程序正在安装中请稍等"
FinishInstall = "完成安装" FinishInstall = "完成安装"
InstallFinishTitle = "安装已完成" InstallFinishTitle = "安装已完成"
InstallFinishInfo = "PEinjector已经安装到您的设备\n点击下方按钮重新启动程序以管理 PEinjector" InstallFinishInfo = "PEinjector已经安装到您的设备\n点击下方按钮关闭程序并重新启动以管理 PEinjector"
InstallFinishBtn = "重启" InstallFinishBtn = "关闭"
HomeWelcome = "欢迎使用 PEinjector"
HomeInfo = "一个增强 WindowsPE 的一个工具和平台\n点击下方版本号进行更新"

View File

@ -1 +0,0 @@
DISKMOUNT = ""

View File

@ -14,10 +14,10 @@ levels = {
} }
def log_init() -> None: def init() -> None:
logging.basicConfig(filename=config.LOGPATH, logging.basicConfig(filename=config.LOGPATH,
format='[%(asctime)s][%(levelname)s] %(message)s', format='[%(asctime)s][%(levelname)s] %(message)s',
level=levels[config.LOGLEVEL], filemode='w') level=levels[config.LOGLEVEL])
def info(msg: str) -> None: def info(msg: str) -> None:
@ -53,7 +53,3 @@ def print(*args, end="\n") -> None:
if (10 >= levels[config.LOGLEVEL]): if (10 >= levels[config.LOGLEVEL]):
sys.stdout.write(msg + end) sys.stdout.write(msg + end)
logging.debug(msg) logging.debug(msg)
def trace_sys(msg: str) -> None:
logging.info(msg)

View File

@ -1,3 +1,3 @@
from ui import win from ui import win
if __name__ == "__main__": if __name__ == "__main__":
win.run() win.main()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,65 +0,0 @@
import os
import sys
from magictk import mtk, color_tmpl
from magictk import fontconfig
from ui.lang import l
from logger.logger import *
from lib import vars
from tkinter import Label as tkLabel
now_frame = None
master: mtk.Frame = None
def show_home_page():
global now_frame, master
first_page = mtk.Frame(master)
mtk.Frame(first_page, w=10000).pack(fill="both", expand=True)
smileimg = mtk.PhotoImage(file="res"+os.sep+"smile.gif")
frames = mtk.Frame(first_page)
smilelabel = tkLabel(frames, image=smileimg,
background=color_tmpl.default_color["background"])
smilelabel.pack()
smilelabel.image = smileimg
frames.pack(fill='x')
mtk.Frame(first_page, w=10000, height=40).pack(fill="x")
mtk.Label(first_page, text=l("HomeWelcome"),
anchor='center', font=(fontconfig.getfont(), 20), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x')
mtk.Label(first_page, text="\n"+l("HomeInfo"),
anchor='center', font=(fontconfig.getfont(), 10), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x')
mtk.Frame(first_page, height=30).pack()
buttonlist = mtk.Frame(first_page)
with open(vars.DISKMOUNT+os.sep+"PEinjector"+os.sep+"VERSION", 'r') as file:
version = file.read().replace("\n", "")
with open("VERSION", 'r') as file:
hubversion = file.read().replace("\n", "")
def restart_to_update(*args):
warn("[homeui]start update, exit")
python_path = sys.executable
os.execl(python_path, python_path, __file__.replace(
"ui"+os.sep+"homeui.py", "main.py"), "--upgrade", "--dis-permission-error")
def open_update(*args):
info("[homeui]open in webbrowser")
__import__("webbrowser").open(
"http://git.hmtsai.cn/cxykevin/injectorHub")
mtk.Frame(buttonlist, height=10).pack(side="left")
mtk.ButtonLight(buttonlist, text="PEinjector "+version,
w=140, func=restart_to_update, color_type="success").pack(side="left")
mtk.ButtonLight(buttonlist, text="Hub "+hubversion,
w=100, color_type="primary", func=open_update).pack(side="left")
buttonlist.pack()
mtk.Frame(first_page, w=10000).pack(fill="both", expand=True)
first_page.pack(fill="both", expand=True)
now_frame = first_page
def home_ui(root: mtk.Frame):
global master
install_root_frame = mtk.Frame(root)
master = install_root_frame
show_home_page()
install_root_frame.pack(fill="both", expand=True)

View File

@ -1,5 +1,6 @@
import json import json
import os import os
from turtle import bgcolor
from magictk import mtk, color_tmpl from magictk import mtk, color_tmpl
from magictk import fontconfig from magictk import fontconfig
from ui.lang import l from ui.lang import l
@ -11,20 +12,13 @@ from logger.logger import *
now_frame = None now_frame = None
master: mtk.Frame = None master: mtk.Frame = None
UPGRADE = 0
def show_first_page(): def show_first_page():
global now_frame, master global now_frame, master
first_page = mtk.Frame(master,) first_page = mtk.Frame(master,)
mtk.Frame(first_page, w=10000).pack(fill="both", expand=True) mtk.Frame(first_page, w=10000).pack(fill="both", expand=True)
if (UPGRADE): mtk.Label(first_page, text=l("InstallWelcome"),
mtk.Label(first_page, text=l("UpgradeWelcome"),
anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x')
mtk.Label(first_page, text="\n"+l("InstallInfo"),
anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x')
else:
mtk.Label(first_page, text=l("UpgradeWelcome"),
anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x') anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x')
mtk.Label(first_page, text="\n"+l("InstallInfo"), mtk.Label(first_page, text="\n"+l("InstallInfo"),
anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x')
@ -285,10 +279,8 @@ def change_page_finish():
anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x')
def closecallback(*args): def closecallback(*args):
warn("restart from installer") info("close from installer")
python_path = sys.executable finish_page.root.quit()
os.execl(python_path, python_path, __file__.replace(
"ui"+os.sep+"installer.py", "main.py"))
btnframe = mtk.Frame(finish_page, height=30) btnframe = mtk.Frame(finish_page, height=30)
mtk.ButtonFill(finish_page, text=l( mtk.ButtonFill(finish_page, text=l(

174
ui/win.py
View File

@ -1,13 +1,9 @@
import shutil
from tkinter import messagebox from tkinter import messagebox
from magictk import mtk from magictk import mtk
from logger.logger import * from logger.logger import *
from logger import config
from ui import nav from ui import nav
from ui import installer from ui import installer
from ui import homeui
from lib import get_disk from lib import get_disk
from lib import vars
from ui.lang import load_lang, l from ui.lang import load_lang, l
import sys import sys
import getpass import getpass
@ -15,178 +11,48 @@ import platform
import ctypes import ctypes
import os import os
import locale import locale
import traceback
import textwrap init()
nlang = locale.getdefaultlocale()[0].lower() nlang = locale.getdefaultlocale()[0].lower()
def check_args(arg, check):
if len(arg) >= len(check):
if (arg[:len(check)] == check):
return 1
return 0
DISPERMISSION = 0
DEBUG = 0
NOTRACE = 0
UPGRADE = 0
DEVICE = ""
SHOW_VERSION = 0
for i in sys.argv[1:]:
if (check_args(i, "/?") or check_args(i, "--help")):
print(""" injector Hub
Usage: hub [options]
Options:
--help Show this help info and exit
--version, -V Get hub version
--lang=<zh_cn/en_us> Set language
--install, -i Install PEinjector
--upgrade, -U Upgrade PEinjector
--device, -D Set device (mount path)
--clean Clean download cache
Debug Options:
--debug Open debug mode (raise all errors)
--dis-permission-error Do not show permission error
--log-level=<level> Set log level (debug,info,warning,err)
--no-trace Do not trace OS version
""")
sys.exit()
elif (check_args(i, "--lang")):
nlang = i.split("=")[-1]
elif (check_args(i, "--dis-permission-error")):
DISPERMISSION = 1
elif (check_args(i, "--log-level")):
config.LOGLEVEL = i.split("=")[-1]
elif (check_args(i, "--debug")):
DEBUG = 1
elif (check_args(i, "--no-trace")):
NOTRACE = 1
elif (check_args(i, "--upgrade") or check_args(i, "-U")):
UPGRADE = 1
elif (check_args(i, "--install") or check_args(i, "-i")):
UPGRADE = 2
elif (check_args(i, "--device") or check_args(i, "-D")):
DEVICE = i.split("=")[-1]
elif (check_args(i, "--clean")):
if (os.path.exists("software")):
info("[win]clean install cache")
shutil.rmtree("software")
sys.exit()
elif (check_args(i, "--version") or check_args(i, "-V")):
SHOW_VERSION = 1
else:
print("Unknown Command: \""+i+"\"\nUse Command \"--help\" to get info")
sys.exit(128)
if (nlang+".toml" not in os.listdir("lang")): if (nlang+".toml" not in os.listdir("lang")):
nlang = "en_us" nlang = "en_us"
load_lang(nlang)
disk_res = get_disk.find_hub_disk()
def main(): errno = disk_res[0]
log_init() root_disk = disk_res[1]
if (DEBUG == 1): if (errno == 1):
info("[win]< debug mode >")
if (NOTRACE == 0):
info("[trace]open trace")
trace_sys(f"[trace]OS={platform.system()}")
trace_sys(f"[trace]VER={platform.version()}")
trace_sys(f"[trace]CPU={platform.processor()}")
trace_sys(f"[trace]ARCH={str(platform.architecture()[0])}")
trace_sys(f"[trace]PYVER={platform.python_version()}")
trace_sys(f"[trace]PYIMP={platform.python_implementation()}")
load_lang(nlang)
disk_res = get_disk.find_hub_disk()
errno = disk_res[0]
if (DEVICE == ""):
root_disk = disk_res[1]
else:
root_disk = DEVICE
if (errno == 1):
messagebox.showerror("Injector Hub Error", root_disk) messagebox.showerror("Injector Hub Error", root_disk)
sys.exit(1) sys.exit(1)
if (SHOW_VERSION == 1): elif (errno == 2):
with open("VERSION", 'r') as file:
ver = file.read()
print(f" injector Hub \n\nHub Version: "+ver)
if (DEVICE == "" and errno == 2):
print("PEinjector Version: Not Found")
elif not (os.path.exists(root_disk+os.sep+"PEinjector"+os.sep+"VERSION")):
print("PEinjector Version: Not Found")
else:
with open(root_disk+os.sep+"PEinjector"+os.sep+"VERSION", 'r') as file:
pver = file.read()
print("PEinjector Version: "+pver)
sys.exit()
if (errno == 2 or UPGRADE == 1 or UPGRADE == 2):
if (UPGRADE == 0):
info("[win]cannot find installed disk") info("[win]cannot find installed disk")
elif (UPGRADE == 1):
info("[win]upgrade")
if DISPERMISSION == 0:
if (platform.system() == "Linux" and getpass.getuser() != "root"): if (platform.system() == "Linux" and getpass.getuser() != "root"):
err("permission denied in linux") messagebox.showerror("Injector Hub Error", l("PermissionDeniedLinux"))
messagebox.showerror("Injector Hub Error",
l("PermissionDeniedLinux"))
if (DEBUG == 0):
sys.exit(1) sys.exit(1)
else:
sys.exit()
if (platform.system() == "Windows" and ctypes.windll.shell32.IsUserAnAdmin() == False): if (platform.system() == "Windows" and ctypes.windll.shell32.IsUserAnAdmin() == False):
err("permission denied in windows") messagebox.showerror("Injector Hub Error", l("PermissionDeniedWin"))
messagebox.showerror("Injector Hub Error",
l("PermissionDeniedWin"))
if (DEBUG == 0):
sys.exit(1)
else:
sys.exit()
installer.UPGRADE = 1
if (UPGRADE == 1):
if (os.path.exists("software")):
info("[win]clean install cache")
shutil.rmtree("software")
nav_list = [ nav_list = [
{"icon": "lightning", "frame": installer.installer_ui, "side": "top"} {"icon": "lightning", "frame": installer.installer_ui, "side": "top"}
] ]
else: else:
vars.DISKMOUNT = root_disk
info(f"[win]found installed disk \"{root_disk}\"") info(f"[win]found installed disk \"{root_disk}\"")
nav_list = [ nav_list = [
{"icon": "home-filled", "frame": homeui.home_ui, "side": "top"}, {"icon": "home-filled", "frame": None, "side": "top"},
{"icon": "dvd", "frame": None, "side": "top"}, {"icon": "dvd", "frame": None, "side": "top"},
{"icon": "plugin", "frame": None, "side": "top"}, {"icon": "plugin", "frame": None, "side": "top"},
{"icon": "setting", "frame": None, "side": "bottom"} {"icon": "setting", "frame": None, "side": "bottom"}
] ]
info("[win]init window") info("[win]init window")
mtk.load_icon_pack("res/icon.pack") mtk.load_icon_pack("res/icon.pack")
main_win = mtk.Tk(title="Injector Hub", w=1000, h=800) main_win = mtk.Tk(title="Injector Hub", w=1000, h=800)
main_frame = mtk.Frame(main_win, w=10000) main_frame = mtk.Frame(main_win, w=10000)
nav.pack_nav(main_win, main_frame, nav_list) nav.pack_nav(main_win, main_frame, nav_list)
main_frame.pack(side="left", fill="both", expand=True) main_frame.pack(side="left", fill="both", expand=True)
def main():
info("[win]mainloop") info("[win]mainloop")
main_win.mainloop() main_win.mainloop()
def run():
try:
main()
except Exception as exp:
err("[errtrace] caught err:"+repr(exp))
for i in traceback.format_exc().split("\n"):
firstlen_flag = "* "
lastlen = ""
for j in textwrap.wrap(i, width=40):
err("[errtrace]"+" "+firstlen_flag+" " *
(len(lastlen)-len(lastlen.lstrip()))+j)
lastlen = " " * (len(lastlen)-len(lastlen.lstrip()))+j
firstlen_flag = " "
if (DEBUG == 1):
raise