From 5c1842daaaffc427b935f8f8ba14d5bb3f7cb143 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:58:08 -0400 Subject: [PATCH] Add additional function to the deobfuscation command --- ReCodeItCLI/Commands/DeObfuscate.cs | 7 +++++-- RecodeItLib/Remapper/DeObfuscator.cs | 13 +++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ReCodeItCLI/Commands/DeObfuscate.cs b/ReCodeItCLI/Commands/DeObfuscate.cs index 3b22553..74a1155 100644 --- a/ReCodeItCLI/Commands/DeObfuscate.cs +++ b/ReCodeItCLI/Commands/DeObfuscate.cs @@ -9,9 +9,12 @@ namespace ReCodeIt.Commands; [Command("DeObfuscate", Description = "Generates a de-obfuscated -cleaned dll in the folder your assembly is in")] public class DeObfuscate : ICommand { - [CommandParameter(0, IsRequired = true, Description = "The absolute path to your obfuscated assembly file, folder must contain all references to be resolved.")] + [CommandParameter(0, IsRequired = true, Description = "The absolute path to your obfuscated assembly or exe file, folder must contain all references to be resolved.")] public string AssemblyPath { get; init; } + [CommandParameter(1, IsRequired = false, Description = "Is the target the EFT launcher?")] + public bool IsLauncher { get; init; } = false; + public ValueTask ExecuteAsync(IConsole console) { DataProvider.IsCli = true; @@ -19,7 +22,7 @@ public class DeObfuscate : ICommand Logger.Log("Deobfuscating assembly..."); - Deobfuscator.Deobfuscate(AssemblyPath); + Deobfuscator.Deobfuscate(AssemblyPath, IsLauncher); Logger.Log("Complete", ConsoleColor.Green); diff --git a/RecodeItLib/Remapper/DeObfuscator.cs b/RecodeItLib/Remapper/DeObfuscator.cs index 3aebe88..88e7933 100644 --- a/RecodeItLib/Remapper/DeObfuscator.cs +++ b/RecodeItLib/Remapper/DeObfuscator.cs @@ -7,7 +7,7 @@ namespace ReCodeItLib.Remapper; public static class Deobfuscator { - public static void Deobfuscate(string assemblyPath) + public static void Deobfuscate(string assemblyPath, bool isLauncher = false) { var executablePath = Path.Combine(DataProvider.DataPath, "De4dot", "de4dot.exe"); @@ -54,13 +54,18 @@ public static class Deobfuscator token = $"0x{(deobfRid.Raw | deobfRid.Rid):x4}"; Console.WriteLine($"Deobfuscation token: {token}"); - var process = Process.Start(executablePath, - $"--un-name \"!^<>[a-z0-9]$&!^<>[a-z0-9]__.*$&![A-Z][A-Z]\\$<>.*$&^[a-zA-Z_<{{$][a-zA-Z_0-9<>{{}}$.`-]*$\" \"{assemblyPath}\" --strtyp delegate --strtok \"{token}\""); + var cmd = isLauncher + ? $"--un-name \"!^<>[a-z0-9]$&!^<>[a-z0-9]__.*$&![A-Z][A-Z]\\$<>.*$&^[a-zA-Z_<{{$][a-zA-Z_0-9<>{{}}$.`-]*$\" \"{assemblyPath}\"" + : $"--un-name \"!^<>[a-z0-9]$&!^<>[a-z0-9]__.*$&![A-Z][A-Z]\\$<>.*$&^[a-zA-Z_<{{$][a-zA-Z_0-9<>{{}}$.`-]*$\" \"{assemblyPath}\" --strtyp delegate --strtok \"{token}\""; + + var process = Process.Start(executablePath, cmd); process.WaitForExit(); + var extName = isLauncher ? "-cleaned.exe" : "-cleaned.dll"; + // Fixes "ResolutionScope is null" by rewriting the assembly - var cleanedDllPath = Path.Combine(Path.GetDirectoryName(assemblyPath), Path.GetFileNameWithoutExtension(assemblyPath) + "-cleaned.dll"); + var cleanedDllPath = Path.Combine(Path.GetDirectoryName(assemblyPath), Path.GetFileNameWithoutExtension(assemblyPath) + extName); ModuleDefMD assemblyRewrite = null;