making it possible to run main.py from wsl#34
making it possible to run main.py from wsl#34julienbarbaud wants to merge 2 commits intoylytdeng:mainfrom
Conversation
|
Note: The fix assumes that the user is writing his paths to config.json in windows file format |
ylytdeng
left a comment
There was a problem hiding this comment.
感谢提交!WSL 兼容的思路很好,通过调用 Windows 端 python.exe 来提取密钥是合理的方案。
审查后发现几个需要修改的问题:
P1 - 需要修复
-
路径注入风险 —
find_all_keys_wsl.py中callWindowsScriptCommand用 f-string 把WINDOWS_DIR拼接到 Python 代码字符串里:sys.path.append(r'{WINDOWS_DIR}')
如果路径包含单引号或特殊字符会导致代码注入。建议改用
json.dumps()转义路径,或通过环境变量/命令行参数传递。 -
get_pids()解析不稳定 — 用ast.literal_eval解析 stdout 最后一行,但如果 Windows 端 Python 输出了 warning、encoding 错误等额外信息,解析可能失败。建议加一个明确的标记(如##RESULT:前缀)来定位输出。 -
main()无错误处理 —subprocess.run(["python.exe", windows_full_path])没有检查 returncode,执行失败时会静默通过。 -
路径转换不完整 —
config.py中只转换了db_dir,但keys_file、decrypted_dir、decoded_image_dir在 WSL 下如果是 Windows 路径也需要转换。建议统一处理。
P2 - 建议改进
-
文件末尾缺少换行符 —
find_all_keys_wsl.py和wsl_utils.py末尾缺少 newline。 -
命名风格不一致 —
isRunningOnWsl、convertWindowsPath2Wsl是 camelCase,项目其他代码用 snake_case(如load_config、get_pids)。建议改为is_running_on_wsl、convert_windows_path_to_wsl。 -
前置条件未说明 — WSL 模式需要 Windows 端也安装 Python 和 pycryptodome,建议在 README 中补充说明。
修复以上问题后可以合并,再次感谢贡献!
|
The requested changes have been made |
Windows Subsystem for Linux (WSL), is a growingly popular linux virtual machine that comes built-in with windows computers.
Currently, the script main.py can not be run from WSL because:
This commit makes some simple and minimal changes to port the existing windows scripts to wsl. The key idea is to call the windows version of python as a subprocess to run find_all_keys_windows.py, and to handle file formats appropriately. While not the most efficient strategy, it is the simplest and this process is not the bottleneck for compute time anyway.
The updated tool can now be used in a fully integrated wsl workflow, by launching main.py directly