运行 CFR 反编译
(cfr_path: str, input_path: str, output_dir: str)
| 70 | |
| 71 | |
| 72 | def run_cfr(cfr_path: str, input_path: str, output_dir: str) -> tuple[bool, str]: |
| 73 | """运行 CFR 反编译""" |
| 74 | cmd = [ |
| 75 | "java", "-jar", cfr_path, |
| 76 | input_path, |
| 77 | "--outputdir", output_dir |
| 78 | ] |
| 79 | |
| 80 | try: |
| 81 | result = subprocess.run( |
| 82 | cmd, |
| 83 | capture_output=True, |
| 84 | text=True, |
| 85 | timeout=300 |
| 86 | ) |
| 87 | |
| 88 | if result.returncode == 0: |
| 89 | return True, result.stdout or "反编译成功" |
| 90 | else: |
| 91 | return False, result.stderr or result.stdout or "反编译失败" |
| 92 | except subprocess.TimeoutExpired: |
| 93 | return False, "反编译超时(超过5分钟)" |
| 94 | except FileNotFoundError: |
| 95 | return False, "未找到 Java 运行时,请确保已安装 Java 并添加到 PATH" |
| 96 | except Exception as e: |
| 97 | return False, f"反编译出错: {str(e)}" |
| 98 | |
| 99 | |
| 100 | def collect_files(path: str, extensions: tuple = (".class", ".jar")) -> list[str]: |
no outgoing calls
no test coverage detected