From 40f5c07fa1359ab864d90d0acbbe9a4de615cbb0 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:08:40 +0800 Subject: [PATCH 01/11] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9pyc?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=8F=8D=E6=B1=87=E7=BC=96=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/Regexdetection.py | 11 ++++++++++- detection/backdoor_detection.py | 30 +++++++++++++++++++++--------- detection/pyc_detection.py | 22 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 detection/pyc_detection.py diff --git a/detection/Regexdetection.py b/detection/Regexdetection.py index b1b1549..39f6280 100644 --- a/detection/Regexdetection.py +++ b/detection/Regexdetection.py @@ -25,6 +25,16 @@ def find_dangerous_functions( ".cpp": { r"\bsystem\(": "high", }, + ".pyc": { + r"\bexec\b": "high", + r"\beval\b": "high", + r"\bos\.system\b": "high", + r"\bos\.exec\b": "high", + r"\bos\.fork\b": "high", + r"\bos\.kill\b": "high", + r"\bos\.popen\b": "medium", + r"\bos\.spawn\b": "medium", + }, } risk_patterns = patterns.get(file_extension, {}) classified_results = {"high": [], "medium": [], "low": [], "none": []} @@ -36,4 +46,3 @@ def find_dangerous_functions( if re.search(pattern, clean_line): classified_results[risk_level].append((line_number, clean_line)) return classified_results - diff --git a/detection/backdoor_detection.py b/detection/backdoor_detection.py index ef3e32b..0dbbe40 100644 --- a/detection/backdoor_detection.py +++ b/detection/backdoor_detection.py @@ -3,12 +3,13 @@ from typing import Dict, List, Tuple from reportlab.lib.pagesizes import letter from reportlab.lib.styles import getSampleStyleSheet from reportlab.platypus import Paragraph, Spacer, SimpleDocTemplate -from .Regexdetection import find_dangerous_functions -from .GPTdetection import detectGPT -from .utils import * +from detection.Regexdetection import find_dangerous_functions +from detection.GPTdetection import detectGPT +from detection.utils import * +from detection.pyc_detection import disassemble_pyc import sys -SUPPORTED_EXTENSIONS = {".py", ".js", ".cpp"} +SUPPORTED_EXTENSIONS = {".py", ".js", ".cpp", ".pyc"} OUTPUT_FORMATS = ["html", "md", "txt", "pdf"] @@ -119,12 +120,23 @@ def output_text(results: Dict[str, List[Tuple[int, str]]], file_name=None): def checkModeAndDetect(mode: str, filePath: str, fileExtension: str): # TODO:添加更多方式,这里提高代码的复用性和扩展性 - if mode == "regex": - return find_dangerous_functions(read_file_content(filePath), fileExtension) - elif mode == "llm": - return detectGPT(read_file_content(filePath)) + if fileExtension == ".pyc": + # 反汇编pyc文件 + file_content = disassemble_pyc(filePath) + if mode == "regex": + return find_dangerous_functions(file_content, fileExtension) + elif mode == "llm": + return detectGPT(file_content) + else: + return find_dangerous_functions(file_content, fileExtension) else: - return find_dangerous_functions(read_file_content(filePath), fileExtension) + file_content = read_file_content(filePath) + if mode == "regex": + return find_dangerous_functions(file_content, fileExtension) + elif mode == "llm": + return detectGPT(file_content) + else: + return find_dangerous_functions(file_content, fileExtension) def process_path(path: str, output_format: str, mode: str, output_file=None): diff --git a/detection/pyc_detection.py b/detection/pyc_detection.py new file mode 100644 index 0000000..697da18 --- /dev/null +++ b/detection/pyc_detection.py @@ -0,0 +1,22 @@ +from typing import List, Tuple +import uncompyle6 +import io + + +def disassemble_pyc(file_path: str) -> str: + """ + Disassembles a .pyc file using uncompyle6. + + Args: + file_path (str): The path to the .pyc file. + + Returns: + str: The disassembled code as a string. + """ + output = io.StringIO() + try: + uncompyle6.main.decompile_file(file_path, output) + return output.getvalue() + except Exception as e: + print(f"Error occurred while disassembling: {e}") + return "" -- 2.47.2 From d30ea0ca610ea20e145a43c7d038707b47db75d2 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:31:42 +0800 Subject: [PATCH 02/11] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8F=8D?= =?UTF-8?q?=E6=B1=87=E7=BC=96=E6=A8=A1=E5=9D=97=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5842882..399f7e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ reportlab requests packaging openai -bs4 \ No newline at end of file +bs4 +uncompyle6 \ No newline at end of file -- 2.47.2 From e418bbf3801e77cb80a0858728e724c303e3541b Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:32:24 +0800 Subject: [PATCH 03/11] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E5=8F=8D?= =?UTF-8?q?=E6=B1=87=E7=BC=96=E4=B9=8B=E5=90=8E=E7=9A=84=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_backdoor_detection.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_backdoor_detection.py b/tests/test_backdoor_detection.py index ebbcd58..d366df1 100644 --- a/tests/test_backdoor_detection.py +++ b/tests/test_backdoor_detection.py @@ -90,6 +90,23 @@ class TestBackdoorDetection(unittest.TestCase): with self.assertRaises(ValueError): detectGPT(content) + def test_find_dangerous_functions_pyc(self): + file_content = """import os + os.system('rm -rf /') + """ + file_extension = ".pyc" + + expected_result = { + "high": [(2, "os.system('rm -rf /')")], + "medium": [], + "low": [], + "none": [], + } + + result = find_dangerous_functions(file_content, file_extension) + + self.assertEqual(result, expected_result) + if __name__ == "__main__": unittest.main() -- 2.47.2 From 8a14ef4341974937270003b914b47ee9d083a52f Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Wed, 29 May 2024 20:36:09 +0800 Subject: [PATCH 04/11] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E6=A8=A1=E5=9D=97=E5=BC=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/backdoor_detection.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/detection/backdoor_detection.py b/detection/backdoor_detection.py index 0dbbe40..22037a6 100644 --- a/detection/backdoor_detection.py +++ b/detection/backdoor_detection.py @@ -3,10 +3,10 @@ from typing import Dict, List, Tuple from reportlab.lib.pagesizes import letter from reportlab.lib.styles import getSampleStyleSheet from reportlab.platypus import Paragraph, Spacer, SimpleDocTemplate -from detection.Regexdetection import find_dangerous_functions -from detection.GPTdetection import detectGPT -from detection.utils import * -from detection.pyc_detection import disassemble_pyc +from .Regexdetection import find_dangerous_functions +from .GPTdetection import detectGPT +from .utils import * +from .pyc_detection import disassemble_pyc import sys SUPPORTED_EXTENSIONS = {".py", ".js", ".cpp", ".pyc"} -- 2.47.2 From df65fff2c7335a9519ffef0f4437cb8e0a342b10 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Fri, 31 May 2024 20:33:47 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9python?= =?UTF-8?q?=203.11=E7=9A=84=E5=8F=8D=E7=BC=96=E8=AF=91=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/Regexdetection.py | 15 ++++++----- detection/__main__.py | 52 +++++++++++++++++++++++++------------ detection/pyc_detection.py | 18 +++++-------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/detection/Regexdetection.py b/detection/Regexdetection.py index 39f6280..4296b49 100644 --- a/detection/Regexdetection.py +++ b/detection/Regexdetection.py @@ -38,11 +38,12 @@ def find_dangerous_functions( } risk_patterns = patterns.get(file_extension, {}) classified_results = {"high": [], "medium": [], "low": [], "none": []} - for line_number, line in enumerate(file_content.split("\n"), start=1): - clean_line = remove_comments(line, file_extension) - if not clean_line: - continue - for pattern, risk_level in risk_patterns.items(): - if re.search(pattern, clean_line): - classified_results[risk_level].append((line_number, clean_line)) + if file_content is not None: + for line_number, line in enumerate(file_content.split("\n"), start=1): + clean_line = remove_comments(line, file_extension) + if not clean_line: + continue + for pattern, risk_level in risk_patterns.items(): + if re.search(pattern, clean_line): + classified_results[risk_level].append((line_number, clean_line)) return classified_results diff --git a/detection/__main__.py b/detection/__main__.py index 6d4aecb..2538ad6 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -1,4 +1,5 @@ import os +from pickle import FALSE from typing import Dict, List, Tuple, Optional from reportlab.lib.pagesizes import letter from reportlab.lib.styles import getSampleStyleSheet @@ -10,6 +11,8 @@ from .utils import * import sys from colorama import init, Fore, Style +PYCDC_FLAG = True +PYCDC_ADDR_FLAG = True SUPPORTED_EXTENSIONS = {".py", ".js", ".cpp", ".pyc"} OUTPUT_FORMATS = ["html", "md", "txt", "pdf"] ORDERS = [ @@ -331,6 +334,13 @@ def checkModeAndDetect(mode: str, filePath: str, fileExtension: str, pycdc_addr: if fileExtension == ".pyc": # 反汇编pyc文件 file_content = disassemble_pyc(filePath, pycdc_addr) + if file_content == "none": + global PYCDC_FLAG + PYCDC_FLAG = False + return "" + elif file_content == "invalid": + global PYCDC_ADDR_FLAG + PYCDC_ADDR_FLAG = False if mode == "regex": return find_dangerous_functions(file_content, fileExtension) elif mode == "llm": @@ -360,26 +370,28 @@ def process_path( file_results = checkModeAndDetect( mode, file_path, file_extension, pycdc_addr ) - for key in file_results: - if key != "none": # Exclude 'none' risk level - results[key].extend( - [ - (f"{file_path}: Line {line_num}", line) - for line_num, line in file_results[key] - ] - ) + if file_results != "": + for key in file_results: + if key != "none": # Exclude 'none' risk level + results[key].extend( + [ + (f"{file_path}: Line {line_num}", line) + for line_num, line in file_results[key] + ] + ) elif os.path.isfile(path): file_extension = os.path.splitext(path)[1] if file_extension in SUPPORTED_EXTENSIONS: file_results = checkModeAndDetect(mode, path, file_extension, pycdc_addr) - for key in file_results: - if key != "none": # Exclude 'none' risk level - results[key].extend( - [ - (f"{path}: Line {line_num}", line) - for line_num, line in file_results[key] - ] - ) + if file_results != "": + for key in file_results: + if key != "none": # Exclude 'none' risk level + results[key].extend( + [ + (f"{path}: Line {line_num}", line) + for line_num, line in file_results[key] + ] + ) else: print("Unsupported file type.") return @@ -420,6 +432,14 @@ def main(): output_file = args.output.rsplit(".", 1)[0] + ".txt" # 如果未指定输出文件,则输出到 stdout;否则写入文件 process_path(args.path, output_format, args.mode, args.pycdc, output_file) + if PYCDC_FLAG == False: + print( + "ERROR: Detected Python 3.11 or above .pyc files. You need to install pycdc and compile it yourself to obtain pycdc." + ) + print("Repo: https://github.com/zrax/pycdc.git") + if PYCDC_ADDR_FLAG == False: + print("ERROR: The specified pycdc.exe path is not valid") + print("Please check your pycdc path.") if __name__ == "__main__": diff --git a/detection/pyc_detection.py b/detection/pyc_detection.py index e898685..d350421 100644 --- a/detection/pyc_detection.py +++ b/detection/pyc_detection.py @@ -3,6 +3,7 @@ import uncompyle6 import io import os import subprocess +from contextlib import redirect_stdout, redirect_stderr def run_pycdc(exe_path: str, pyc_file: str) -> str: @@ -17,15 +18,12 @@ def run_pycdc(exe_path: str, pyc_file: str) -> str: str: Output from pycdc.exe. """ if not os.path.isfile(exe_path): - print(f"ERROR: The specified pycdc.exe path is not valid: {exe_path}") - print("Please check your pycdc path.") - exit(1) + return "invalid" command = f'"{exe_path}" "{pyc_file}"' - result = subprocess.run(command, capture_output=True, text=True, shell=True) - - if result.returncode != 0: - raise Exception(f"Error running pycdc.exe: {result.stderr}") + result = subprocess.run( + command, capture_output=True, text=True, shell=True, encoding="utf-8" + ) return result.stdout @@ -46,10 +44,6 @@ def disassemble_pyc(file_path: str, pycdc_addr=None) -> str: return output.getvalue() except Exception as e: if pycdc_addr is None: - print( - "ERROR: For Python 3.11 and above, you need to install pycdc and compile it yourself to obtain pycdc.exe." - ) - print("repo: https://github.com/zrax/pycdc.git") - exit(1) + return "none" else: return run_pycdc(pycdc_addr, file_path) -- 2.47.2 From b673575fe406900128afd534c4a64c1d10142ad1 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Fri, 31 May 2024 20:36:42 +0800 Subject: [PATCH 06/11] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E6=95=88=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/detection/__main__.py b/detection/__main__.py index 2538ad6..75db0fa 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -1,5 +1,4 @@ import os -from pickle import FALSE from typing import Dict, List, Tuple, Optional from reportlab.lib.pagesizes import letter from reportlab.lib.styles import getSampleStyleSheet -- 2.47.2 From 17245a9bcf051a6c15b0849e4c88c9e3c3eeec42 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Fri, 31 May 2024 21:13:01 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3unicode=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detection/__main__.py b/detection/__main__.py index 75db0fa..b9531d9 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -369,7 +369,7 @@ def process_path( file_results = checkModeAndDetect( mode, file_path, file_extension, pycdc_addr ) - if file_results != "": + if file_results is not None: for key in file_results: if key != "none": # Exclude 'none' risk level results[key].extend( @@ -382,7 +382,7 @@ def process_path( file_extension = os.path.splitext(path)[1] if file_extension in SUPPORTED_EXTENSIONS: file_results = checkModeAndDetect(mode, path, file_extension, pycdc_addr) - if file_results != "": + if file_results is not None: for key in file_results: if key != "none": # Exclude 'none' risk level results[key].extend( -- 2.47.2 From b99334ed1256c5185af8b58568acb7881c695d5b Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Sun, 2 Jun 2024 19:54:47 +0800 Subject: [PATCH 08/11] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3unicode=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detection/utils.py b/detection/utils.py index 563e7f0..c15e8ec 100644 --- a/detection/utils.py +++ b/detection/utils.py @@ -4,7 +4,7 @@ import sys def read_file_content(file_path: str) -> str: try: - with open(file_path, "r", encoding="utf-8") as file: + with open(file_path, "r", encoding="utf-8", errors="ignore") as file: return file.read() except FileNotFoundError: print("Error: File not found.") @@ -21,4 +21,4 @@ def remove_comments(code: str, extension: str) -> str: code = re.sub(r"//.*", "", code) code = re.sub(r"/\*.*?\*/", "", code, flags=re.DOTALL) return code.strip() - return code.strip() \ No newline at end of file + return code.strip() -- 2.47.2 From 7eb4de8e6c597cec95f7cb01a3f864a659ec5f6d Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Sun, 2 Jun 2024 20:24:03 +0800 Subject: [PATCH 09/11] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/detection/__main__.py b/detection/__main__.py index b9531d9..351f2ec 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -9,6 +9,7 @@ from .pyc_detection import disassemble_pyc from .utils import * import sys from colorama import init, Fore, Style +from tqdm import tqdm PYCDC_FLAG = True PYCDC_ADDR_FLAG = True @@ -361,27 +362,40 @@ def process_path( ): results = {"high": [], "medium": [], "low": [], "none": []} if os.path.isdir(path): + # 获取所有文件 + all_files = [] for root, dirs, files in os.walk(path): for file in files: file_extension = os.path.splitext(file)[1] if file_extension in SUPPORTED_EXTENSIONS: file_path = os.path.join(root, file) - file_results = checkModeAndDetect( - mode, file_path, file_extension, pycdc_addr - ) - if file_results is not None: - for key in file_results: - if key != "none": # Exclude 'none' risk level - results[key].extend( - [ - (f"{file_path}: Line {line_num}", line) - for line_num, line in file_results[key] - ] - ) + all_files.append(file_path) + # 扫描动画 + for file_path in tqdm(all_files, desc="Scanning files", unit="file"): + file_extension = os.path.splitext(file_path)[1] + file_results = checkModeAndDetect( + mode, file_path, file_extension, pycdc_addr + ) + if file_results is not None: + for key in file_results: + if key != "none": # Exclude 'none' risk level + results[key].extend( + [ + (f"{file_path}: Line {line_num}", line) + for line_num, line in file_results[key] + ] + ) elif os.path.isfile(path): + file_results = "" file_extension = os.path.splitext(path)[1] if file_extension in SUPPORTED_EXTENSIONS: - file_results = checkModeAndDetect(mode, path, file_extension, pycdc_addr) + # 扫描动画 + with tqdm(total=100, desc="Scanning file", unit="%", ncols=100) as pbar: + for i in range(10): + file_results = checkModeAndDetect( + mode, path, file_extension, pycdc_addr + ) + pbar.update(10) # Update the progress bar by 10% if file_results is not None: for key in file_results: if key != "none": # Exclude 'none' risk level -- 2.47.2 From 62b77812af7825eacfa91b203a8750f871020476 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Mon, 3 Jun 2024 11:41:19 +0800 Subject: [PATCH 10/11] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E5=8D=95=E4=B8=AA=E6=96=87=E4=BB=B6=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/detection/__main__.py b/detection/__main__.py index 351f2ec..24f8703 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -386,16 +386,9 @@ def process_path( ] ) elif os.path.isfile(path): - file_results = "" file_extension = os.path.splitext(path)[1] if file_extension in SUPPORTED_EXTENSIONS: - # 扫描动画 - with tqdm(total=100, desc="Scanning file", unit="%", ncols=100) as pbar: - for i in range(10): - file_results = checkModeAndDetect( - mode, path, file_extension, pycdc_addr - ) - pbar.update(10) # Update the progress bar by 10% + file_results = checkModeAndDetect(mode, path, file_extension, pycdc_addr) if file_results is not None: for key in file_results: if key != "none": # Exclude 'none' risk level -- 2.47.2 From d1ac4594e4f20ea139566e43ace5582bc7dd102a Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Mon, 3 Jun 2024 16:29:35 +0800 Subject: [PATCH 11/11] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8rglob=E6=89=AB?= =?UTF-8?q?=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/detection/__main__.py b/detection/__main__.py index 24f8703..9881eb5 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -10,6 +10,7 @@ from .utils import * import sys from colorama import init, Fore, Style from tqdm import tqdm +from pathlib import Path PYCDC_FLAG = True PYCDC_ADDR_FLAG = True @@ -362,19 +363,18 @@ def process_path( ): results = {"high": [], "medium": [], "low": [], "none": []} if os.path.isdir(path): - # 获取所有文件 - all_files = [] - for root, dirs, files in os.walk(path): - for file in files: - file_extension = os.path.splitext(file)[1] - if file_extension in SUPPORTED_EXTENSIONS: - file_path = os.path.join(root, file) - all_files.append(file_path) + # 使用rglob获取所有文件 + all_files = [ + file_path + for file_path in Path(path).rglob("*") + if file_path.suffix in SUPPORTED_EXTENSIONS + ] + # 扫描动画 for file_path in tqdm(all_files, desc="Scanning files", unit="file"): - file_extension = os.path.splitext(file_path)[1] + file_extension = file_path.suffix file_results = checkModeAndDetect( - mode, file_path, file_extension, pycdc_addr + mode, str(file_path), file_extension, pycdc_addr ) if file_results is not None: for key in file_results: -- 2.47.2