diff --git a/src/action.py b/src/action.py index ae6aefe..b8b7260 100644 --- a/src/action.py +++ b/src/action.py @@ -45,8 +45,7 @@ def force_copy(pkg_path: str, pkg_name: str, data_list: list, froms: str, tos: s if len(tos) > 1 and tos[-1] == '/': tos = tos[:-1] datas = [] - data_dir = config.DATAPATH.replace( - "{DISK}", utils.find_disk())+"/"+pkg_name + data_dir = config.DATAPATH.format(DISK=utils.find_disk())+"/"+pkg_name data_check = [i["from"] for i in data_list] @@ -78,8 +77,7 @@ def copy(pkg_path: str, pkg_name: str, data_list: list, froms: str, tos: str) -> if len(tos) > 1 and tos[-1] == '/': tos = tos[:-1] datas = [] - data_dir = config.DATAPATH.replace( - "{DISK}", utils.find_disk())+"/"+pkg_name + data_dir = config.DATAPATH.format(DISK=utils.find_disk())+"/"+pkg_name data_check = [i["from"] for i in data_list] @@ -109,9 +107,9 @@ def start(pkg_name: str, data_list: list, cmd: str) -> list: def save_action(actions_list: list) -> None: tmp_filename = "PEinjector.tmp" - log.info(f"save action list to {config.TEMP_DIR.replace( - '{TEMP}', "X:\\PEinjector")+'\\'+tmp_filename}") - with open(config.TEMP_DIR.replace("{TEMP}", "X:\\PEinjector")+"\\"+tmp_filename, "wb") as file: + log.info(f"save action list to {config.TEMP_DIR.format( + TEMP="X:\\PEinjector")+'\\'+tmp_filename}") + with open(config.TEMP_DIR.format(TEMP="X:\\PEinjector")+"\\"+tmp_filename, "wb") as file: pickle.dump(actions_list, file) return tmp_filename @@ -181,5 +179,4 @@ def do_action(actions_list: list) -> tuple: except: actionlogs = actionlogs + \ f" add reg \"{i[1]}\" failed: {repr(exp)}\r\n" - print(removeinfo) return (actionlogs, removeinfo) diff --git a/src/hook.pyw b/src/hook.pyw index b3831e8..34bd8ec 100644 --- a/src/hook.pyw +++ b/src/hook.pyw @@ -71,12 +71,12 @@ try: # 加载 log.info("load action \"onload\"") - with open(config.TEMP_DIR.replace("{TEMP}", "X:\\PEinjector")+"\\"+"PEinjector.tmp", "rb") as file: + with open(config.TEMP_DIR.format(TEMP="X:\\PEinjector")+"\\"+"PEinjector.tmp", "rb") as file: lists = pickle.load(file) # 读取文件 alog = action.do_action(lists) - with open(config.ACTIONLOGPATH.replace("{DISK}", utils.find_disk()), "a") as file: + with open(config.ACTIONLOGPATH.format(DISK=utils.find_disk()), "a") as file: file.write(alog[0]) # 追加写入日志 - with open(config.TEMP_DIR.replace("{TEMP}", "X:\\PEinjector")+"\\"+"remove.tmp", "wb") as file: + with open(config.TEMP_DIR.format(TEMP="X:\\PEinjector")+"\\"+"remove.tmp", "wb") as file: pickle.dump(alog[1], file) # 写入卸载文件 # 刷新path regwrite.refresh_path() diff --git a/src/loader.py b/src/loader.py index 5e6226f..c568bad 100644 --- a/src/loader.py +++ b/src/loader.py @@ -141,7 +141,7 @@ def load_package(pkg_name: str) -> int: if "data" in file_json: # 对于数据的预处理,实际在load处理链接 j = -1 # 计数 prep_flag = False # 判断 data 是否初始化 - if pkg_name not in os.listdir(config.DATAPATH.replace("{DISK}", utils.find_disk())): + if pkg_name not in os.listdir(config.DATAPATH.format(DISK=utils.find_disk())): log.info(f"prep moudle [{pkg_name}] data") prep_flag = True for i in file_json["data"]: @@ -160,8 +160,8 @@ def load_package(pkg_name: str) -> int: data_list.append(i) # 初始化 data if prep_flag: - data_dir = config.DATAPATH.replace( - "{DISK}", utils.find_disk())+"/"+pkg_name + data_dir = config.DATAPATH.format( + DISK=utils.find_disk())+"/"+pkg_name os.mkdir(data_dir) if os.path.isfile(pkg_path+"/"+i["from"]): shutil.copyfile(( @@ -302,7 +302,7 @@ def load(): disk = utils.find_disk() lists = os.listdir(f"{disk}/PEinjector/package") # 读取禁用包列表 - with open(config.DISABLEPATH.replace("{DISK}", disk), "r") as file: + with open(config.DISABLEPATH.format(DISK=disk), "r") as file: disable_packages = [i.rstrip("\n\r") for i in file.readlines()] for packs in lists: # 加载包 if packs not in loaded_package and packs not in disable_packages: @@ -314,7 +314,7 @@ def load(): action.save_action(actions["onload"]) alog = action.do_action(actions["onboot"])[0] # 写action日志 - with open(config.ACTIONLOGPATH.replace("{DISK}", utils.find_disk()), "w") as file: + with open(config.ACTIONLOGPATH.format(DISK=utils.find_disk()), "w") as file: file.write(alog) except Exception as exp: # 未知错误 log.break_err("Exception \n"+str(traceback.format_exc(exp))) diff --git a/src/log.py b/src/log.py index 58f17b5..ff0e6ef 100644 --- a/src/log.py +++ b/src/log.py @@ -16,12 +16,12 @@ levels = { def newlog() -> None: - with open(config.LOGPATH.replace("{DISK}", utils.find_disk()), "w") as _: + with open(config.LOGPATH.format(DISK=utils.find_disk()), "w") as _: pass def init() -> None: - logging.basicConfig(filename=config.LOGPATH.replace("{DISK}", utils.find_disk()), + logging.basicConfig(filename=config.LOGPATH.format(DISK=utils.find_disk()), format='[%(asctime)s][%(levelname)s] %(message)s', level=levels[config.LOGLEVEL])