feat: (UNFINISH) 正则匹配检测测试
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from typing import Tuple
|
||||
from git import Repo # type: ignore
|
||||
from git import Repo
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
@@ -20,7 +20,7 @@ def clone_repo(repo_url: str, clone_dir: str) -> None:
|
||||
|
||||
def inject_random_backdoor(
|
||||
path: str, pickle: bool = False, pyc: bool = False, sample_rate: float = 0.1
|
||||
) -> None:
|
||||
) -> int:
|
||||
"""
|
||||
Insert random backdoor into the path.
|
||||
|
||||
@@ -42,9 +42,10 @@ def inject_random_backdoor(
|
||||
# sample files to inject backdoor
|
||||
if random.random() < sample_rate:
|
||||
injected_python_files.append(python_file)
|
||||
|
||||
injectedNum = len(injected_python_files)
|
||||
print([str(i) for i in injected_python_files])
|
||||
for python_file in injected_python_files:
|
||||
with open(python_file, "r+") as f:
|
||||
with open(python_file, "r+",errors="ignore") as f:
|
||||
lines = f.readlines()
|
||||
total_lines = len(lines)
|
||||
inject_line_number = random.randint(0, total_lines)
|
||||
@@ -57,6 +58,7 @@ def inject_random_backdoor(
|
||||
|
||||
# Write the modified content back to the file
|
||||
f.writelines(lines)
|
||||
return injectedNum
|
||||
|
||||
|
||||
# 示例1: 通过 os.system 执行命令
|
||||
|
||||
Reference in New Issue
Block a user