使用Mono.Cecil自动补丁.net程序

坚果云是我常用的一个工具,但是我一般喜欢使用绿色版,不喜欢程序到处写文件,也不喜欢重装以后还要各种登录。所以要折腾“绿色版”来使用。坚果云的完整版下载链接为 https://pkg-cdn.jianguoyun.com/static/exe/installer/NutstoreWindowsWPF_Full.exe 手动IL处理 一般手动处理坚果云的个人用户资料目录。需要使用dnspyEx,然后修改NutstoreLib.dll中的Utils.DirectoryUtils下的APPDATA_NUTSTORE_DIR,下面是我的一个手动IL修改列表: 0 0000 call string NutstoreLib.Utils.DirectoryUtils::get_NUTSTORE_INSTALL_DIR() 1 0005 newobj instance void [mscorlib]System.IO.DirectoryInfo::.ctor(string) 2 000A call instance class [mscorlib]System.IO.DirectoryInfo [mscorlib]System.IO.DirectoryInfo::get_Parent() 3 000F callvirt instance string [mscorlib]System.IO.FileSystemInfo::get_FullName() 4 0014 ldstr "UserData" 5 0019 call string [Pri.LongPath]Pri.LongPath.Path::Combine(string, string) 6 001E ret 自动IL处理 借助Mono.Cecil我们可以实现上面的功能,自动进行dll的patch修改。 注:因为我不喜欢调用太多的库,所以Pri.LongPath.Path::Combine(string, string)我改为了系统的库 完整代码如下: using System.Linq; using Mono.Cecil; using Mono.Cecil.Cil; namespace NutstoreAutoPatch { internal class Program { public static void Main(string[] args) { const string nutstoreLib = "NutstoreLib.dll"; const string directoryutils = "NutstoreLib....

April 4, 2024 · 1 min · czyt