| 15 | logger = logging.getLogger(__name__) |
| 16 | |
| 17 | def PlusOBF(file_path: str) -> str: |
| 18 | path = Path(file_path) |
| 19 | output_filename = path.stem + "-cleaned.py" |
| 20 | |
| 21 | try: |
| 22 | content = path.read_text(encoding='utf-8', errors='replace') |
| 23 | regex = re.findall(r"\[(.*?)\]", content) |
| 24 | if not regex: |
| 25 | return "Detected PlusOBF but could not find data patterns." |
| 26 | |
| 27 | # Safely evaluate the bracketed content |
| 28 | try: |
| 29 | data = ast.literal_eval(f"[{regex[0]}]") |
| 30 | # The original logic used len(i), assuming i is a string/list member |
| 31 | cleaned = "".join([chr(len(str(i))) for i in data]) |
| 32 | except Exception as e: |
| 33 | logger.error(f"PlusOBF analysis failed: {e}") |
| 34 | return f"PlusOBF analysis failed: {e}" |
| 35 | |
| 36 | header = "# Cleaned with de4py | https://github.com/Fadi002/de4py\n" |
| 37 | full_content = header + cleaned |
| 38 | |
| 39 | output_path = path.parent / output_filename |
| 40 | output_path.write_text(full_content, encoding="utf-8") |
| 41 | |
| 42 | return f"Saved as {output_filename}\n\n\n{full_content}" |
| 43 | except Exception as e: |
| 44 | logger.error(f"PlusOBF engine encountered an error: {e}") |
| 45 | return f"Engine failed: {e}" |