def collect_into_three_files(folder_path): global output for (_, _, files) in walk(str(folder_path)): for f in sorted(files): f_path = Path(folder_path) / f if not is_collectable_file(f_path): continue data = f_path.read_text(encoding='utf-8-sig') # Новые данные # Заменяем все ентеры на пробелы data, _ = strip_comments(data) data, _ = strip_multiline_comments(data) data = data.replace('\n', ' ') # Старые данные old_data = '' common_file_path = Path(folder_path) / get_common_file(f_path.name) if common_file_path.exists(): old_data = common_file_path.read_text(encoding='utf-8-sig') common_file_path.write_text( old_data + ' ' + data, encoding='utf-8-sig') if drm_debug: output += 'Перемещён файл ' + \ format_path(f_path) + ' --> ' + \ format_path(common_file_path) + '\n' Path(f_path).unlink() break
def proceed_common_file(fl, fl_in): global output if fl_in.exists(): if fl.exists(): old_content = fl.read_text(encoding='utf-8-sig') content = fl_in.read_text(encoding='utf-8-sig') fl.write_text(old_content + ' ' + content, encoding='utf-8-sig') if drm_debug: output += 'Перемещён главный файл ' + \ format_path(fl_in) + ' --> ' + \ format_path(fl) + '\n' fl_in.unlink() if not any(Path(d_path).iterdir()): d_path.rmdir()
from files import format_path import sys from obfuscator import obf_folder from collector import collect_folder from settings import do_not_collect, do_not_obfuscate inp_folder = format_path(sys.argv[1]) inp_folder = inp_folder.rstrip('/') out_folder = inp_folder + '-public' if not do_not_obfuscate: print('-------- [Obfuscating...] --------') obf_folder(inp_folder, out_folder) if not do_not_collect: print('-------- [Collecting...] --------') collect_folder(out_folder) print('-------- [Done!] --------')
obf_level = 2 do_not_collect = True do_not_obfuscate = False # Debug drm_debug = False # Пути DRM_DIR = Path(__file__).parent.absolute() OBF_DIR = DRM_DIR / 'LuaObfuscator' PYTHON_CMD = 'py' cmd_file_path = DRM_DIR / 'commands.sh' ignored_files_start = '-- [do not obfuscate]' ignored_folders = [ format_path(Path('lua') / 'cyber-langs'), # format_path(Path('lua') / 'cyber-external'), ] cl_common_file = '__cl.lua' sv_common_file = '__sv.lua' sh_common_file = '___sh.lua' collect_file_name = '__collectfolder__.lua' def is_cl_file(f): return f == 'cl.lua' or '_cl.lua' in f def is_sv_file(f):
def obf_folder(in_folder, out_folder): in_folder = Path(in_folder) out_folder = Path(out_folder) Path(out_folder).mkdir(parents=True, exist_ok=True) # СОЗДАЕМ ФАЙЛИК if Path(cmd_file_path).exists(): Path(cmd_file_path).unlink() commands = '' # ЗАНОСИМ ТУДА КОМАНДЫ commands += '# bin/sh\n' commands += 'cd ' + format_path(OBF_DIR) + '|| exit\n' # Удаляем старую папку изнутри, и шифруем по новой for (_, dirs, _) in walk(str(out_folder)): for d in dirs: if d != '.git': shutil.rmtree(str(out_folder / d), ignore_errors=True) for (dirPath, _, _) in walk(str(in_folder)): folder_is_in_ignored = False for ignored in ignored_folders: if ignored in dirPath: folder_is_in_ignored = True for (_, _, files) in walk(dirPath): for file_name in files: file_path = format_path(Path(dirPath) / file_name) enc_file_path = file_path.replace(format_path(in_folder), format_path(out_folder)) encrypted_dir_path = format_path(dirPath).replace( format_path(in_folder), format_path(out_folder)) Path(encrypted_dir_path).mkdir(parents=True, exist_ok=True) _, file_extension = os.path.splitext(file_name) if file_extension == '.lua' and not do_not_obfuscate and not folder_is_in_ignored and not file_path.__contains__( collect_file_name): fl_data = Path(file_path).read_text(encoding='utf-8-sig') if fl_data.__contains__(ignored_files_start): Path(enc_file_path).write_text(fl_data.replace( ignored_files_start + '\n', ''), encoding='utf-8-sig') else: commands += 'echo ---------- OBF [' + file_path + \ '] TO LVL ' + \ str(obf_level) + '\n' commands += PYTHON_CMD+' ' + '__main__.py' + ' --input ' + file_path \ + ' --output ' + enc_file_path + ' --level ' + str(obf_level) \ + ' --dontcopy --debug\n' else: if '.git' not in file_path: shutil.copy(file_path, enc_file_path) break # ЗАПУСКАЕМ ФАЙЛИК cmd_file = Path(cmd_file_path) # if drm_debug: # commands += '\n sleep 1h' commands += '\n echo ------- All scripts is finished!' # commands += '\n sleep 1h' cmd_file.write_text(commands) output = run_file(cmd_file, 40) # УБИРАЕМ ЗА СОБОЙ if Path(cmd_file_path).exists() and not drm_debug: Path(cmd_file_path).unlink() return output