in ransomware/testing/mock_ransomware.py [0:0]
def create_target_files(dir_path, num_set=15, fsize=100000):
if os.path.isdir(dir_path):
shutil.rmtree(dir_path, onerror=handle_remote_readonly)
os.makedirs(dir_path)
for _ in range(num_set):
for file_ext in ["gif", "doc", "jpg", "pdf", "docx", "txt"]:
file_path = os.path.join(
dir_path, "%s.%s" % (get_random_string(), file_ext)
)
print(f"Creating {file_path} for size = {fsize} bytes")
with open(file_path, "wb") as fh:
match file_ext:
case "gif":
file_header = bytes([0x47, 0x49, 0x46, 0x38])
case "doc":
file_header = bytes([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1])
case"jpg":
file_header = bytes([0xff, 0xd8, 0xff])
case "pdf":
file_header = bytes([0x25, 0x50, 0x44, 0x46])
case "docx":
file_header = bytes([0x50, 0x4b])
case _:
file_header = bytes([0])
fh.write(file_header)
fh.seek(fsize)
fh.write(bytes([0]))
return len(os.listdir(dir_path))