diff --git a/Assets/de4dot/AssemblyData.dll b/Assets/de4dot/AssemblyData.dll
index 6b8a250..91ac918 100644
Binary files a/Assets/de4dot/AssemblyData.dll and b/Assets/de4dot/AssemblyData.dll differ
diff --git a/Assets/de4dot/AssemblyServer-x64.exe b/Assets/de4dot/AssemblyServer-x64.exe
new file mode 100644
index 0000000..9a8d086
Binary files /dev/null and b/Assets/de4dot/AssemblyServer-x64.exe differ
diff --git a/Assets/de4dot/AssemblyServer-x64.exe.config b/Assets/de4dot/AssemblyServer-x64.exe.config
new file mode 100644
index 0000000..c254b3c
--- /dev/null
+++ b/Assets/de4dot/AssemblyServer-x64.exe.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assets/de4dot/de4dot-x64.exe b/Assets/de4dot/de4dot-x64.exe
new file mode 100644
index 0000000..32e5ca2
Binary files /dev/null and b/Assets/de4dot/de4dot-x64.exe differ
diff --git a/Assets/de4dot/de4dot-x64.exe.config b/Assets/de4dot/de4dot-x64.exe.config
new file mode 100644
index 0000000..1fda120
--- /dev/null
+++ b/Assets/de4dot/de4dot-x64.exe.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assets/de4dot/de4dot.blocks.dll b/Assets/de4dot/de4dot.blocks.dll
index 6983abd..86ed5b3 100644
Binary files a/Assets/de4dot/de4dot.blocks.dll and b/Assets/de4dot/de4dot.blocks.dll differ
diff --git a/Assets/de4dot/de4dot.code.dll b/Assets/de4dot/de4dot.code.dll
index c43643e..7e52155 100644
Binary files a/Assets/de4dot/de4dot.code.dll and b/Assets/de4dot/de4dot.code.dll differ
diff --git a/Assets/de4dot/de4dot.cui.dll b/Assets/de4dot/de4dot.cui.dll
index 3e32a85..703ab32 100644
Binary files a/Assets/de4dot/de4dot.cui.dll and b/Assets/de4dot/de4dot.cui.dll differ
diff --git a/Assets/de4dot/de4dot.exe b/Assets/de4dot/de4dot.exe
deleted file mode 100644
index d8ae798..0000000
Binary files a/Assets/de4dot/de4dot.exe and /dev/null differ
diff --git a/Assets/de4dot/de4dot.mdecrypt.dll b/Assets/de4dot/de4dot.mdecrypt.dll
index 1b48852..48989fb 100644
Binary files a/Assets/de4dot/de4dot.mdecrypt.dll and b/Assets/de4dot/de4dot.mdecrypt.dll differ
diff --git a/Assets/de4dot/dnlib.dll b/Assets/de4dot/dnlib.dll
index c43c9b6..11ba648 100644
Binary files a/Assets/de4dot/dnlib.dll and b/Assets/de4dot/dnlib.dll differ
diff --git a/RecodeItLib/Remapper/DeObfuscator.cs b/RecodeItLib/Remapper/DeObfuscator.cs
index af6650c..9ea5931 100644
--- a/RecodeItLib/Remapper/DeObfuscator.cs
+++ b/RecodeItLib/Remapper/DeObfuscator.cs
@@ -10,7 +10,7 @@ public static class Deobfuscator
{
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-x64.exe");
string token;
diff --git a/de4dot/.editorconfig b/de4dot/.editorconfig
new file mode 100644
index 0000000..63fd71d
--- /dev/null
+++ b/de4dot/.editorconfig
@@ -0,0 +1,112 @@
+root = true
+
+[*]
+charset = utf-8
+#end_of_line =
+indent_size = 4
+indent_style = tab
+tab_width = 4
+
+[*.json]
+
+[app.config]
+
+[*.yml]
+indent_size = 2
+indent_style = space
+
+[*.{proj,csproj,vbproj,props,targets,resx,vsixmanifest}]
+indent_size = 2
+indent_style = space
+
+[app.manifest]
+indent_size = 2
+indent_style = space
+
+[*.xml]
+
+[*.xaml]
+indent_style = space
+
+[*.{cs,vb}]
+insert_final_newline = true
+
+dotnet_separate_import_directive_groups = false
+dotnet_sort_system_directives_first = true
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_predefined_type_for_locals_parameters_members = true:none
+dotnet_style_predefined_type_for_member_access = true:none
+dotnet_style_prefer_auto_properties = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = false:suggestion
+dotnet_style_qualification_for_event = false:suggestion
+dotnet_style_qualification_for_field = false:suggestion
+dotnet_style_qualification_for_method = false:suggestion
+dotnet_style_qualification_for_property = false:suggestion
+dotnet_style_require_accessibility_modifiers = never:info
+
+[*.cs]
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_case_contents_when_block = false
+csharp_indent_labels = flush_left
+csharp_indent_switch_labels = false
+csharp_new_line_before_catch = true
+csharp_new_line_before_else = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_open_brace = none
+csharp_new_line_between_query_expression_clauses = true
+csharp_prefer_braces = false
+csharp_prefer_simple_default_expression = true:suggestion
+#csharp_preferred_modifier_order =
+csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = true
+csharp_space_after_cast = false
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
+csharp_space_after_keywords_in_control_flow_statements = true
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_space_between_method_call_parameter_list_parentheses = false
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_between_parentheses =
+csharp_space_between_square_brackets = false
+csharp_style_conditional_delegate_call = true:suggestion
+csharp_style_deconstructed_variable_declaration = false:none
+csharp_style_expression_bodied_accessors = true:suggestion
+csharp_style_expression_bodied_constructors = true:suggestion
+csharp_style_expression_bodied_indexers = true:suggestion
+csharp_style_expression_bodied_methods = true:suggestion
+csharp_style_expression_bodied_operators = true:suggestion
+csharp_style_expression_bodied_properties = true:suggestion
+csharp_style_inlined_variable_declaration = true:suggestion
+csharp_style_pattern_local_over_anonymous_function = true:suggestion
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_throw_expression = true:suggestion
+csharp_style_var_elsewhere = true:suggestion
+csharp_style_var_for_built_in_types = false:none
+csharp_style_var_when_type_is_apparent = true:suggestion
+
+[*.vb]
+#visual_basic_preferred_modifier_order =
diff --git a/de4dot/.gitignore b/de4dot/.gitignore
new file mode 100644
index 0000000..915a022
--- /dev/null
+++ b/de4dot/.gitignore
@@ -0,0 +1,10 @@
+*~
+.vs/
+bin/
+obj/
+Release/
+Debug/
+publish-netcoreapp*/
+launchSettings.json
+*.user
+.nuget/
\ No newline at end of file
diff --git a/de4dot/AssemblyData/AssemblyData.csproj b/de4dot/AssemblyData/AssemblyData.csproj
new file mode 100644
index 0000000..d306984
--- /dev/null
+++ b/de4dot/AssemblyData/AssemblyData.csproj
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/de4dot/AssemblyData/AssemblyResolver.cs b/de4dot/AssemblyData/AssemblyResolver.cs
new file mode 100644
index 0000000..bd491dc
--- /dev/null
+++ b/de4dot/AssemblyData/AssemblyResolver.cs
@@ -0,0 +1,134 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+
+namespace AssemblyData {
+ class AssemblyResolver {
+ Dictionary assemblies = new Dictionary(StringComparer.Ordinal);
+ Dictionary assemblySearchPathsDict = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ List assemblySearchPaths = new List();
+
+ public AssemblyResolver() => AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
+
+ void AddAssemblySearchPath(string path) {
+ if (assemblySearchPathsDict.ContainsKey(path))
+ return;
+ assemblySearchPathsDict[path] = true;
+ assemblySearchPaths.Add(path);
+ }
+
+ Assembly Get(string assemblyFullName) {
+ var asmName = new AssemblyName(assemblyFullName);
+
+ if (assemblies.TryGetValue(asmName.FullName, out var assembly))
+ return assembly;
+ if (assemblies.TryGetValue(asmName.Name, out assembly))
+ return assembly;
+
+ return null;
+ }
+
+ static string[] assemblyExtensions = new string[] { ".dll", ".exe" };
+ Assembly AssemblyResolve(object sender, ResolveEventArgs args) {
+ var assembly = Get(args.Name);
+ if (assembly != null)
+ return assembly;
+
+ var asmName = new AssemblyName(args.Name);
+ foreach (var path in assemblySearchPaths) {
+ foreach (var ext in assemblyExtensions) {
+ try {
+ var filename = Path.Combine(path, asmName.Name + ext);
+ if (!new FileInfo(filename).Exists)
+ continue;
+ AddConfigFile(filename + ".config");
+ return AddAssembly(Assembly.LoadFile(filename));
+ }
+ catch (IOException) {
+ }
+ catch (BadImageFormatException) {
+ }
+ catch (ArgumentException) {
+ }
+ catch (NotSupportedException) {
+ }
+ catch (UnauthorizedAccessException) {
+ }
+ catch (System.Security.SecurityException) {
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public Assembly Load(string filename) {
+ AddConfigFile(filename + ".config");
+ return AddAssembly(LoadFile(filename));
+ }
+
+ Assembly LoadFile(string filename) {
+ try {
+ return Assembly.LoadFrom(filename);
+ }
+ catch (FileLoadException) {
+ // Here if eg. strong name signature validation failed and possibly other errors
+ return Assembly.Load(File.ReadAllBytes(filename));
+ }
+ }
+
+ Assembly AddAssembly(Assembly assembly) {
+ var asmName = assembly.GetName();
+ assemblies[asmName.FullName] = assembly;
+ assemblies[asmName.Name] = assembly;
+ return assembly;
+ }
+
+ void AddConfigFile(string configFilename) {
+ var dirName = Utils.GetDirName(Utils.GetFullPath(configFilename));
+ AddAssemblySearchPath(dirName);
+
+ try {
+ using (var xmlStream = new FileStream(configFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
+ var doc = new XmlDocument();
+ doc.Load(XmlReader.Create(xmlStream));
+ foreach (var tmp in doc.GetElementsByTagName("probing")) {
+ var probingElem = tmp as XmlElement;
+ if (probingElem == null)
+ continue;
+ var privatePath = probingElem.GetAttribute("privatePath");
+ if (string.IsNullOrEmpty(privatePath))
+ continue;
+ foreach (var path in privatePath.Split(';'))
+ AddAssemblySearchPath(Path.Combine(dirName, path));
+ }
+ }
+ }
+ catch (IOException) {
+ }
+ catch (XmlException) {
+ }
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/AssemblyServer.cs b/de4dot/AssemblyData/AssemblyServer.cs
new file mode 100644
index 0000000..8958870
--- /dev/null
+++ b/de4dot/AssemblyData/AssemblyServer.cs
@@ -0,0 +1,63 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+#if NETFRAMEWORK
+using System;
+using System.Collections;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Ipc;
+using AssemblyData;
+
+namespace AssemblyServer {
+ public static class Start {
+ public static int Main(string[] args) {
+ if (args.Length != 3)
+ Environment.Exit(1);
+ var serviceType = (AssemblyServiceType)int.Parse(args[0]);
+ var channelName = args[1];
+ var uri = args[2];
+
+ var service = (AssemblyService)AssemblyService.Create(serviceType);
+ StartServer(service, channelName, uri);
+ service.WaitExit();
+ return 0;
+ }
+
+ static void StartServer(AssemblyService service, string name, string uri) {
+ var props = new Hashtable();
+ props["portName"] = name;
+ var provider = new BinaryServerFormatterSinkProvider();
+ provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
+ var channel = new IpcServerChannel(props, provider);
+ ChannelServices.RegisterChannel(channel, false);
+ RemotingServices.Marshal(service, uri);
+ }
+ }
+}
+#else
+namespace AssemblyServer {
+ public static class Start {
+ public static int Main(string[] args) {
+ System.Console.WriteLine("Not supported");
+ return -1;
+ }
+ }
+}
+#endif
diff --git a/de4dot/AssemblyData/AssemblyService.cs b/de4dot/AssemblyData/AssemblyService.cs
new file mode 100644
index 0000000..19e86cb
--- /dev/null
+++ b/de4dot/AssemblyData/AssemblyService.cs
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+using System.Threading;
+
+namespace AssemblyData {
+ public abstract class AssemblyService : MarshalByRefObject, IAssemblyService {
+ ManualResetEvent exitEvent = new ManualResetEvent(false);
+ protected Assembly assembly = null;
+ AssemblyResolver assemblyResolver = new AssemblyResolver();
+
+ public static AssemblyService Create(AssemblyServiceType serviceType) {
+ switch (serviceType) {
+ case AssemblyServiceType.StringDecrypter:
+ return new StringDecrypterService();
+
+ case AssemblyServiceType.MethodDecrypter:
+ return new MethodDecrypterService();
+
+ case AssemblyServiceType.Generic:
+ return new GenericService();
+
+ default:
+ throw new ArgumentException("Invalid assembly service type");
+ }
+ }
+
+ public static Type GetType(AssemblyServiceType serviceType) {
+ switch (serviceType) {
+ case AssemblyServiceType.StringDecrypter:
+ return typeof(StringDecrypterService);
+
+ case AssemblyServiceType.MethodDecrypter:
+ return typeof(MethodDecrypterService);
+
+ case AssemblyServiceType.Generic:
+ return typeof(GenericService);
+
+ default:
+ throw new ArgumentException("Invalid assembly service type");
+ }
+ }
+
+ public void DoNothing() { }
+ public virtual void Exit() => exitEvent.Set();
+ public void WaitExit() => exitEvent.WaitOne();
+ public override object InitializeLifetimeService() => null;
+
+ protected void CheckAssembly() {
+ if (assembly == null)
+ throw new ApplicationException("LoadAssembly() hasn't been called yet.");
+ }
+
+ protected void LoadAssemblyInternal(string filename) {
+ if (assembly != null)
+ throw new ApplicationException("Only one assembly can be explicitly loaded");
+ try {
+ assembly = assemblyResolver.Load(filename);
+ }
+ catch (BadImageFormatException ex) {
+ throw new ApplicationException($"Could not load assembly {filename}. Maybe it's 32-bit or 64-bit only?", ex);
+ }
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/DelegateStringDecrypter.cs b/de4dot/AssemblyData/DelegateStringDecrypter.cs
new file mode 100644
index 0000000..00dc7df
--- /dev/null
+++ b/de4dot/AssemblyData/DelegateStringDecrypter.cs
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Collections.Generic;
+
+namespace AssemblyData {
+ class DelegateStringDecrypter : IStringDecrypter {
+ delegate string DecryptString(object[] args);
+ List stringDecryptMethods = new List();
+
+ public int DefineStringDecrypter(MethodInfo method) {
+ stringDecryptMethods.Add(BuildDynamicMethod(method));
+ return stringDecryptMethods.Count - 1;
+ }
+
+ public object[] DecryptStrings(int stringDecrypterMethod, object[] args, MethodBase caller) {
+ if (stringDecrypterMethod > stringDecryptMethods.Count)
+ throw new ApplicationException("Invalid string decrypter method");
+
+ var rv = new object[args.Length];
+ var stringDecrypter = stringDecryptMethods[stringDecrypterMethod];
+ for (int i = 0; i < args.Length; i++)
+ rv[i] = stringDecrypter((object[])args[i]);
+ return rv;
+ }
+
+ DecryptString BuildDynamicMethod(MethodInfo method) {
+ var dm = new DynamicMethod("", typeof(string), new Type[] { typeof(object[]) }, typeof(DelegateStringDecrypter), true);
+ Utils.AddCallStringDecrypterMethodInstructions(method, dm.GetILGenerator());
+ return (DecryptString)dm.CreateDelegate(typeof(DecryptString));
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/EmuStringDecrypter.cs b/de4dot/AssemblyData/EmuStringDecrypter.cs
new file mode 100644
index 0000000..6dde351
--- /dev/null
+++ b/de4dot/AssemblyData/EmuStringDecrypter.cs
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System.Collections.Generic;
+using System.Reflection;
+using AssemblyData.methodsrewriter;
+
+namespace AssemblyData {
+ class EmuStringDecrypter : IStringDecrypter {
+ List decryptInfos = new List();
+ MethodsRewriter methodsRewriter = new MethodsRewriter();
+
+ class DecryptInfo {
+ public MethodInfo method;
+ public RewrittenMethod decryptString;
+
+ public DecryptInfo(MethodInfo method) => this.method = method;
+ }
+
+ public int DefineStringDecrypter(MethodInfo method) {
+ decryptInfos.Add(new DecryptInfo(method));
+ return decryptInfos.Count - 1;
+ }
+
+ public object[] DecryptStrings(int stringDecrypterMethod, object[] args, MethodBase caller) {
+ var decryptInfo = decryptInfos[stringDecrypterMethod];
+ if (decryptInfo.decryptString == null)
+ decryptInfo.decryptString = CreateDecryptString(decryptInfo.method);
+
+ methodsRewriter.SetCaller(decryptInfo.decryptString, caller);
+ var result = new object[args.Length];
+ for (int i = 0; i < args.Length; i++)
+ result[i] = decryptInfo.decryptString((object[])args[i]);
+ return result;
+ }
+
+ RewrittenMethod CreateDecryptString(MethodInfo method) {
+ methodsRewriter.CreateMethod(method);
+ return methodsRewriter.CreateDelegate(method);
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/GenericService.cs b/de4dot/AssemblyData/GenericService.cs
new file mode 100644
index 0000000..a166e07
--- /dev/null
+++ b/de4dot/AssemblyData/GenericService.cs
@@ -0,0 +1,67 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+
+namespace AssemblyData {
+ class GenericService : AssemblyService, IGenericService {
+ IUserGenericService userGenericService;
+
+ public override void Exit() {
+ if (userGenericService != null)
+ userGenericService.Dispose();
+ userGenericService = null;
+ base.Exit();
+ }
+
+ public void LoadUserService(Type createServiceType, object createMethodArgs) {
+ var createServiceMethod = GetCreateUserServiceMethod(createServiceType);
+ userGenericService = createServiceMethod.Invoke(null, null) as IUserGenericService;
+ if (userGenericService == null)
+ throw new ApplicationException("create-service-method failed to create user service");
+ }
+
+ MethodInfo GetCreateUserServiceMethod(Type createServiceType) {
+ if (createServiceType == null)
+ throw new ApplicationException("Create-service-type is null");
+ foreach (var method in createServiceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) {
+ if (method.GetCustomAttributes(typeof(CreateUserGenericServiceAttribute), false).Length > 0)
+ return method;
+ }
+ throw new ApplicationException($"Failed to find create-service-method. Type token: Type: {createServiceType}");
+ }
+
+ void CheckUserService() {
+ if (userGenericService == null)
+ throw new ApplicationException("LoadUserService() hasn't been called yet.");
+ }
+
+ public void LoadAssembly(string filename) {
+ CheckUserService();
+ LoadAssemblyInternal(filename);
+ userGenericService.AssemblyLoaded(assembly);
+ }
+
+ public object SendMessage(int msg, object[] args) {
+ CheckUserService();
+ return userGenericService.HandleMessage(msg, args);
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/IAssemblyService.cs b/de4dot/AssemblyData/IAssemblyService.cs
new file mode 100644
index 0000000..9839765
--- /dev/null
+++ b/de4dot/AssemblyData/IAssemblyService.cs
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+namespace AssemblyData {
+ public enum AssemblyServiceType {
+ StringDecrypter,
+ MethodDecrypter,
+ Generic,
+ }
+
+ public interface IAssemblyService {
+ void DoNothing();
+ void Exit();
+ }
+}
diff --git a/de4dot/AssemblyData/IGenericService.cs b/de4dot/AssemblyData/IGenericService.cs
new file mode 100644
index 0000000..6e517d1
--- /dev/null
+++ b/de4dot/AssemblyData/IGenericService.cs
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+
+namespace AssemblyData {
+ public class CreateUserGenericServiceAttribute : Attribute {
+ }
+
+ public interface IGenericService : IAssemblyService {
+ void LoadUserService(Type createServiceType, object createMethodArgs);
+ void LoadAssembly(string filename);
+ object SendMessage(int msg, object[] args);
+ }
+}
diff --git a/de4dot/AssemblyData/IMethodDecrypterService.cs b/de4dot/AssemblyData/IMethodDecrypterService.cs
new file mode 100644
index 0000000..cbd1ee7
--- /dev/null
+++ b/de4dot/AssemblyData/IMethodDecrypterService.cs
@@ -0,0 +1,30 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using de4dot.blocks;
+using de4dot.mdecrypt;
+
+namespace AssemblyData {
+ public interface IMethodDecrypterService : IAssemblyService {
+ void InstallCompileMethod(DecryptMethodsInfo decryptMethodsInfo);
+ void LoadObfuscator(string filename);
+ bool CanDecryptMethods();
+ DumpedMethods DecryptMethods();
+ }
+}
diff --git a/de4dot/AssemblyData/IStringDecrypter.cs b/de4dot/AssemblyData/IStringDecrypter.cs
new file mode 100644
index 0000000..8f57f26
--- /dev/null
+++ b/de4dot/AssemblyData/IStringDecrypter.cs
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System.Reflection;
+
+namespace AssemblyData {
+ interface IStringDecrypter {
+ int DefineStringDecrypter(MethodInfo method);
+ object[] DecryptStrings(int stringDecrypterMethod, object[] args, MethodBase caller);
+ }
+}
diff --git a/de4dot/AssemblyData/IStringDecrypterService.cs b/de4dot/AssemblyData/IStringDecrypterService.cs
new file mode 100644
index 0000000..37e4a52
--- /dev/null
+++ b/de4dot/AssemblyData/IStringDecrypterService.cs
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+namespace AssemblyData {
+ public enum StringDecrypterType {
+ Delegate,
+ Emulate,
+ }
+
+ public interface IStringDecrypterService : IAssemblyService {
+ void LoadAssembly(string filename);
+ void SetStringDecrypterType(StringDecrypterType type);
+ int DefineStringDecrypter(int methodToken);
+ object[] DecryptStrings(int stringDecrypterMethod, object[] args, int callerToken);
+ }
+}
diff --git a/de4dot/AssemblyData/IUserGenericService.cs b/de4dot/AssemblyData/IUserGenericService.cs
new file mode 100644
index 0000000..36acbe8
--- /dev/null
+++ b/de4dot/AssemblyData/IUserGenericService.cs
@@ -0,0 +1,28 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+
+namespace AssemblyData {
+ public interface IUserGenericService : IDisposable {
+ void AssemblyLoaded(Assembly assembly);
+ object HandleMessage(int msg, object[] args);
+ }
+}
diff --git a/de4dot/AssemblyData/MethodDecrypterService.cs b/de4dot/AssemblyData/MethodDecrypterService.cs
new file mode 100644
index 0000000..88ecc64
--- /dev/null
+++ b/de4dot/AssemblyData/MethodDecrypterService.cs
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using de4dot.blocks;
+using de4dot.mdecrypt;
+
+namespace AssemblyData {
+ class MethodDecrypterService : AssemblyService, IMethodDecrypterService {
+ bool installCompileMethodCalled = false;
+
+ public void InstallCompileMethod(DecryptMethodsInfo decryptMethodsInfo) {
+ if (installCompileMethodCalled)
+ throw new ApplicationException("installCompileMethod() has already been called");
+ installCompileMethodCalled = true;
+ DynamicMethodsDecrypter.Instance.DecryptMethodsInfo = decryptMethodsInfo;
+ DynamicMethodsDecrypter.Instance.InstallCompileMethod();
+ }
+
+ public void LoadObfuscator(string filename) {
+ LoadAssemblyInternal(filename);
+ DynamicMethodsDecrypter.Instance.Module = assembly.ManifestModule;
+ DynamicMethodsDecrypter.Instance.LoadObfuscator();
+ }
+
+ public bool CanDecryptMethods() {
+ CheckAssembly();
+ return DynamicMethodsDecrypter.Instance.CanDecryptMethods();
+ }
+
+ public DumpedMethods DecryptMethods() {
+ CheckAssembly();
+ return DynamicMethodsDecrypter.Instance.DecryptMethods();
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/SimpleData.cs b/de4dot/AssemblyData/SimpleData.cs
new file mode 100644
index 0000000..0777e1a
--- /dev/null
+++ b/de4dot/AssemblyData/SimpleData.cs
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Text;
+
+namespace AssemblyData {
+ // This class will make sure no data in the string is destroyed by serialization
+ [Serializable]
+ class MyString {
+ short[] data;
+
+ public MyString() {
+ }
+
+ public MyString(string s) {
+ if (s == null)
+ data = null;
+ else {
+ data = new short[s.Length];
+ for (int i = 0; i < s.Length; i++)
+ data[i] = (short)s[i];
+ }
+ }
+
+ public override string ToString() {
+ if (data == null)
+ return null;
+
+ var sb = new StringBuilder(data.Length);
+ foreach (var c in data)
+ sb.Append((char)c);
+ return sb.ToString();
+ }
+ }
+
+ public static class SimpleData {
+ public static object[] Pack(object[] args) {
+ for (int i = 0; i < args.Length; i++) {
+ if (args[i] is string s)
+ args[i] = new MyString(s);
+ }
+ return args;
+ }
+
+ public static object[] Unpack(object[] args) {
+ for (int i = 0; i < args.Length; i++) {
+ if (args[i] is MyString s)
+ args[i] = s.ToString();
+ }
+ return args;
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/StringDecrypterService.cs b/de4dot/AssemblyData/StringDecrypterService.cs
new file mode 100644
index 0000000..70daa60
--- /dev/null
+++ b/de4dot/AssemblyData/StringDecrypterService.cs
@@ -0,0 +1,90 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Reflection;
+
+namespace AssemblyData {
+ class StringDecrypterService : AssemblyService, IStringDecrypterService {
+ IStringDecrypter stringDecrypter = null;
+
+ void CheckStringDecrypter() {
+ if (stringDecrypter == null)
+ throw new ApplicationException("SetStringDecrypterType() hasn't been called yet.");
+ }
+
+ public void LoadAssembly(string filename) => LoadAssemblyInternal(filename);
+
+ public void SetStringDecrypterType(StringDecrypterType type) {
+ if (stringDecrypter != null)
+ throw new ApplicationException("StringDecrypterType already set");
+
+ switch (type) {
+ case StringDecrypterType.Delegate:
+ stringDecrypter = new DelegateStringDecrypter();
+ break;
+
+ case StringDecrypterType.Emulate:
+ stringDecrypter = new EmuStringDecrypter();
+ break;
+
+ default:
+ throw new ApplicationException($"Unknown StringDecrypterType {type}");
+ }
+ }
+
+ public int DefineStringDecrypter(int methodToken) {
+ CheckStringDecrypter();
+ var methodInfo = FindMethod(methodToken);
+ if (methodInfo == null)
+ throw new ApplicationException($"Could not find method {methodToken:X8}");
+ if (methodInfo.ReturnType != typeof(string) && methodInfo.ReturnType != typeof(object))
+ throw new ApplicationException($"Method return type must be string or object: {methodInfo}");
+ return stringDecrypter.DefineStringDecrypter(methodInfo);
+ }
+
+ public object[] DecryptStrings(int stringDecrypterMethod, object[] args, int callerToken) {
+ CheckStringDecrypter();
+ var caller = GetCaller(callerToken);
+ foreach (var arg in args)
+ SimpleData.Unpack((object[])arg);
+ return SimpleData.Pack(stringDecrypter.DecryptStrings(stringDecrypterMethod, args, caller));
+ }
+
+ MethodBase GetCaller(int callerToken) {
+ try {
+ return assembly.GetModules()[0].ResolveMethod(callerToken);
+ }
+ catch {
+ return null;
+ }
+ }
+
+ MethodInfo FindMethod(int methodToken) {
+ CheckAssembly();
+
+ foreach (var module in assembly.GetModules()) {
+ if (module.ResolveMethod(methodToken) is MethodInfo method)
+ return method;
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/de4dot/AssemblyData/Utils.cs b/de4dot/AssemblyData/Utils.cs
new file mode 100644
index 0000000..fa32ab6
--- /dev/null
+++ b/de4dot/AssemblyData/Utils.cs
@@ -0,0 +1,174 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+
+namespace AssemblyData {
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17, T18 arg18);
+ internal delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17, T18 arg18, T19 arg19);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17, T18 arg18);
+ internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, T17 arg17, T18 arg18, T19 arg19);
+
+ static class Utils {
+ static Random random = new Random();
+
+ public static uint GetRandomUint() => (uint)(random.NextDouble() * uint.MaxValue);
+
+ public static Type GetDelegateType(Type returnType, Type[] args) {
+ Type[] types;
+ if (returnType == typeof(void)) {
+ types = args;
+ switch (types.Length) {
+ case 0: return typeof(Action).MakeGenericType(types);
+ case 1: return typeof(Action<>).MakeGenericType(types);
+ case 2: return typeof(Action<,>).MakeGenericType(types);
+ case 3: return typeof(Action<,,>).MakeGenericType(types);
+ case 4: return typeof(Action<,,,>).MakeGenericType(types);
+ case 5: return typeof(Action<,,,,>).MakeGenericType(types);
+ case 6: return typeof(Action<,,,,,>).MakeGenericType(types);
+ case 7: return typeof(Action<,,,,,,>).MakeGenericType(types);
+ case 8: return typeof(Action<,,,,,,,>).MakeGenericType(types);
+ case 9: return typeof(Action<,,,,,,,,>).MakeGenericType(types);
+ case 10: return typeof(Action<,,,,,,,,,>).MakeGenericType(types);
+ case 11: return typeof(Action<,,,,,,,,,,>).MakeGenericType(types);
+ case 12: return typeof(Action<,,,,,,,,,,,>).MakeGenericType(types);
+ case 13: return typeof(Action<,,,,,,,,,,,,>).MakeGenericType(types);
+ case 14: return typeof(Action<,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 15: return typeof(Action<,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 16: return typeof(Action<,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 17: return typeof(Action<,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 18: return typeof(Action<,,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 19: return typeof(Action<,,,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ default:
+ throw new ApplicationException($"Too many delegate type arguments: {types.Length}");
+ }
+ }
+ else {
+ types = new Type[args.Length + 1];
+ Array.Copy(args, types, args.Length);
+ types[types.Length - 1] = returnType;
+
+ switch (types.Length) {
+ case 1: return typeof(Func<>).MakeGenericType(types);
+ case 2: return typeof(Func<,>).MakeGenericType(types);
+ case 3: return typeof(Func<,,>).MakeGenericType(types);
+ case 4: return typeof(Func<,,,>).MakeGenericType(types);
+ case 5: return typeof(Func<,,,,>).MakeGenericType(types);
+ case 6: return typeof(Func<,,,,,>).MakeGenericType(types);
+ case 7: return typeof(Func<,,,,,,>).MakeGenericType(types);
+ case 8: return typeof(Func<,,,,,,,>).MakeGenericType(types);
+ case 9: return typeof(Func<,,,,,,,,>).MakeGenericType(types);
+ case 10: return typeof(Func<,,,,,,,,,>).MakeGenericType(types);
+ case 11: return typeof(Func<,,,,,,,,,,>).MakeGenericType(types);
+ case 12: return typeof(Func<,,,,,,,,,,,>).MakeGenericType(types);
+ case 13: return typeof(Func<,,,,,,,,,,,,>).MakeGenericType(types);
+ case 14: return typeof(Func<,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 15: return typeof(Func<,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 16: return typeof(Func<,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 17: return typeof(Func<,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 18: return typeof(Func<,,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 19: return typeof(Func<,,,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ case 20: return typeof(Func<,,,,,,,,,,,,,,,,,,,>).MakeGenericType(types);
+ default:
+ throw new ApplicationException($"Too many delegate type arguments: {types.Length}");
+ }
+ }
+ }
+
+ public static string RandomName(int min, int max) {
+ int numChars = random.Next(min, max + 1);
+ var sb = new StringBuilder(numChars);
+ int numLower = 0;
+ for (int i = 0; i < numChars; i++) {
+ if (numLower == 0)
+ sb.Append((char)((int)'A' + random.Next(26)));
+ else
+ sb.Append((char)((int)'a' + random.Next(26)));
+
+ if (numLower == 0) {
+ numLower = random.Next(1, 5);
+ }
+ else {
+ numLower--;
+ }
+ }
+ return sb.ToString();
+ }
+
+ public static void AddCallStringDecrypterMethodInstructions(MethodInfo method, ILGenerator ilg) {
+ var args = method.GetParameters();
+ for (int i = 0; i < args.Length; i++) {
+ var arg = args[i].ParameterType;
+
+ ilg.Emit(OpCodes.Ldarg_0);
+ ilg.Emit(OpCodes.Ldc_I4, i);
+ ilg.Emit(OpCodes.Ldelem_Ref);
+
+ if (arg.IsValueType)
+ ilg.Emit(OpCodes.Unbox_Any, arg);
+ else
+ ilg.Emit(OpCodes.Castclass, arg);
+ }
+ ilg.Emit(OpCodes.Call, method);
+ ilg.Emit(OpCodes.Ret);
+ }
+
+ public static string GetFullPath(string path) {
+ try {
+ return Path.GetFullPath(path);
+ }
+ catch (Exception) {
+ return path;
+ }
+ }
+
+ public static string GetDirName(string name) => Path.GetDirectoryName(name);
+ }
+}
diff --git a/de4dot/AssemblyData/methodsrewriter/AssemblyResolver.cs b/de4dot/AssemblyData/methodsrewriter/AssemblyResolver.cs
new file mode 100644
index 0000000..b4538e9
--- /dev/null
+++ b/de4dot/AssemblyData/methodsrewriter/AssemblyResolver.cs
@@ -0,0 +1,141 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using dnlib.DotNet;
+
+namespace AssemblyData.methodsrewriter {
+ class MGenericParameter {
+ }
+
+ class AssemblyResolver {
+ Dictionary> types = new Dictionary>(StringComparer.Ordinal);
+ List globalMethods;
+ List globalFields;
+ Assembly assembly;
+
+ public AssemblyResolver(string asmName) {
+ assembly = Assembly.Load(new AssemblyName(asmName));
+ InitTypes();
+ }
+
+ void InitTypes() {
+ foreach (var type in assembly.GetTypes()) {
+ string key = (type.Namespace ?? "") + "." + type.Name;
+ if (!types.TryGetValue(key, out var list))
+ types[key] = list = new List();
+ list.Add(new TypeResolver(type));
+ }
+ }
+
+ TypeResolver GetTypeResolver(ITypeDefOrRef typeRef) {
+ if (typeRef == null)
+ return null;
+ var scopeType = typeRef.ScopeType;
+ var key = scopeType.Namespace + "." + scopeType.TypeName;
+ if (!types.TryGetValue(key, out var list))
+ return null;
+
+ if (scopeType is TypeDef) {
+ foreach (var resolver in list) {
+ if (resolver.type.MetadataToken == scopeType.MDToken.Raw)
+ return resolver;
+ }
+ }
+
+ foreach (var resolver in list) {
+ if (ResolverUtils.CompareTypes(resolver.type, scopeType))
+ return resolver;
+ }
+
+ return null;
+ }
+
+ public FieldInfo Resolve(IField fieldRef) {
+ var resolver = GetTypeResolver(fieldRef.DeclaringType);
+ if (resolver != null)
+ return resolver.Resolve(fieldRef);
+ return ResolveGlobalField(fieldRef);
+ }
+
+ FieldInfo ResolveGlobalField(IField fieldRef) {
+ InitGlobalFields();
+ foreach (var globalField in globalFields) {
+ if (ResolverUtils.CompareFields(globalField, fieldRef))
+ return globalField;
+ }
+ return null;
+ }
+
+ void InitGlobalFields() {
+ if (globalFields != null)
+ return;
+ globalFields = new List();
+
+ var flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
+ foreach (var module in assembly.GetModules(true)) {
+ foreach (var method in module.GetFields(flags))
+ globalFields.Add(method);
+ }
+ }
+
+ public MethodBase Resolve(IMethod methodRef) {
+ var resolver = GetTypeResolver(methodRef.DeclaringType);
+ if (resolver != null)
+ return resolver.Resolve(methodRef);
+ return ResolveGlobalMethod(methodRef);
+ }
+
+ MethodBase ResolveGlobalMethod(IMethod methodRef) {
+ InitGlobalMethods();
+ foreach (var globalMethod in globalMethods) {
+ if (ResolverUtils.CompareMethods(globalMethod, methodRef))
+ return globalMethod;
+ }
+ return null;
+ }
+
+ void InitGlobalMethods() {
+ if (globalMethods != null)
+ return;
+ globalMethods = new List();
+
+ var flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
+ foreach (var module in assembly.GetModules(true)) {
+ foreach (var method in module.GetMethods(flags))
+ globalMethods.Add(method);
+ }
+ }
+
+ public Type Resolve(ITypeDefOrRef typeRef) {
+ var resolver = GetTypeResolver(typeRef);
+ if (resolver != null)
+ return resolver.type;
+
+ if (typeRef is TypeSpec ts && ts.TypeSig is GenericSig)
+ return typeof(MGenericParameter);
+
+ return null;
+ }
+
+ public override string ToString() => assembly.ToString();
+ }
+}
diff --git a/de4dot/AssemblyData/methodsrewriter/CodeGenerator.cs b/de4dot/AssemblyData/methodsrewriter/CodeGenerator.cs
new file mode 100644
index 0000000..a00f5c9
--- /dev/null
+++ b/de4dot/AssemblyData/methodsrewriter/CodeGenerator.cs
@@ -0,0 +1,328 @@
+/*
+ Copyright (C) 2011-2015 de4dot@gmail.com
+
+ This file is part of de4dot.
+
+ de4dot is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ de4dot is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with de4dot. If not, see .
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Reflection.Emit;
+using dnlib.DotNet.Emit;
+using dnlib.DotNet;
+
+using OpCode = dnlib.DotNet.Emit.OpCode;
+using OpCodes = dnlib.DotNet.Emit.OpCodes;
+using OperandType = dnlib.DotNet.Emit.OperandType;
+using ROpCode = System.Reflection.Emit.OpCode;
+using ROpCodes = System.Reflection.Emit.OpCodes;
+
+namespace AssemblyData.methodsrewriter {
+ class CodeGenerator {
+ static Dictionary dnlibToReflection = new Dictionary();
+ static CodeGenerator() {
+ var refDict = new Dictionary(0x100);
+ foreach (var f in typeof(ROpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) {
+ if (f.FieldType != typeof(ROpCode))
+ continue;
+ var ropcode = (ROpCode)f.GetValue(null);
+ refDict[ropcode.Value] = ropcode;
+ }
+
+ foreach (var f in typeof(OpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) {
+ if (f.FieldType != typeof(OpCode))
+ continue;
+ var opcode = (OpCode)f.GetValue(null);
+ if (!refDict.TryGetValue(opcode.Value, out var ropcode))
+ continue;
+ dnlibToReflection[opcode] = ropcode;
+ }
+ }
+
+ IMethodsRewriter methodsRewriter;
+ string methodName;
+ IList allInstructions;
+ IList allExceptionHandlers;
+ ILGenerator ilg;
+ Type methodReturnType;
+ Type[] methodParameters;
+ Type delegateType;
+ MMethod methodInfo;
+ LocalBuilder tempObjLocal;
+ LocalBuilder tempObjArrayLocal;
+ int thisArgIndex;
+ List locals;
+ List