Skip to content

Commit

Permalink
更新混淆、反混淆跳过逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwxi committed Sep 9, 2024
1 parent bdef272 commit 53b1219
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 1 addition & 2 deletions epub_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def prepare_args():

def check_args(args):
if not args.i:
print("未指定epub文件路径或文件夹路径")
args.i = input("请输入epub文件路径或文件夹路径:")
# 判断输入文件是否为文件夹
if os.path.isdir(args.i):
Expand Down Expand Up @@ -74,7 +73,7 @@ def main():
if ret == 0:
result = f"^_^ {file} 成功"
elif ret == "skip":
result = f"O_O {file} 跳过"
result = f"O_O {file} 跳过:已{process}"
else:
result = f"T_T {file} 失败: {ret}"
tmp_run_result.append(result)
Expand Down
13 changes: 10 additions & 3 deletions utils/decrypt_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class EpubTool:

def __init__(self, epub_src):
self.encrypted = False
self.epub = zipfile.ZipFile(epub_src)
self.epub_src = epub_src
self.epub_name = path.basename(epub_src)
Expand All @@ -42,7 +43,8 @@ def __init__(self, epub_src):
self.errorOPF_log = [] # (error_type,error_value)
self.errorLink_log = {} # {filepath:[(error_link,correct_link || None),...]}
self._parse_opf()



def _init_namelist(self):
self.namelist = self.epub.namelist()

Expand Down Expand Up @@ -168,6 +170,9 @@ def creatNewHerf(_id, _href):
############################################################
for id, href, mime, properties in self.manifest_list:
bkpath = opf_dir + "/" + href if opf_dir else href
# 判断herf是否包含特殊字符
if re.search(r'[\\/:*?"<>|]', href.rsplit("/")[-1]):
self.encrypted = True
if mime == "application/xhtml+xml":
new_href = creatNewHerf(id, href)
self.text_list.append((id, href, properties, new_href))
Expand Down Expand Up @@ -887,10 +892,12 @@ def run(epub_src):
try:
print("%s 正在尝试重构EPUB" % epub_src)
if epub_src.lower().endswith("_decrypt.epub"):
print("警告:该文件已经解密,无需再次处理!")
print("警告:该文件已解密,无需再次处理!")
return "skip"
epub = EpubTool(epub_src)

if not epub.encrypted:
print("警告:该文件未加密,无需处理!")
return "skip"
epub.restructure() # 重构
el = epub.errorLink_log.copy()
del_keys = []
Expand Down
9 changes: 8 additions & 1 deletion utils/encrypt_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class EpubTool:

def __init__(self, epub_src):
self.encrypted = False
self.epub = zipfile.ZipFile(epub_src)
self.epub_src = epub_src
self.epub_name = path.basename(epub_src)
Expand All @@ -40,6 +41,7 @@ def __init__(self, epub_src):
self.errorOPF_log = [] # (error_type,error_value)
self.errorLink_log = {} # {filepath:[(error_link,correct_link || None),...]}
self._parse_opf()


def _init_namelist(self):
self.namelist = self.epub.namelist()
Expand Down Expand Up @@ -158,6 +160,8 @@ def creatNewHerf(_id, _href):

for id, href, mime, properties in self.manifest_list:
bkpath = opf_dir + "/" + href if opf_dir else href
if re.search(r'[\\/:*?"<>|]', href.rsplit("/")[-1]):
self.encrypted = True
if mime == "application/xhtml+xml":
self.text_list.append((id, href, properties, creatNewHerf(id, href)))
elif mime == "text/css":
Expand Down Expand Up @@ -840,9 +844,12 @@ def run(epub_src):
try:
print("%s 正在尝试重构EPUB" % epub_src)
if epub_src.lower().endswith("_encrypt.epub"):
print("警告:该文件已经加密,无需再次处理!")
print("警告:该文件已加密,无需再次处理!")
return "skip"
epub = EpubTool(epub_src)
if epub.encrypted == True:
print("警告:该文件已加密,无需再次处理!")
return "skip"
epub.restructure() # 重构
el = epub.errorLink_log.copy()
del_keys = []
Expand Down

0 comments on commit 53b1219

Please sign in to comment.