From 9694bfb952461d4e25c53b2597e86ecb76af9d33 Mon Sep 17 00:00:00 2001 From: cnhacklqr Date: Wed, 14 Feb 2024 21:28:53 +0800 Subject: [PATCH] Update code --- .gitignore | 1 + .vscode/launch.json | 11 +++++++++- Makefile.linux | 44 ++++++++++++++++++++++++++++++++++++++++ Makefile => Makefile.win | 6 +++--- installer/install.py | 18 ++++++++++------ 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 Makefile.linux rename Makefile => Makefile.win (85%) diff --git a/.gitignore b/.gitignore index f2cec82..2925675 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist env/*.* # VM debug file start_vm.cmd +start_vm.sh # Debug file src/debug.py diff --git a/.vscode/launch.json b/.vscode/launch.json index ebc044b..47f2bc3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,14 @@ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Python 调试程序: 包含参数的当前文件", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": "${command:pickArgs}" + }, { "name": "Python 调试 main", "type": "debugpy", @@ -23,7 +31,8 @@ "type": "debugpy", "request": "launch", "program": "${file}", - "console": "integratedTerminal" + "console": "integratedTerminal", + "sudo": true }, { "command": "make debug", diff --git a/Makefile.linux b/Makefile.linux new file mode 100644 index 0000000..d22708d --- /dev/null +++ b/Makefile.linux @@ -0,0 +1,44 @@ +dist/PEinjector.7z: src/main.py src/log.py src/action.py src/hook.pyw src/makelnk.py src/regwrite.py src/config.py src/loader.py src/utils.py root/VentoyAutoRun.bat + mkdir tmp/pkg/PEinjector/env -p + mkdir tmp/pkg/PEinjector/src -p + mkdir tmp/pkg/PEinjector/tool -p + cp ./root/* ./tmp/pkg -rfp + cp ./env ./tmp/pkg/PEinjector/env -rfp + cp ./src ./tmp/pkg/PEinjector/src -rfp + cp ./tool ./tmp/pkg/PEinjector/tool -rfp + rm -rf dist + mkdir disk -p + 7z a -t7z dist/PEinjector.7z ./tmp/pkg/PEinjector -r -m0=BCJ -m1=LZMA:d=21 -ms -mmt + 7z a -t7z dist/PEinjector.7z ./tmp/pkg/VentoyAutoRun.bat -m0=BCJ -m1=LZMA:d=21 -ms -mmt + rm -rf tmp + +tmp/py/python.zip: + mkdir tmp/py -p + cd tmp/py + wget https://registry.npmmirror.com/-/binary/python/3.12.1/python-3.12.1-embed-amd64.zip -O tmp/py/python.zip + +env/python.exe: tmp/py/python.zip + 7z x -y -aos -o env/ tmp/py/python.zip + +install: dist/PEinjector.7z installer\install.py + python3 installer\install.py + +build: dist/PEinjector.7z + +prepare: env/python.exe + +clean: + rm -rf tmp + rm -rf dist + mkdir dist -p + +debug: dist/PEinjector.7z + sudo python3 installer/install.py + chmod +x ./start_vm.sh + ./start_vm.sh + +start: + chmod +x ./start_vm.sh + ./start_vm.sh + + diff --git a/Makefile b/Makefile.win similarity index 85% rename from Makefile rename to Makefile.win index 8633370..0404051 100644 --- a/Makefile +++ b/Makefile.win @@ -14,9 +14,9 @@ dist\PEinjector.7z: src\main.py src\log.py src\action.py src\hook.pyw src\makeln tmp\py\python.zip: mkdir tmp\py cd tmp\py - curl https://www.python.org/ftp/python/3.12.1/python-3.12.1-embed-amd64.zip -o tmp\py\python.zip + wget https://registry.npmmirror.com/-/binary/python/3.12.1/python-3.12.1-embed-amd64.zip -O tmp\py/python.zip env\python.exe: tmp\py\python.zip - 7z x -y -aos -oenv\ tmp\py\python.zip + 7z x -y -aos -oenv\ tmppy/python.zip install: dist\PEinjector.7z installer/install.py python installer\install.py build: dist\PEinjector.7z @@ -29,4 +29,4 @@ debug: dist\PEinjector.7z python installer\install.py start_vm.cmd start: - start_vm.cmd \ No newline at end of file + start_vm.cmd diff --git a/installer/install.py b/installer/install.py index 31f37fe..7e8d1ee 100644 --- a/installer/install.py +++ b/installer/install.py @@ -1,6 +1,6 @@ ##################################### ## PEinjector/installer ## -##################################### +#################################### # This moudle is a part of PEinjector. # Please comply with the LICENSE. @@ -9,6 +9,7 @@ import os import shutil import json import platform +import getpass ############ Config ############ KEYWORD = "winpe" @@ -16,12 +17,16 @@ PYTHON = "python" DISK = "{disk}" ################################ +is_linux:bool = False def find_disk(): if platform.system() == 'Linux': + if getpass.getuser() != 'root': + raise OSError("Permission denied") + is_linux = True mount_point = "/mnt/prinjector_mount_point" - print( - "Warning: Linux support is developing.Please umount {mount_point}") +# print( +# "Warning: Linux support is developing.Please umount {mount_point}") if not os.path.exists(mount_point): os.mkdir(mount_point) elif len(os.listdir(mount_point)): @@ -30,10 +35,9 @@ def find_disk(): i: int = 97 while os.path.exists(f"/dev/sd{chr(i)}"): j: int = 1 - this_disk = f"/dev/sd{chr(i)}{str(j)}" - while os.path.exists(this_disk): + while os.path.exists(f"/dev/sd{chr(i)}{str(j)}"): os.system( - f"mount /dev/sd{chr(i)}{str(j)} {mount_point} --mkdir") + f"mount /dev/sd{chr(i)}{str(j)} {mount_point}") if os.path.exists(mount_point+"/ventoy/ventoy.json"): return mount_point j += 1 @@ -151,5 +155,7 @@ for i in os.listdir("package"): shutil.rmtree(DISK+"/PEinjector/package/"+i) shutil.copytree("package/"+i, DISK+"/PEinjector/package/"+i) +if is_linux: + os.system(f"umount {mount_point}") print("All done.")