优化写法
This commit is contained in:
parent
70b0c6792f
commit
efbd54b52b
|
@ -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] == '/':
|
if len(tos) > 1 and tos[-1] == '/':
|
||||||
tos = tos[:-1]
|
tos = tos[:-1]
|
||||||
datas = []
|
datas = []
|
||||||
data_dir = config.DATAPATH.replace(
|
data_dir = config.DATAPATH.format(DISK=utils.find_disk())+"/"+pkg_name
|
||||||
"{DISK}", utils.find_disk())+"/"+pkg_name
|
|
||||||
|
|
||||||
data_check = [i["from"] for i in data_list]
|
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] == '/':
|
if len(tos) > 1 and tos[-1] == '/':
|
||||||
tos = tos[:-1]
|
tos = tos[:-1]
|
||||||
datas = []
|
datas = []
|
||||||
data_dir = config.DATAPATH.replace(
|
data_dir = config.DATAPATH.format(DISK=utils.find_disk())+"/"+pkg_name
|
||||||
"{DISK}", utils.find_disk())+"/"+pkg_name
|
|
||||||
|
|
||||||
data_check = [i["from"] for i in data_list]
|
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:
|
def save_action(actions_list: list) -> None:
|
||||||
tmp_filename = "PEinjector.tmp"
|
tmp_filename = "PEinjector.tmp"
|
||||||
log.info(f"save action list to {config.TEMP_DIR.replace(
|
log.info(f"save action list to {config.TEMP_DIR.format(
|
||||||
'{TEMP}', "X:\\PEinjector")+'\\'+tmp_filename}")
|
TEMP="X:\\PEinjector")+'\\'+tmp_filename}")
|
||||||
with open(config.TEMP_DIR.replace("{TEMP}", "X:\\PEinjector")+"\\"+tmp_filename, "wb") as file:
|
with open(config.TEMP_DIR.format(TEMP="X:\\PEinjector")+"\\"+tmp_filename, "wb") as file:
|
||||||
pickle.dump(actions_list, file)
|
pickle.dump(actions_list, file)
|
||||||
return tmp_filename
|
return tmp_filename
|
||||||
|
|
||||||
|
@ -181,5 +179,4 @@ def do_action(actions_list: list) -> tuple:
|
||||||
except:
|
except:
|
||||||
actionlogs = actionlogs + \
|
actionlogs = actionlogs + \
|
||||||
f" add reg \"{i[1]}\" failed: {repr(exp)}\r\n"
|
f" add reg \"{i[1]}\" failed: {repr(exp)}\r\n"
|
||||||
print(removeinfo)
|
|
||||||
return (actionlogs, removeinfo)
|
return (actionlogs, removeinfo)
|
||||||
|
|
|
@ -71,12 +71,12 @@ try:
|
||||||
|
|
||||||
# 加载
|
# 加载
|
||||||
log.info("load action \"onload\"")
|
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) # 读取文件
|
lists = pickle.load(file) # 读取文件
|
||||||
alog = action.do_action(lists)
|
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]) # 追加写入日志
|
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) # 写入卸载文件
|
pickle.dump(alog[1], file) # 写入卸载文件
|
||||||
# 刷新path
|
# 刷新path
|
||||||
regwrite.refresh_path()
|
regwrite.refresh_path()
|
||||||
|
|
|
@ -141,7 +141,7 @@ def load_package(pkg_name: str) -> int:
|
||||||
if "data" in file_json: # 对于数据的预处理,实际在load处理链接
|
if "data" in file_json: # 对于数据的预处理,实际在load处理链接
|
||||||
j = -1 # 计数
|
j = -1 # 计数
|
||||||
prep_flag = False # 判断 data 是否初始化
|
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")
|
log.info(f"prep moudle [{pkg_name}] data")
|
||||||
prep_flag = True
|
prep_flag = True
|
||||||
for i in file_json["data"]:
|
for i in file_json["data"]:
|
||||||
|
@ -160,8 +160,8 @@ def load_package(pkg_name: str) -> int:
|
||||||
data_list.append(i)
|
data_list.append(i)
|
||||||
# 初始化 data
|
# 初始化 data
|
||||||
if prep_flag:
|
if prep_flag:
|
||||||
data_dir = config.DATAPATH.replace(
|
data_dir = config.DATAPATH.format(
|
||||||
"{DISK}", utils.find_disk())+"/"+pkg_name
|
DISK=utils.find_disk())+"/"+pkg_name
|
||||||
os.mkdir(data_dir)
|
os.mkdir(data_dir)
|
||||||
if os.path.isfile(pkg_path+"/"+i["from"]):
|
if os.path.isfile(pkg_path+"/"+i["from"]):
|
||||||
shutil.copyfile((
|
shutil.copyfile((
|
||||||
|
@ -302,7 +302,7 @@ def load():
|
||||||
disk = utils.find_disk()
|
disk = utils.find_disk()
|
||||||
lists = os.listdir(f"{disk}/PEinjector/package")
|
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()]
|
disable_packages = [i.rstrip("\n\r") for i in file.readlines()]
|
||||||
for packs in lists: # 加载包
|
for packs in lists: # 加载包
|
||||||
if packs not in loaded_package and packs not in disable_packages:
|
if packs not in loaded_package and packs not in disable_packages:
|
||||||
|
@ -314,7 +314,7 @@ def load():
|
||||||
action.save_action(actions["onload"])
|
action.save_action(actions["onload"])
|
||||||
alog = action.do_action(actions["onboot"])[0]
|
alog = action.do_action(actions["onboot"])[0]
|
||||||
# 写action日志
|
# 写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)
|
file.write(alog)
|
||||||
except Exception as exp: # 未知错误
|
except Exception as exp: # 未知错误
|
||||||
log.break_err("Exception \n"+str(traceback.format_exc(exp)))
|
log.break_err("Exception \n"+str(traceback.format_exc(exp)))
|
||||||
|
|
|
@ -16,12 +16,12 @@ levels = {
|
||||||
|
|
||||||
|
|
||||||
def newlog() -> None:
|
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
|
pass
|
||||||
|
|
||||||
|
|
||||||
def init() -> None:
|
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',
|
format='[%(asctime)s][%(levelname)s] %(message)s',
|
||||||
level=levels[config.LOGLEVEL])
|
level=levels[config.LOGLEVEL])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue