Add additional function to the deobfuscation command

This commit is contained in:
Cj 2024-11-02 15:58:08 -04:00
parent 0e53a50977
commit 5c1842daaa
2 changed files with 14 additions and 6 deletions

View File

@ -9,9 +9,12 @@ namespace ReCodeIt.Commands;
[Command("DeObfuscate", Description = "Generates a de-obfuscated -cleaned dll in the folder your assembly is in")] [Command("DeObfuscate", Description = "Generates a de-obfuscated -cleaned dll in the folder your assembly is in")]
public class DeObfuscate : ICommand 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; } 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) public ValueTask ExecuteAsync(IConsole console)
{ {
DataProvider.IsCli = true; DataProvider.IsCli = true;
@ -19,7 +22,7 @@ public class DeObfuscate : ICommand
Logger.Log("Deobfuscating assembly..."); Logger.Log("Deobfuscating assembly...");
Deobfuscator.Deobfuscate(AssemblyPath); Deobfuscator.Deobfuscate(AssemblyPath, IsLauncher);
Logger.Log("Complete", ConsoleColor.Green); Logger.Log("Complete", ConsoleColor.Green);

View File

@ -7,7 +7,7 @@ namespace ReCodeItLib.Remapper;
public static class Deobfuscator 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"); var executablePath = Path.Combine(DataProvider.DataPath, "De4dot", "de4dot.exe");
@ -54,13 +54,18 @@ public static class Deobfuscator
token = $"0x{(deobfRid.Raw | deobfRid.Rid):x4}"; token = $"0x{(deobfRid.Raw | deobfRid.Rid):x4}";
Console.WriteLine($"Deobfuscation token: {token}"); Console.WriteLine($"Deobfuscation token: {token}");
var process = Process.Start(executablePath, var cmd = isLauncher
$"--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}\""); ? $"--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(); process.WaitForExit();
var extName = isLauncher ? "-cleaned.exe" : "-cleaned.dll";
// Fixes "ResolutionScope is null" by rewriting the assembly // 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; ModuleDefMD assemblyRewrite = null;