Skip to content

Commit

Permalink
Enable offline export
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyw15 committed May 4, 2024
1 parent b4b97bb commit 516676c
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 15 deletions.
87 changes: 87 additions & 0 deletions AssemblyPatcher.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
7 changes: 3 additions & 4 deletions CeVIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -100,7 +100,6 @@ public IEnumerable<object> Licenses
get
{
var licenses = Instance.GetProperty("Licenses");
var a = licenses.GetValue(null);
return licenses.GetValue(null) as IEnumerable<object>;
}
}
Expand Down
11 changes: 11 additions & 0 deletions CeVIO_crack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.11.5.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>packages\Mono.Cecil.0.11.5\lib\net40\Mono.Cecil.dll</HintPath>
Expand Down Expand Up @@ -79,12 +88,14 @@
<Compile Include="Activator.cs" />
<Compile Include="CeVIO.cs" />
<Compile Include="ExecutableModifier.cs" />
<Compile Include="AssemblyPatcher.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
34 changes: 23 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
73 changes: 73 additions & 0 deletions Properties/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

0 comments on commit 516676c

Please sign in to comment.