反编译多个 .class 或 .jar 文件(支持多线程) Args: file_paths: 要反编译的文件路径列表 output_dir: 输出目录,默认为当前目录下的 decompiled 文件夹 save_to_file: 是否直接保存到文件系统(推荐),默认为 True show_progress: 是否显示详细进度信息,默认为 True max_workers: 最大并发线程数,默认为 4(设为 1 则单线程处理) Returns: 反编译结
(
file_paths: list[str],
output_dir: Optional[str] = None,
save_to_file: bool = True,
show_progress: bool = True,
max_workers: int = 4
)
| 193 | |
| 194 | @mcp.tool() |
| 195 | def decompile_files( |
| 196 | file_paths: list[str], |
| 197 | output_dir: Optional[str] = None, |
| 198 | save_to_file: bool = True, |
| 199 | show_progress: bool = True, |
| 200 | max_workers: int = 4 |
| 201 | ) -> str: |
| 202 | """ |
| 203 | 反编译多个 .class 或 .jar 文件(支持多线程) |
| 204 | |
| 205 | Args: |
| 206 | file_paths: 要反编译的文件路径列表 |
| 207 | output_dir: 输出目录,默认为当前目录下的 decompiled 文件夹 |
| 208 | save_to_file: 是否直接保存到文件系统(推荐),默认为 True |
| 209 | show_progress: 是否显示详细进度信息,默认为 True |
| 210 | max_workers: 最大并发线程数,默认为 4(设为 1 则单线程处理) |
| 211 | |
| 212 | Returns: |
| 213 | 反编译结果信息 |
| 214 | """ |
| 215 | if not file_paths: |
| 216 | return "错误:未提供任何文件" |
| 217 | |
| 218 | # 确定输出目录 |
| 219 | if output_dir is None: |
| 220 | output_dir = os.path.join(os.getcwd(), "decompiled") |
| 221 | output_dir = os.path.abspath(output_dir) |
| 222 | os.makedirs(output_dir, exist_ok=True) |
| 223 | |
| 224 | # 获取 CFR |
| 225 | try: |
| 226 | cfr_path = ensure_cfr() |
| 227 | except Exception as e: |
| 228 | return f"错误:无法获取 CFR 反编译器 - {str(e)}" |
| 229 | |
| 230 | results = [] |
| 231 | success_count = 0 |
| 232 | fail_count = 0 |
| 233 | skip_count = 0 |
| 234 | total = len(file_paths) |
| 235 | |
| 236 | # 预处理:过滤有效文件 |
| 237 | valid_files = [] |
| 238 | for file_path in file_paths: |
| 239 | file_path = os.path.abspath(file_path) |
| 240 | |
| 241 | if not os.path.isfile(file_path): |
| 242 | if show_progress: |
| 243 | results.append(f"❌ 跳过(文件不存在): {file_path}") |
| 244 | skip_count += 1 |
| 245 | continue |
| 246 | |
| 247 | ext = os.path.splitext(file_path)[1].lower() |
| 248 | if ext not in (".class", ".jar"): |
| 249 | if show_progress: |
| 250 | results.append(f"❌ 跳过(不支持的类型): {file_path}") |
| 251 | skip_count += 1 |
| 252 | continue |
no test coverage detected