feat: update test case
This commit is contained in:
@@ -3,9 +3,8 @@ from git import Repo # type: ignore
|
||||
import random
|
||||
from pathlib import Path
|
||||
import pickle
|
||||
import marshal
|
||||
import importlib.util
|
||||
import os
|
||||
import py_compile
|
||||
|
||||
|
||||
def clone_repo(repo_url: str, clone_dir: str) -> None:
|
||||
@@ -175,20 +174,13 @@ def inject_pyc_backdoor(root_path: str) -> None:
|
||||
for path in paths:
|
||||
backdoor_id = random.randrange(0, len(backdoors))
|
||||
backdoor = backdoors[backdoor_id]
|
||||
filename = os.path.join(path, f"backdoor{backdoor_id}.pyc")
|
||||
py_filename = os.path.join(path, f"backdoor{backdoor_id}.py")
|
||||
pyc_filename = os.path.join(path, f"backdoor{backdoor_id}.pyc")
|
||||
with open(py_filename, "w") as f:
|
||||
f.write(backdoor)
|
||||
|
||||
# Compile the string to a code object
|
||||
code = compile(backdoor, filename, "exec")
|
||||
|
||||
# Create a code object header
|
||||
header = importlib.util.MAGIC_NUMBER
|
||||
if hasattr(importlib.util, "SOURCE_SUFFIXES"):
|
||||
header += b"\x00" * 4
|
||||
|
||||
# Write the .pyc file
|
||||
with open(filename, "wb") as file:
|
||||
file.write(header)
|
||||
marshal.dump(code, file)
|
||||
py_compile.compile(py_filename, cfile=pyc_filename)
|
||||
os.remove(py_filename)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user