From 516676cd2571e4593c1b29ad5042f15319c0ec89 Mon Sep 17 00:00:00 2001 From: wangyw15 Date: Sun, 5 May 2024 00:41:17 +0800 Subject: [PATCH] Enable offline export --- AssemblyPatcher.cs | 87 +++++++++++++++++++++++++++++++++++++++++ CeVIO.cs | 7 ++-- CeVIO_crack.csproj | 11 ++++++ Program.cs | 34 ++++++++++------ Properties/app.manifest | 73 ++++++++++++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 15 deletions(-) create mode 100644 AssemblyPatcher.cs create mode 100644 Properties/app.manifest diff --git a/AssemblyPatcher.cs b/AssemblyPatcher.cs new file mode 100644 index 0000000..d6796ee --- /dev/null +++ b/AssemblyPatcher.cs @@ -0,0 +1,87 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace CeVIO_crack +{ + public static class AssemblyPatcher + { + private const string TARGET_FILE = "CeVIO.ToolBarControl.dll"; + public static void PatchFile(string cevioInstallPath) + { + // System.Void CeVIO.ToolBarControl.ToolBarControl::.cctor() + // System.Reflection.Assembly.GetEntryAssembly().GetType("CeVIO.Editor.MissionAssistant.Authorizer").GetProperty("HasAuthorized").SetValue(null, true); + + var modulePath = Path.Combine(cevioInstallPath, TARGET_FILE); + if (!File.Exists(modulePath)) + { + throw new FileNotFoundException($"{TARGET_FILE} not found"); + } + + // find method + var module = ModuleDefinition.ReadModule(modulePath); + var type = module.GetType("CeVIO.ToolBarControl.ToolBarControl"); + var method = type.Methods.First(m => m.Name == ".cctor"); + + // patch + var processor = method.Body.GetILProcessor(); + var instructions = new Instruction[] + { + processor.Create(OpCodes.Call, module.ImportReference(typeof(Assembly).GetMethod("GetEntryAssembly"))), + processor.Create(OpCodes.Ldstr, "CeVIO.Editor.MissionAssistant.Authorizer"), + processor.Create(OpCodes.Callvirt, module.ImportReference(typeof(Assembly).GetMethod("GetType", new Type[] { typeof(string) }))), + processor.Create(OpCodes.Ldstr, "HasAuthorized"), + processor.Create(OpCodes.Callvirt, module.ImportReference(typeof(Type).GetMethod("GetProperty", new Type[] { typeof(string) }))), + processor.Create(OpCodes.Ldnull), + processor.Create(OpCodes.Ldc_I4_1), + processor.Create(OpCodes.Box, module.ImportReference(typeof(bool))), + processor.Create(OpCodes.Callvirt, module.ImportReference(typeof(PropertyInfo).GetMethod("SetValue", new Type[] { typeof(object), typeof(object) }))) + }; + + for (var i = instructions.Length - 1; i >= 0; i--) + { + processor.InsertBefore(method.Body.Instructions[0], instructions[i]); + } + + // write + module.Write(TARGET_FILE); + } + + public static void DeleteNgen(string cevioInstallPath) + { + foreach (var i in Directory.GetFiles(cevioInstallPath)) + { + if (!Regex.IsMatch(Path.GetFileName(i), @"cevio.*\.(?:exe|dll)", RegexOptions.IgnoreCase)) + { + continue; + } + var process = new Process(); + process.StartInfo.FileName = "C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ngen.exe"; + process.StartInfo.Arguments = $"uninstall \"{i}\""; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.CreateNoWindow = true; + process.Start(); + process.WaitForExit(); + Console.WriteLine("ngen uninstalled " + i); + } + } + + public static void ReplaceFile(string cevioInstallPath) + { + var sourcePath = Path.GetFullPath(TARGET_FILE); + var targetPath = Path.Combine(cevioInstallPath, TARGET_FILE); + var process = new Process(); + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.Arguments = $"/c \"timeout 1 /nobreak & copy /y \"{sourcePath}\" \"{targetPath}\" & del \"{sourcePath}\" & echo Completed & pause\""; + process.StartInfo.UseShellExecute = false; + process.Start(); + } + } +} diff --git a/CeVIO.cs b/CeVIO.cs index 6ddbcbc..312c923 100644 --- a/CeVIO.cs +++ b/CeVIO.cs @@ -9,12 +9,12 @@ namespace CeVIO public class CeVIOAssembly { public Assembly Instance { get; } - + private Type _EditorResource; - public CeVIOAssembly(string cevioPath) + public CeVIOAssembly(string cevioExecutablePath) { - Instance = Assembly.LoadFile(cevioPath); + Instance = Assembly.LoadFile(cevioExecutablePath); _EditorResource = Instance.GetType("CeVIO.Editor.Properties.Resources"); } @@ -100,7 +100,6 @@ public IEnumerable Licenses get { var licenses = Instance.GetProperty("Licenses"); - var a = licenses.GetValue(null); return licenses.GetValue(null) as IEnumerable; } } diff --git a/CeVIO_crack.csproj b/CeVIO_crack.csproj index b6c2d36..a5d8341 100644 --- a/CeVIO_crack.csproj +++ b/CeVIO_crack.csproj @@ -52,6 +52,15 @@ prompt true + + LocalIntranet + + + false + + + Properties\app.manifest + packages\Mono.Cecil.0.11.5\lib\net40\Mono.Cecil.dll @@ -79,12 +88,14 @@ + + \ No newline at end of file diff --git a/Program.cs b/Program.cs index ead46f4..7acd684 100644 --- a/Program.cs +++ b/Program.cs @@ -9,38 +9,50 @@ class Program // N54KC-7U2ZL-PQZBM-SPF8H suzuki trial key static void Main(string[] args) { - var path = GetCeVIOExecutable(); - if (string.IsNullOrEmpty(path)) + var executablePath = GetCeVIOExecutable(); + if (string.IsNullOrEmpty(executablePath)) { Console.Write("CeVIO AI.exe not found, please specify the file: "); - path = (Console.ReadLine() ?? "").Replace("\"", ""); + executablePath = (Console.ReadLine() ?? "").Replace("\"", ""); } - var activator = new Activator(path); - + Console.WriteLine("Loading..."); - + var activator = new Activator(executablePath); activator.ActivateProducts(); Console.WriteLine("Activated all packages"); activator.GenerateLicenseSummary(); Console.WriteLine("Authorized"); - Console.WriteLine("Completed"); + var installFolder = GetCeVIOInstallFolder(); + + Console.WriteLine("Patching CeVIO.ToolBarControl.dll"); + AssemblyPatcher.PatchFile(installFolder); + + Console.WriteLine("Deleting Ngen"); + AssemblyPatcher.DeleteNgen(installFolder); + Console.WriteLine("You should reactivate CeVIO AI before " + DateTime.Now.AddDays(365).ToLongDateString()); - Console.ReadLine(); + + Console.WriteLine("Replace the file to enable offline export"); + AssemblyPatcher.ReplaceFile(installFolder); } - private static string GetCeVIOExecutable() + private static string GetCeVIOInstallFolder() { - var folder = ""; using (var reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\CeVIO_NV\\Subject\\Editor\\x64")) { if (reg == null) { return null; } - folder = reg.GetValue("InstallFolder") as string; + return reg.GetValue("InstallFolder") as string; } + } + + private static string GetCeVIOExecutable() + { + var folder = GetCeVIOInstallFolder(); if (string.IsNullOrEmpty(folder)) { diff --git a/Properties/app.manifest b/Properties/app.manifest new file mode 100644 index 0000000..a269fff --- /dev/null +++ b/Properties/app.manifest @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file