Merge pull request #107 from mrexodia/dynamic_loading_fix
Dynamic loading fix
This commit is contained in:
commit
e0dfa64e31
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,3 +6,5 @@
|
||||||
*.suo
|
*.suo
|
||||||
/Debug/
|
/Debug/
|
||||||
/Release/
|
/Release/
|
||||||
|
/deobfuscator.*/
|
||||||
|
!/deobfuscator.Template/
|
||||||
|
|
|
@ -24,7 +24,7 @@ using System.Threading;
|
||||||
using AssemblyData;
|
using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
sealed class AssemblyClient : IAssemblyClient {
|
public sealed class AssemblyClient : IAssemblyClient {
|
||||||
const int WAIT_TIME_BEFORE_CONNECTING = 1000;
|
const int WAIT_TIME_BEFORE_CONNECTING = 1000;
|
||||||
const int MAX_CONNECT_WAIT_TIME_MS = 2000;
|
const int MAX_CONNECT_WAIT_TIME_MS = 2000;
|
||||||
IAssemblyServerLoader loader;
|
IAssemblyServerLoader loader;
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace de4dot.code.AssemblyClient {
|
||||||
this.serverVersion = ServerClrVersion.CLR_ANY_ANYCPU;
|
this.serverVersion = ServerClrVersion.CLR_ANY_ANYCPU;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal NewProcessAssemblyClientFactory(ServerClrVersion serverVersion) {
|
public NewProcessAssemblyClientFactory(ServerClrVersion serverVersion) {
|
||||||
this.serverVersion = serverVersion;
|
this.serverVersion = serverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ namespace de4dot.code.AssemblyClient {
|
||||||
return new AssemblyClient(new NewProcessAssemblyServerLoader(serviceType, serverVersion));
|
return new AssemblyClient(new NewProcessAssemblyServerLoader(serviceType, serverVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static ServerClrVersion GetServerClrVersion(ModuleDef module) {
|
public static ServerClrVersion GetServerClrVersion(ModuleDef module) {
|
||||||
switch (module.GetPointerSize()) {
|
switch (module.GetPointerSize()) {
|
||||||
default:
|
default:
|
||||||
case 4:
|
case 4:
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System;
|
||||||
using AssemblyData;
|
using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
interface IAssemblyServerLoader : IDisposable {
|
public interface IAssemblyServerLoader : IDisposable {
|
||||||
void LoadServer();
|
void LoadServer();
|
||||||
IAssemblyService CreateService();
|
IAssemblyService CreateService();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System;
|
||||||
using AssemblyData;
|
using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
enum ServerClrVersion {
|
public enum ServerClrVersion {
|
||||||
CLR_ANY_ANYCPU,
|
CLR_ANY_ANYCPU,
|
||||||
CLR_ANY_x86,
|
CLR_ANY_x86,
|
||||||
CLR_ANY_x64,
|
CLR_ANY_x64,
|
||||||
|
@ -31,7 +31,7 @@ namespace de4dot.code.AssemblyClient {
|
||||||
CLR_v40_x64,
|
CLR_v40_x64,
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IpcAssemblyServerLoader : IAssemblyServerLoader {
|
public abstract class IpcAssemblyServerLoader : IAssemblyServerLoader {
|
||||||
readonly string assemblyServerFilename;
|
readonly string assemblyServerFilename;
|
||||||
protected string ipcName;
|
protected string ipcName;
|
||||||
protected string ipcUri;
|
protected string ipcUri;
|
||||||
|
|
|
@ -23,7 +23,7 @@ using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
// Starts the server in a new app domain.
|
// Starts the server in a new app domain.
|
||||||
sealed class NewAppDomainAssemblyServerLoader : IpcAssemblyServerLoader {
|
public sealed class NewAppDomainAssemblyServerLoader : IpcAssemblyServerLoader {
|
||||||
AppDomain appDomain;
|
AppDomain appDomain;
|
||||||
Thread thread;
|
Thread thread;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
// Starts the server in a new process
|
// Starts the server in a new process
|
||||||
class NewProcessAssemblyServerLoader : IpcAssemblyServerLoader {
|
public class NewProcessAssemblyServerLoader : IpcAssemblyServerLoader {
|
||||||
Process process;
|
Process process;
|
||||||
|
|
||||||
public NewProcessAssemblyServerLoader(AssemblyServiceType serviceType)
|
public NewProcessAssemblyServerLoader(AssemblyServiceType serviceType)
|
||||||
|
|
|
@ -22,7 +22,7 @@ using AssemblyData;
|
||||||
|
|
||||||
namespace de4dot.code.AssemblyClient {
|
namespace de4dot.code.AssemblyClient {
|
||||||
// Starts the server in the current app domain.
|
// Starts the server in the current app domain.
|
||||||
class SameAppDomainAssemblyServerLoader : IAssemblyServerLoader {
|
public class SameAppDomainAssemblyServerLoader : IAssemblyServerLoader {
|
||||||
IAssemblyService service;
|
IAssemblyService service;
|
||||||
AssemblyServiceType serviceType;
|
AssemblyServiceType serviceType;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ using dnlib.DotNet.Writer;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
class AssemblyModule {
|
public class AssemblyModule {
|
||||||
string filename;
|
string filename;
|
||||||
ModuleDefMD module;
|
ModuleDefMD module;
|
||||||
ModuleContext moduleContext;
|
ModuleContext moduleContext;
|
||||||
|
|
|
@ -25,7 +25,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
class DumpedMethodsRestorer : IRowReader<RawMethodRow>, IColumnReader, IMethodDecrypter {
|
public class DumpedMethodsRestorer : IRowReader<RawMethodRow>, IColumnReader, IMethodDecrypter {
|
||||||
ModuleDefMD module;
|
ModuleDefMD module;
|
||||||
DumpedMethods dumpedMethods;
|
DumpedMethods dumpedMethods;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
|
|
||||||
namespace System.Runtime.ExceptionServices {
|
namespace System.Runtime.ExceptionServices {
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||||
class HandleProcessCorruptedStateExceptionsAttribute : Attribute {
|
public class HandleProcessCorruptedStateExceptionsAttribute : Attribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
class MethodPrinter {
|
public class MethodPrinter {
|
||||||
LoggerEvent loggerEvent;
|
LoggerEvent loggerEvent;
|
||||||
IList<Instruction> allInstructions;
|
IList<Instruction> allInstructions;
|
||||||
IList<ExceptionHandler> allExceptionHandlers;
|
IList<ExceptionHandler> allExceptionHandlers;
|
||||||
|
|
|
@ -25,7 +25,7 @@ using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
// A simple class that statically detects the values of some local variables
|
// A simple class that statically detects the values of some local variables
|
||||||
class VariableValues {
|
public class VariableValues {
|
||||||
IList<Block> allBlocks;
|
IList<Block> allBlocks;
|
||||||
IList<Local> locals;
|
IList<Local> locals;
|
||||||
Dictionary<Local, Variable> variableToValue = new Dictionary<Local, Variable>();
|
Dictionary<Local, Variable> variableToValue = new Dictionary<Local, Variable>();
|
||||||
|
@ -140,7 +140,7 @@ namespace de4dot.code {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class MethodReturnValueInliner {
|
public abstract class MethodReturnValueInliner {
|
||||||
protected List<CallResult> callResults;
|
protected List<CallResult> callResults;
|
||||||
List<Block> allBlocks;
|
List<Block> allBlocks;
|
||||||
MethodDef theMethod;
|
MethodDef theMethod;
|
||||||
|
|
|
@ -22,7 +22,7 @@ using dnlib.DotNet.MD;
|
||||||
using dnlib.DotNet.Writer;
|
using dnlib.DotNet.Writer;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
class PrintNewTokens : IModuleWriterListener {
|
public class PrintNewTokens : IModuleWriterListener {
|
||||||
readonly ModuleDef module;
|
readonly ModuleDef module;
|
||||||
readonly IModuleWriterListener otherListener;
|
readonly IModuleWriterListener otherListener;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ using de4dot.code.AssemblyClient;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
abstract class StringInlinerBase : MethodReturnValueInliner {
|
public abstract class StringInlinerBase : MethodReturnValueInliner {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
@ -62,7 +62,7 @@ namespace de4dot.code {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicStringInliner : StringInlinerBase {
|
public class DynamicStringInliner : StringInlinerBase {
|
||||||
IAssemblyClient assemblyClient;
|
IAssemblyClient assemblyClient;
|
||||||
Dictionary<int, int> methodTokenToId = new Dictionary<int, int>();
|
Dictionary<int, int> methodTokenToId = new Dictionary<int, int>();
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ namespace de4dot.code {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StaticStringInliner : StringInlinerBase {
|
public class StaticStringInliner : StringInlinerBase {
|
||||||
MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>> stringDecrypters = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>>();
|
MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>> stringDecrypters = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>>();
|
||||||
|
|
||||||
public override bool HasHandlers {
|
public override bool HasHandlers {
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace de4dot.code {
|
||||||
public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
|
public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
|
||||||
public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
|
public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
|
||||||
|
|
||||||
class Tuple<T1, T2> {
|
public class Tuple<T1, T2> {
|
||||||
public T1 Item1 { get; set; }
|
public T1 Item1 { get; set; }
|
||||||
public T2 Item2 { get; set; }
|
public T2 Item2 { get; set; }
|
||||||
public override bool Equals(object obj) {
|
public override bool Equals(object obj) {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code {
|
namespace de4dot.code {
|
||||||
static class Win32Path {
|
public static class Win32Path {
|
||||||
public static string GetFileName(string path) {
|
public static string GetFileName(string path) {
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -24,7 +24,7 @@ using de4dot.blocks;
|
||||||
using de4dot.blocks.cflow;
|
using de4dot.blocks.cflow;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
static class ArrayFinder {
|
public static class ArrayFinder {
|
||||||
public static List<byte[]> GetArrays(MethodDef method) {
|
public static List<byte[]> GetArrays(MethodDef method) {
|
||||||
return GetArrays(method, null);
|
return GetArrays(method, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class Blowfish {
|
public class Blowfish {
|
||||||
static readonly uint[] Pboxes = new uint[18] {
|
static readonly uint[] Pboxes = new uint[18] {
|
||||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||||
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
struct CRC32 {
|
public struct CRC32 {
|
||||||
static readonly uint[] table = new uint[256] {
|
static readonly uint[] table = new uint[256] {
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
||||||
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class ConstantsReader {
|
public class ConstantsReader {
|
||||||
protected IInstructions instructions;
|
protected IInstructions instructions;
|
||||||
protected IList<Local> locals;
|
protected IList<Local> locals;
|
||||||
protected Dictionary<Local, int> localsValuesInt32 = new Dictionary<Local, int>();
|
protected Dictionary<Local, int> localsValuesInt32 = new Dictionary<Local, int>();
|
||||||
|
|
|
@ -28,7 +28,7 @@ using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
static class DeobUtils {
|
public static class DeobUtils {
|
||||||
public static void DecryptAndAddResources(ModuleDef module, string encryptedName, Func<byte[]> decryptResource) {
|
public static void DecryptAndAddResources(ModuleDef module, string encryptedName, Func<byte[]> decryptResource) {
|
||||||
Logger.v("Decrypting resources, name: {0}", Utils.ToCsharpString(encryptedName));
|
Logger.v("Decrypting resources, name: {0}", Utils.ToCsharpString(encryptedName));
|
||||||
var decryptedResourceData = decryptResource();
|
var decryptedResourceData = decryptResource();
|
||||||
|
|
|
@ -27,7 +27,7 @@ using de4dot.blocks;
|
||||||
using de4dot.blocks.cflow;
|
using de4dot.blocks.cflow;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
abstract class DeobfuscatorBase : IDeobfuscator, IModuleWriterListener {
|
public abstract class DeobfuscatorBase : IDeobfuscator, IModuleWriterListener {
|
||||||
public const string DEFAULT_VALID_NAME_REGEX = @"^[a-zA-Z_<{$][a-zA-Z_0-9<>{}$.`-]*$";
|
public const string DEFAULT_VALID_NAME_REGEX = @"^[a-zA-Z_<{$][a-zA-Z_0-9<>{}$.`-]*$";
|
||||||
public const string DEFAULT_ASIAN_VALID_NAME_REGEX = @"^[\u2E80-\u9FFFa-zA-Z_<{$][\u2E80-\u9FFFa-zA-Z_0-9<>{}$.`-]*$";
|
public const string DEFAULT_ASIAN_VALID_NAME_REGEX = @"^[\u2E80-\u9FFFa-zA-Z_<{$][\u2E80-\u9FFFa-zA-Z_0-9<>{}$.`-]*$";
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
set { moduleBytes = value; }
|
set { moduleBytes = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class OptionsBase : IDeobfuscatorOptions {
|
public class OptionsBase : IDeobfuscatorOptions {
|
||||||
public bool RenameResourcesInCode { get; set; }
|
public bool RenameResourcesInCode { get; set; }
|
||||||
public NameRegexes ValidNameRegex { get; set; }
|
public NameRegexes ValidNameRegex { get; set; }
|
||||||
public bool DecryptStrings { get; set; }
|
public bool DecryptStrings { get; set; }
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class ExceptionLoggerRemover {
|
public class ExceptionLoggerRemover {
|
||||||
MethodDefAndDeclaringTypeDict<bool> exceptionLoggerMethods = new MethodDefAndDeclaringTypeDict<bool>();
|
MethodDefAndDeclaringTypeDict<bool> exceptionLoggerMethods = new MethodDefAndDeclaringTypeDict<bool>();
|
||||||
|
|
||||||
public int NumRemovedExceptionLoggers { get; set; }
|
public int NumRemovedExceptionLoggers { get; set; }
|
||||||
|
|
|
@ -26,7 +26,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class InitializedDataCreator {
|
public class InitializedDataCreator {
|
||||||
ModuleDef module;
|
ModuleDef module;
|
||||||
Dictionary<long, TypeDef> sizeToArrayType = new Dictionary<long, TypeDef>();
|
Dictionary<long, TypeDef> sizeToArrayType = new Dictionary<long, TypeDef>();
|
||||||
TypeDef ourType;
|
TypeDef ourType;
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
static class InlinedMethodsFinder {
|
public static class InlinedMethodsFinder {
|
||||||
public static List<MethodDef> Find(ModuleDef module) {
|
public static List<MethodDef> Find(ModuleDef module) {
|
||||||
// Not all garbage methods are inlined, possibly because we remove some code that calls
|
// Not all garbage methods are inlined, possibly because we remove some code that calls
|
||||||
// the garbage method before the methods inliner has a chance to inline it. Try to find
|
// the garbage method before the methods inliner has a chance to inline it. Try to find
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class MemberRefBuilder {
|
public class MemberRefBuilder {
|
||||||
ModuleDefMD module;
|
ModuleDefMD module;
|
||||||
Dictionary<TypeSig, TypeSig> createdTypes = new Dictionary<TypeSig, TypeSig>(TypeEqualityComparer.Instance);
|
Dictionary<TypeSig, TypeSig> createdTypes = new Dictionary<TypeSig, TypeSig>(TypeEqualityComparer.Instance);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.IO;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
[Serializable]
|
[Serializable]
|
||||||
class InvalidMethodBody : Exception {
|
public class InvalidMethodBody : Exception {
|
||||||
public InvalidMethodBody() {
|
public InvalidMethodBody() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,14 +32,14 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodBodyHeader {
|
public class MethodBodyHeader {
|
||||||
public ushort flags;
|
public ushort flags;
|
||||||
public ushort maxStack;
|
public ushort maxStack;
|
||||||
public uint codeSize;
|
public uint codeSize;
|
||||||
public uint localVarSigTok;
|
public uint localVarSigTok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MethodBodyParser {
|
public static class MethodBodyParser {
|
||||||
public static MethodBodyHeader ParseMethodBody(IBinaryReader reader, out byte[] code, out byte[] extraSections) {
|
public static MethodBodyHeader ParseMethodBody(IBinaryReader reader, out byte[] code, out byte[] extraSections) {
|
||||||
try {
|
try {
|
||||||
return ParseMethodBody2(reader, out code, out extraSections);
|
return ParseMethodBody2(reader, out code, out extraSections);
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class MethodCallRestorerBase {
|
public class MethodCallRestorerBase {
|
||||||
protected MemberRefBuilder builder;
|
protected MemberRefBuilder builder;
|
||||||
protected ModuleDefMD module;
|
protected ModuleDefMD module;
|
||||||
MethodDefAndDeclaringTypeDict<NewMethodInfo> oldToNewMethod = new MethodDefAndDeclaringTypeDict<NewMethodInfo>();
|
MethodDefAndDeclaringTypeDict<NewMethodInfo> oldToNewMethod = new MethodDefAndDeclaringTypeDict<NewMethodInfo>();
|
||||||
|
|
|
@ -22,7 +22,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class MethodCollection {
|
public class MethodCollection {
|
||||||
TypeDefDict<bool> types = new TypeDefDict<bool>();
|
TypeDefDict<bool> types = new TypeDefDict<bool>();
|
||||||
MethodDefAndDeclaringTypeDict<bool> methods = new MethodDefAndDeclaringTypeDict<bool>();
|
MethodDefAndDeclaringTypeDict<bool> methods = new MethodDefAndDeclaringTypeDict<bool>();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class PushedArgs {
|
public class PushedArgs {
|
||||||
List<Instruction> args;
|
List<Instruction> args;
|
||||||
int nextIndex;
|
int nextIndex;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MethodStack {
|
public static class MethodStack {
|
||||||
// May not return all args. The args are returned in reverse order.
|
// May not return all args. The args are returned in reverse order.
|
||||||
public static PushedArgs GetPushedArgInstructions(IList<Instruction> instructions, int index) {
|
public static PushedArgs GetPushedArgInstructions(IList<Instruction> instructions, int index) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -26,7 +26,7 @@ using de4dot.blocks;
|
||||||
using de4dot.mdecrypt;
|
using de4dot.mdecrypt;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
static class MethodsDecrypter {
|
public static class MethodsDecrypter {
|
||||||
public static DumpedMethods Decrypt(ModuleDef module, byte[] moduleCctorBytes) {
|
public static DumpedMethods Decrypt(ModuleDef module, byte[] moduleCctorBytes) {
|
||||||
return Decrypt(NewProcessAssemblyClientFactory.GetServerClrVersion(module), module.Location, moduleCctorBytes);
|
return Decrypt(NewProcessAssemblyClientFactory.GetServerClrVersion(module), module.Location, moduleCctorBytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ using dnlib.DotNet.MD;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
sealed class MyPEImage : IDisposable {
|
public sealed class MyPEImage : IDisposable {
|
||||||
IPEImage peImage;
|
IPEImage peImage;
|
||||||
byte[] peImageData;
|
byte[] peImageData;
|
||||||
IImageStream peStream;
|
IImageStream peStream;
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class NullStream : Stream {
|
public class NullStream : Stream {
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
long length = 0;
|
long length = 0;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
OpDecryptString DecryptStrings { get; }
|
OpDecryptString DecryptStrings { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Operations : IOperations {
|
public class Operations : IOperations {
|
||||||
public bool KeepObfuscatorTypes { get; set; }
|
public bool KeepObfuscatorTypes { get; set; }
|
||||||
public MetaDataFlags MetaDataFlags { get; set; }
|
public MetaDataFlags MetaDataFlags { get; set; }
|
||||||
public RenamerFlags RenamerFlags { get; set; }
|
public RenamerFlags RenamerFlags { get; set; }
|
||||||
|
|
|
@ -24,7 +24,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
abstract class ProxyCallFixerBase {
|
public abstract class ProxyCallFixerBase {
|
||||||
protected ModuleDefMD module;
|
protected ModuleDefMD module;
|
||||||
protected List<MethodDef> delegateCreatorMethods = new List<MethodDef>();
|
protected List<MethodDef> delegateCreatorMethods = new List<MethodDef>();
|
||||||
protected Dictionary<TypeDef, bool> delegateTypesDict = new Dictionary<TypeDef, bool>();
|
protected Dictionary<TypeDef, bool> delegateTypesDict = new Dictionary<TypeDef, bool>();
|
||||||
|
@ -187,7 +187,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
// ldsfld delegate_instance
|
// ldsfld delegate_instance
|
||||||
// ...push args...
|
// ...push args...
|
||||||
// call Invoke
|
// call Invoke
|
||||||
abstract class ProxyCallFixer1 : ProxyCallFixerBase {
|
public abstract class ProxyCallFixer1 : ProxyCallFixerBase {
|
||||||
FieldDefAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefAndDeclaringTypeDict<DelegateInfo>();
|
FieldDefAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefAndDeclaringTypeDict<DelegateInfo>();
|
||||||
|
|
||||||
protected ProxyCallFixer1(ModuleDefMD module)
|
protected ProxyCallFixer1(ModuleDefMD module)
|
||||||
|
@ -375,7 +375,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
// Invoke() on a delegate instance, eg.:
|
// Invoke() on a delegate instance, eg.:
|
||||||
// ...push args...
|
// ...push args...
|
||||||
// call static method
|
// call static method
|
||||||
abstract class ProxyCallFixer2 : ProxyCallFixerBase {
|
public abstract class ProxyCallFixer2 : ProxyCallFixerBase {
|
||||||
MethodDefAndDeclaringTypeDict<DelegateInfo> proxyMethodToDelegateInfo = new MethodDefAndDeclaringTypeDict<DelegateInfo>();
|
MethodDefAndDeclaringTypeDict<DelegateInfo> proxyMethodToDelegateInfo = new MethodDefAndDeclaringTypeDict<DelegateInfo>();
|
||||||
|
|
||||||
protected ProxyCallFixer2(ModuleDefMD module)
|
protected ProxyCallFixer2(ModuleDefMD module)
|
||||||
|
@ -497,7 +497,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
// ...push args...
|
// ...push args...
|
||||||
// ldsfld delegate instance
|
// ldsfld delegate instance
|
||||||
// call static method
|
// call static method
|
||||||
abstract class ProxyCallFixer3 : ProxyCallFixer1 {
|
public abstract class ProxyCallFixer3 : ProxyCallFixer1 {
|
||||||
protected ProxyCallFixer3(ModuleDefMD module)
|
protected ProxyCallFixer3(ModuleDefMD module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class QuickLZBase {
|
public class QuickLZBase {
|
||||||
protected static uint Read32(byte[] data, int index) {
|
protected static uint Read32(byte[] data, int index) {
|
||||||
return BitConverter.ToUInt32(data, index);
|
return BitConverter.ToUInt32(data, index);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class QuickLZ : QuickLZBase {
|
public class QuickLZ : QuickLZBase {
|
||||||
static int DEFAULT_QCLZ_SIG = 0x5A4C4351; // "QCLZ"
|
static int DEFAULT_QCLZ_SIG = 0x5A4C4351; // "QCLZ"
|
||||||
|
|
||||||
public static bool IsCompressed(byte[] data) {
|
public static bool IsCompressed(byte[] data) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
static class RandomNameChecker {
|
public static class RandomNameChecker {
|
||||||
static Regex noUpper = new Regex(@"^[^A-Z]+$");
|
static Regex noUpper = new Regex(@"^[^A-Z]+$");
|
||||||
static Regex allUpper = new Regex(@"^[A-Z]+$");
|
static Regex allUpper = new Regex(@"^[A-Z]+$");
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet;
|
||||||
using dnlib.DotNet.Emit;
|
using dnlib.DotNet.Emit;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class StringCounts {
|
public class StringCounts {
|
||||||
Dictionary<string, int> strings = new Dictionary<string, int>(StringComparer.Ordinal);
|
Dictionary<string, int> strings = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public IEnumerable<string> Strings {
|
public IEnumerable<string> Strings {
|
||||||
|
@ -65,7 +65,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FieldTypes : StringCounts {
|
public class FieldTypes : StringCounts {
|
||||||
public FieldTypes(TypeDef type) {
|
public FieldTypes(TypeDef type) {
|
||||||
Initialize(type.Fields);
|
Initialize(type.Fields);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalTypes : StringCounts {
|
public class LocalTypes : StringCounts {
|
||||||
public LocalTypes(MethodDef method) {
|
public LocalTypes(MethodDef method) {
|
||||||
if (method != null && method.Body != null)
|
if (method != null && method.Body != null)
|
||||||
Initialize(method.Body.Variables);
|
Initialize(method.Body.Variables);
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
// Restore the type of all fields / parameters that have had their type turned into object.
|
// Restore the type of all fields / parameters that have had their type turned into object.
|
||||||
// This thing requires a lot more code than I have time to do now (similar to symbol renaming)
|
// This thing requires a lot more code than I have time to do now (similar to symbol renaming)
|
||||||
// so it will be a basic implementation only.
|
// so it will be a basic implementation only.
|
||||||
abstract class TypesRestorerBase {
|
public abstract class TypesRestorerBase {
|
||||||
ModuleDef module;
|
ModuleDef module;
|
||||||
List<MethodDef> allMethods;
|
List<MethodDef> allMethods;
|
||||||
Dictionary<Parameter, TypeInfo<Parameter>> argInfos = new Dictionary<Parameter, TypeInfo<Parameter>>();
|
Dictionary<Parameter, TypeInfo<Parameter>> argInfos = new Dictionary<Parameter, TypeInfo<Parameter>>();
|
||||||
|
@ -639,7 +639,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypesRestorer : TypesRestorerBase {
|
public class TypesRestorer : TypesRestorerBase {
|
||||||
public TypesRestorer(ModuleDef module)
|
public TypesRestorer(ModuleDef module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class UnpackedFile {
|
public class UnpackedFile {
|
||||||
public string filename;
|
public string filename;
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
class UnusedMethodsFinder {
|
public class UnusedMethodsFinder {
|
||||||
ModuleDef module;
|
ModuleDef module;
|
||||||
MethodCollection removedMethods;
|
MethodCollection removedMethods;
|
||||||
Dictionary<MethodDef, bool> possiblyUnusedMethods = new Dictionary<MethodDef, bool>();
|
Dictionary<MethodDef, bool> possiblyUnusedMethods = new Dictionary<MethodDef, bool>();
|
||||||
|
|
|
@ -24,7 +24,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
abstract class ValueInlinerBase<TValue> : MethodReturnValueInliner {
|
public abstract class ValueInlinerBase<TValue> : MethodReturnValueInliner {
|
||||||
MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>> decrypterMethods = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>>();
|
MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>> decrypterMethods = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>>();
|
||||||
bool removeUnbox = false;
|
bool removeUnbox = false;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BooleanValueInliner : ValueInlinerBase<bool> {
|
public class BooleanValueInliner : ValueInlinerBase<bool> {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
@ -104,7 +104,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32ValueInliner : ValueInlinerBase<int> {
|
public class Int32ValueInliner : ValueInlinerBase<int> {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
@ -117,7 +117,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64ValueInliner : ValueInlinerBase<long> {
|
public class Int64ValueInliner : ValueInlinerBase<long> {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
@ -130,7 +130,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SingleValueInliner : ValueInlinerBase<float> {
|
public class SingleValueInliner : ValueInlinerBase<float> {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
@ -143,7 +143,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DoubleValueInliner : ValueInlinerBase<double> {
|
public class DoubleValueInliner : ValueInlinerBase<double> {
|
||||||
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
protected override void InlineReturnValues(IList<CallResult> callResults) {
|
||||||
foreach (var callResult in callResults) {
|
foreach (var callResult in callResults) {
|
||||||
var block = callResult.block;
|
var block = callResult.block;
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
using de4dot.code.renamer.asmmodules;
|
using de4dot.code.renamer.asmmodules;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class DerivedFrom {
|
public class DerivedFrom {
|
||||||
Dictionary<string, bool> classNames = new Dictionary<string, bool>(StringComparer.Ordinal);
|
Dictionary<string, bool> classNames = new Dictionary<string, bool>(StringComparer.Ordinal);
|
||||||
Dictionary<MTypeDef, bool> results = new Dictionary<MTypeDef, bool>();
|
Dictionary<MTypeDef, bool> results = new Dictionary<MTypeDef, bool>();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class ExistingNames {
|
public class ExistingNames {
|
||||||
Dictionary<string, bool> allNames = new Dictionary<string, bool>(StringComparer.Ordinal);
|
Dictionary<string, bool> allNames = new Dictionary<string, bool>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public void Add(string name) {
|
public void Add(string name) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||||
using de4dot.code.renamer.asmmodules;
|
using de4dot.code.renamer.asmmodules;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class MemberInfo {
|
public class MemberInfo {
|
||||||
protected Ref memberRef;
|
protected Ref memberRef;
|
||||||
public string oldFullName;
|
public string oldFullName;
|
||||||
public string oldName;
|
public string oldName;
|
||||||
|
@ -50,31 +50,31 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GenericParamInfo : MemberInfo {
|
public class GenericParamInfo : MemberInfo {
|
||||||
public GenericParamInfo(MGenericParamDef genericParamDef)
|
public GenericParamInfo(MGenericParamDef genericParamDef)
|
||||||
: base(genericParamDef) {
|
: base(genericParamDef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyInfo : MemberInfo {
|
public class PropertyInfo : MemberInfo {
|
||||||
public PropertyInfo(MPropertyDef propertyDef)
|
public PropertyInfo(MPropertyDef propertyDef)
|
||||||
: base(propertyDef) {
|
: base(propertyDef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventInfo : MemberInfo {
|
public class EventInfo : MemberInfo {
|
||||||
public EventInfo(MEventDef eventDef)
|
public EventInfo(MEventDef eventDef)
|
||||||
: base(eventDef) {
|
: base(eventDef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FieldInfo : MemberInfo {
|
public class FieldInfo : MemberInfo {
|
||||||
public FieldInfo(MFieldDef fieldDef)
|
public FieldInfo(MFieldDef fieldDef)
|
||||||
: base(fieldDef) {
|
: base(fieldDef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodInfo : MemberInfo {
|
public class MethodInfo : MemberInfo {
|
||||||
public MMethodDef MethodDef {
|
public MMethodDef MethodDef {
|
||||||
get { return (MMethodDef)memberRef; }
|
get { return (MMethodDef)memberRef; }
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ParamInfo {
|
public class ParamInfo {
|
||||||
MParamDef paramDef;
|
MParamDef paramDef;
|
||||||
public string oldName;
|
public string oldName;
|
||||||
public string newName;
|
public string newName;
|
||||||
|
@ -100,7 +100,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MemberInfos {
|
public class MemberInfos {
|
||||||
Dictionary<MTypeDef, TypeInfo> allTypeInfos = new Dictionary<MTypeDef, TypeInfo>();
|
Dictionary<MTypeDef, TypeInfo> allTypeInfos = new Dictionary<MTypeDef, TypeInfo>();
|
||||||
Dictionary<MPropertyDef, PropertyInfo> allPropertyInfos = new Dictionary<MPropertyDef, PropertyInfo>();
|
Dictionary<MPropertyDef, PropertyInfo> allPropertyInfos = new Dictionary<MPropertyDef, PropertyInfo>();
|
||||||
Dictionary<MEventDef, EventInfo> allEventInfos = new Dictionary<MEventDef, EventInfo>();
|
Dictionary<MEventDef, EventInfo> allEventInfos = new Dictionary<MEventDef, EventInfo>();
|
||||||
|
|
|
@ -22,11 +22,11 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
interface INameCreator {
|
public interface INameCreator {
|
||||||
string Create();
|
string Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
class OneNameCreator : INameCreator {
|
public class OneNameCreator : INameCreator {
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
public OneNameCreator(string name) {
|
public OneNameCreator(string name) {
|
||||||
|
@ -38,7 +38,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class NameCreatorCounter : INameCreator {
|
public abstract class NameCreatorCounter : INameCreator {
|
||||||
protected int num;
|
protected int num;
|
||||||
|
|
||||||
public abstract string Create();
|
public abstract string Create();
|
||||||
|
@ -50,7 +50,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GenericParamNameCreator : NameCreatorCounter {
|
public class GenericParamNameCreator : NameCreatorCounter {
|
||||||
static string[] names = new string[] { "T", "U", "V", "W", "X", "Y", "Z" };
|
static string[] names = new string[] { "T", "U", "V", "W", "X", "Y", "Z" };
|
||||||
|
|
||||||
public override string Create() {
|
public override string Create() {
|
||||||
|
@ -60,7 +60,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NameCreator : NameCreatorCounter {
|
public class NameCreator : NameCreatorCounter {
|
||||||
string prefix;
|
string prefix;
|
||||||
|
|
||||||
public NameCreator(string prefix)
|
public NameCreator(string prefix)
|
||||||
|
@ -82,7 +82,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like NameCreator but don't add the counter the first time
|
// Like NameCreator but don't add the counter the first time
|
||||||
class NameCreator2 : NameCreatorCounter {
|
public class NameCreator2 : NameCreatorCounter {
|
||||||
string prefix;
|
string prefix;
|
||||||
const string separator = "_";
|
const string separator = "_";
|
||||||
|
|
||||||
|
@ -106,11 +106,11 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ITypeNameCreator {
|
public interface ITypeNameCreator {
|
||||||
string Create(TypeDef typeDef, string newBaseTypeName);
|
string Create(TypeDef typeDef, string newBaseTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
class NameInfos {
|
public class NameInfos {
|
||||||
IList<NameInfo> nameInfos = new List<NameInfo>();
|
IList<NameInfo> nameInfos = new List<NameInfo>();
|
||||||
|
|
||||||
class NameInfo {
|
class NameInfo {
|
||||||
|
@ -136,7 +136,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeNameCreator : ITypeNameCreator {
|
public class TypeNameCreator : ITypeNameCreator {
|
||||||
ExistingNames existingNames;
|
ExistingNames existingNames;
|
||||||
NameCreator createUnknownTypeName;
|
NameCreator createUnknownTypeName;
|
||||||
NameCreator createEnumName;
|
NameCreator createEnumName;
|
||||||
|
@ -205,7 +205,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GlobalTypeNameCreator : TypeNameCreator {
|
public class GlobalTypeNameCreator : TypeNameCreator {
|
||||||
public GlobalTypeNameCreator(ExistingNames existingNames)
|
public GlobalTypeNameCreator(ExistingNames existingNames)
|
||||||
: base(existingNames) {
|
: base(existingNames) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ using de4dot.blocks;
|
||||||
using de4dot.code.resources;
|
using de4dot.code.resources;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class ResourceKeysRenamer {
|
public class ResourceKeysRenamer {
|
||||||
const int RESOURCE_KEY_MAX_LEN = 50;
|
const int RESOURCE_KEY_MAX_LEN = 50;
|
||||||
const string DEFAULT_KEY_NAME = "Key";
|
const string DEFAULT_KEY_NAME = "Key";
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ using de4dot.blocks;
|
||||||
using de4dot.code.renamer.asmmodules;
|
using de4dot.code.renamer.asmmodules;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class ResourceRenamer {
|
public class ResourceRenamer {
|
||||||
Module module;
|
Module module;
|
||||||
Dictionary<string, Resource> nameToResource;
|
Dictionary<string, Resource> nameToResource;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ using de4dot.code.renamer.asmmodules;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class TypeInfo : MemberInfo {
|
public class TypeInfo : MemberInfo {
|
||||||
public string oldNamespace;
|
public string oldNamespace;
|
||||||
public string newNamespace;
|
public string newNamespace;
|
||||||
public VariableNameState variableNameState = VariableNameState.Create();
|
public VariableNameState variableNameState = VariableNameState.Create();
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
abstract class TypeNames {
|
public abstract class TypeNames {
|
||||||
protected Dictionary<string, NameCreator> typeNames = new Dictionary<string, NameCreator>(StringComparer.Ordinal);
|
protected Dictionary<string, NameCreator> typeNames = new Dictionary<string, NameCreator>(StringComparer.Ordinal);
|
||||||
protected NameCreator genericParamNameCreator = new NameCreator("gparam_");
|
protected NameCreator genericParamNameCreator = new NameCreator("gparam_");
|
||||||
protected NameCreator fnPtrNameCreator = new NameCreator("fnptr_");
|
protected NameCreator fnPtrNameCreator = new NameCreator("fnptr_");
|
||||||
|
@ -135,7 +135,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VariableNameCreator : TypeNames {
|
public class VariableNameCreator : TypeNames {
|
||||||
static Dictionary<string, string> ourFullNameToShortName;
|
static Dictionary<string, string> ourFullNameToShortName;
|
||||||
static Dictionary<string, string> ourFullNameToShortNamePrefix;
|
static Dictionary<string, string> ourFullNameToShortNamePrefix;
|
||||||
static VariableNameCreator() {
|
static VariableNameCreator() {
|
||||||
|
@ -201,7 +201,7 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyNameCreator : TypeNames {
|
public class PropertyNameCreator : TypeNames {
|
||||||
static Dictionary<string, string> ourFullNameToShortName = new Dictionary<string, string>(StringComparer.Ordinal);
|
static Dictionary<string, string> ourFullNameToShortName = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
static Dictionary<string, string> ourFullNameToShortNamePrefix = new Dictionary<string, string>(StringComparer.Ordinal);
|
static Dictionary<string, string> ourFullNameToShortNamePrefix = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class TypeRenamerState {
|
public class TypeRenamerState {
|
||||||
ExistingNames existingNames;
|
ExistingNames existingNames;
|
||||||
Dictionary<string, string> namespaceToNewName;
|
Dictionary<string, string> namespaceToNewName;
|
||||||
NameCreator createNamespaceName;
|
NameCreator createNamespaceName;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class VariableNameState {
|
public class VariableNameState {
|
||||||
ExistingNames existingVariableNames;
|
ExistingNames existingVariableNames;
|
||||||
ExistingNames existingMethodNames;
|
ExistingNames existingMethodNames;
|
||||||
ExistingNames existingPropertyNames;
|
ExistingNames existingPropertyNames;
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MEventDef : Ref {
|
public class MEventDef : Ref {
|
||||||
public MMethodDef AddMethod { get; set; }
|
public MMethodDef AddMethod { get; set; }
|
||||||
public MMethodDef RemoveMethod { get; set; }
|
public MMethodDef RemoveMethod { get; set; }
|
||||||
public MMethodDef RaiseMethod { get; set; }
|
public MMethodDef RaiseMethod { get; set; }
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MFieldDef : Ref {
|
public class MFieldDef : Ref {
|
||||||
public FieldDef FieldDef {
|
public FieldDef FieldDef {
|
||||||
get { return (FieldDef)memberRef; }
|
get { return (FieldDef)memberRef; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MGenericParamDef : Ref {
|
public class MGenericParamDef : Ref
|
||||||
|
{
|
||||||
public GenericParam GenericParam {
|
public GenericParam GenericParam {
|
||||||
get { return (GenericParam)memberRef; }
|
get { return (GenericParam)memberRef; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
interface IResolver {
|
public interface IResolver {
|
||||||
MTypeDef ResolveType(ITypeDefOrRef typeRef);
|
MTypeDef ResolveType(ITypeDefOrRef typeRef);
|
||||||
MMethodDef ResolveMethod(IMethodDefOrRef methodRef);
|
MMethodDef ResolveMethod(IMethodDefOrRef methodRef);
|
||||||
MFieldDef ResolveField(MemberRef fieldRef);
|
MFieldDef ResolveField(MemberRef fieldRef);
|
||||||
|
|
|
@ -24,7 +24,7 @@ using dnlib.DotNet.Emit;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
enum ObjectType {
|
public enum ObjectType {
|
||||||
Unknown,
|
Unknown,
|
||||||
EventDef,
|
EventDef,
|
||||||
FieldDef,
|
FieldDef,
|
||||||
|
@ -40,7 +40,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
ExportedType,
|
ExportedType,
|
||||||
}
|
}
|
||||||
|
|
||||||
class MemberRefFinder {
|
public class MemberRefFinder {
|
||||||
public Dictionary<CustomAttribute, bool> customAttributes = new Dictionary<CustomAttribute, bool>();
|
public Dictionary<CustomAttribute, bool> customAttributes = new Dictionary<CustomAttribute, bool>();
|
||||||
public Dictionary<EventDef, bool> eventDefs = new Dictionary<EventDef, bool>();
|
public Dictionary<EventDef, bool> eventDefs = new Dictionary<EventDef, bool>();
|
||||||
public Dictionary<FieldDef, bool> fieldDefs = new Dictionary<FieldDef, bool>();
|
public Dictionary<FieldDef, bool> fieldDefs = new Dictionary<FieldDef, bool>();
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MMethodDef : Ref {
|
public class MMethodDef : Ref {
|
||||||
IList<MGenericParamDef> genericParams;
|
IList<MGenericParamDef> genericParams;
|
||||||
IList<MParamDef> paramDefs = new List<MParamDef>();
|
IList<MParamDef> paramDefs = new List<MParamDef>();
|
||||||
MParamDef returnParamDef;
|
MParamDef returnParamDef;
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MethodNameGroup {
|
public class MethodNameGroup {
|
||||||
List<MMethodDef> methods = new List<MMethodDef>();
|
List<MMethodDef> methods = new List<MMethodDef>();
|
||||||
|
|
||||||
public List<MMethodDef> Methods {
|
public List<MMethodDef> Methods {
|
||||||
|
@ -101,7 +101,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodNameGroups {
|
public class MethodNameGroups {
|
||||||
Dictionary<MMethodDef, MethodNameGroup> methodGroups = new Dictionary<MMethodDef, MethodNameGroup>();
|
Dictionary<MMethodDef, MethodNameGroup> methodGroups = new Dictionary<MMethodDef, MethodNameGroup>();
|
||||||
|
|
||||||
public void Same(MMethodDef a, MMethodDef b) {
|
public void Same(MMethodDef a, MMethodDef b) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class Module : IResolver {
|
public class Module : IResolver {
|
||||||
IObfuscatedFile obfuscatedFile;
|
IObfuscatedFile obfuscatedFile;
|
||||||
TypeDefDict types = new TypeDefDict();
|
TypeDefDict types = new TypeDefDict();
|
||||||
MemberRefFinder memberRefFinder;
|
MemberRefFinder memberRefFinder;
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class Modules : IResolver {
|
public class Modules : IResolver {
|
||||||
bool initializeCalled = false;
|
bool initializeCalled = false;
|
||||||
IDeobfuscatorContext deobfuscatorContext;
|
IDeobfuscatorContext deobfuscatorContext;
|
||||||
List<Module> modules = new List<Module>();
|
List<Module> modules = new List<Module>();
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MParamDef {
|
public class MParamDef {
|
||||||
public Parameter ParameterDef { get; set; }
|
public Parameter ParameterDef { get; set; }
|
||||||
public int Index { get; private set; }
|
public int Index { get; private set; }
|
||||||
public bool IsReturnParameter {
|
public bool IsReturnParameter {
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class MPropertyDef : Ref {
|
public class MPropertyDef : Ref {
|
||||||
public MMethodDef GetMethod { get; set; }
|
public MMethodDef GetMethod { get; set; }
|
||||||
public MMethodDef SetMethod { get; set; }
|
public MMethodDef SetMethod { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
abstract class Ref {
|
public abstract class Ref {
|
||||||
public readonly IMemberRef memberRef;
|
public readonly IMemberRef memberRef;
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public MTypeDef Owner { get; set; }
|
public MTypeDef Owner { get; set; }
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
static class DictHelper {
|
public static class DictHelper {
|
||||||
public static IEnumerable<T> GetSorted<T>(IEnumerable<T> values) where T : Ref {
|
public static IEnumerable<T> GetSorted<T>(IEnumerable<T> values) where T : Ref {
|
||||||
var list = new List<T>(values);
|
var list = new List<T>(values);
|
||||||
list.Sort((a, b) => a.Index.CompareTo(b.Index));
|
list.Sort((a, b) => a.Index.CompareTo(b.Index));
|
||||||
|
@ -29,7 +29,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeDefDict : TypeDefDict<MTypeDef> {
|
public class TypeDefDict : TypeDefDict<MTypeDef> {
|
||||||
public IEnumerable<MTypeDef> GetSorted() {
|
public IEnumerable<MTypeDef> GetSorted() {
|
||||||
return DictHelper.GetSorted(GetValues());
|
return DictHelper.GetSorted(GetValues());
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FieldDefDict : FieldDefDict<MFieldDef> {
|
public class FieldDefDict : FieldDefDict<MFieldDef> {
|
||||||
public IEnumerable<MFieldDef> GetSorted() {
|
public IEnumerable<MFieldDef> GetSorted() {
|
||||||
return DictHelper.GetSorted(GetValues());
|
return DictHelper.GetSorted(GetValues());
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodDefDict : MethodDefDict<MMethodDef> {
|
public class MethodDefDict : MethodDefDict<MMethodDef> {
|
||||||
public IEnumerable<MMethodDef> GetSorted() {
|
public IEnumerable<MMethodDef> GetSorted() {
|
||||||
return DictHelper.GetSorted(GetValues());
|
return DictHelper.GetSorted(GetValues());
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyDefDict : PropertyDefDict<MPropertyDef> {
|
public class PropertyDefDict : PropertyDefDict<MPropertyDef> {
|
||||||
public IEnumerable<MPropertyDef> GetSorted() {
|
public IEnumerable<MPropertyDef> GetSorted() {
|
||||||
return DictHelper.GetSorted(GetValues());
|
return DictHelper.GetSorted(GetValues());
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventDefDict : EventDefDict<MEventDef> {
|
public class EventDefDict : EventDefDict<MEventDef> {
|
||||||
public IEnumerable<MEventDef> GetSorted() {
|
public IEnumerable<MEventDef> GetSorted() {
|
||||||
return DictHelper.GetSorted(GetValues());
|
return DictHelper.GetSorted(GetValues());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer.asmmodules {
|
namespace de4dot.code.renamer.asmmodules {
|
||||||
class TypeInfo {
|
public class TypeInfo {
|
||||||
public ITypeDefOrRef typeRef;
|
public ITypeDefOrRef typeRef;
|
||||||
public MTypeDef typeDef;
|
public MTypeDef typeDef;
|
||||||
public TypeInfo(ITypeDefOrRef typeRef, MTypeDef typeDef) {
|
public TypeInfo(ITypeDefOrRef typeRef, MTypeDef typeDef) {
|
||||||
|
@ -54,7 +54,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodDefKey {
|
public class MethodDefKey {
|
||||||
public readonly MMethodDef methodDef;
|
public readonly MMethodDef methodDef;
|
||||||
|
|
||||||
public MethodDefKey(MMethodDef methodDef) {
|
public MethodDefKey(MMethodDef methodDef) {
|
||||||
|
@ -73,7 +73,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodInst {
|
public class MethodInst {
|
||||||
public MMethodDef origMethodDef;
|
public MMethodDef origMethodDef;
|
||||||
public IMethodDefOrRef methodRef;
|
public IMethodDefOrRef methodRef;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MethodInstances {
|
public class MethodInstances {
|
||||||
Dictionary<IMethodDefOrRef, List<MethodInst>> methodInstances = new Dictionary<IMethodDefOrRef, List<MethodInst>>(MethodEqualityComparer.DontCompareDeclaringTypes);
|
Dictionary<IMethodDefOrRef, List<MethodInst>> methodInstances = new Dictionary<IMethodDefOrRef, List<MethodInst>>(MethodEqualityComparer.DontCompareDeclaringTypes);
|
||||||
|
|
||||||
public void InitializeFrom(MethodInstances other, GenericInstSig git) {
|
public void InitializeFrom(MethodInstances other, GenericInstSig git) {
|
||||||
|
@ -119,7 +119,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keeps track of which methods of an interface that have been implemented
|
// Keeps track of which methods of an interface that have been implemented
|
||||||
class InterfaceMethodInfo {
|
public class InterfaceMethodInfo {
|
||||||
TypeInfo iface;
|
TypeInfo iface;
|
||||||
Dictionary<MethodDefKey, MMethodDef> ifaceMethodToClassMethod = new Dictionary<MethodDefKey, MMethodDef>();
|
Dictionary<MethodDefKey, MMethodDef> ifaceMethodToClassMethod = new Dictionary<MethodDefKey, MMethodDef>();
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InterfaceMethodInfos {
|
public class InterfaceMethodInfos {
|
||||||
Dictionary<ITypeDefOrRef, InterfaceMethodInfo> interfaceMethods = new Dictionary<ITypeDefOrRef, InterfaceMethodInfo>(TypeEqualityComparer.Instance);
|
Dictionary<ITypeDefOrRef, InterfaceMethodInfo> interfaceMethods = new Dictionary<ITypeDefOrRef, InterfaceMethodInfo>(TypeEqualityComparer.Instance);
|
||||||
|
|
||||||
public IEnumerable<InterfaceMethodInfo> AllInfos {
|
public IEnumerable<InterfaceMethodInfo> AllInfos {
|
||||||
|
@ -223,7 +223,7 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MTypeDef : Ref {
|
public class MTypeDef : Ref {
|
||||||
EventDefDict events = new EventDefDict();
|
EventDefDict events = new EventDefDict();
|
||||||
FieldDefDict fields = new FieldDefDict();
|
FieldDefDict fields = new FieldDefDict();
|
||||||
MethodDefDict methods = new MethodDefDict();
|
MethodDefDict methods = new MethodDefDict();
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.IO;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class BuiltInResourceData : IResourceData {
|
public class BuiltInResourceData : IResourceData {
|
||||||
readonly ResourceTypeCode code;
|
readonly ResourceTypeCode code;
|
||||||
readonly object data;
|
readonly object data;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System.IO;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
interface IResourceData {
|
public interface IResourceData {
|
||||||
ResourceTypeCode Code { get; }
|
ResourceTypeCode Code { get; }
|
||||||
void WriteData(BinaryWriter writer, IFormatter formatter);
|
void WriteData(BinaryWriter writer, IFormatter formatter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class ResourceDataCreator {
|
public class ResourceDataCreator {
|
||||||
readonly ModuleDef module;
|
readonly ModuleDef module;
|
||||||
readonly ModuleDefMD moduleMD;
|
readonly ModuleDefMD moduleMD;
|
||||||
readonly Dictionary<string, UserResourceType> dict = new Dictionary<string, UserResourceType>(StringComparer.Ordinal);
|
readonly Dictionary<string, UserResourceType> dict = new Dictionary<string, UserResourceType>(StringComparer.Ordinal);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class ResourceElement {
|
public class ResourceElement {
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public IResourceData ResourceData { get; set; }
|
public IResourceData ResourceData { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class ResourceElementSet {
|
public class ResourceElementSet {
|
||||||
Dictionary<string, ResourceElement> dict = new Dictionary<string, ResourceElement>(StringComparer.Ordinal);
|
Dictionary<string, ResourceElement> dict = new Dictionary<string, ResourceElement>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public int Count {
|
public int Count {
|
||||||
|
|
|
@ -27,13 +27,13 @@ using dnlib.IO;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
[Serializable]
|
[Serializable]
|
||||||
class ResourceReaderException : Exception {
|
public class ResourceReaderException : Exception {
|
||||||
public ResourceReaderException(string msg)
|
public ResourceReaderException(string msg)
|
||||||
: base(msg) {
|
: base(msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResourceReader {
|
public struct ResourceReader {
|
||||||
IBinaryReader reader;
|
IBinaryReader reader;
|
||||||
ResourceDataCreator resourceDataCreator;
|
ResourceDataCreator resourceDataCreator;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
enum ResourceTypeCode {
|
public enum ResourceTypeCode {
|
||||||
Null,
|
Null,
|
||||||
String,
|
String,
|
||||||
Boolean,
|
Boolean,
|
||||||
|
|
|
@ -26,7 +26,7 @@ using System.Text;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class ResourceWriter {
|
public class ResourceWriter {
|
||||||
ModuleDefMD module;
|
ModuleDefMD module;
|
||||||
BinaryWriter writer;
|
BinaryWriter writer;
|
||||||
ResourceElementSet resources;
|
ResourceElementSet resources;
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.IO;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
abstract class UserResourceData : IResourceData {
|
public abstract class UserResourceData : IResourceData {
|
||||||
readonly UserResourceType type;
|
readonly UserResourceType type;
|
||||||
|
|
||||||
public string TypeName {
|
public string TypeName {
|
||||||
|
@ -40,7 +40,7 @@ namespace de4dot.code.resources {
|
||||||
public abstract void WriteData(BinaryWriter writer, IFormatter formatter);
|
public abstract void WriteData(BinaryWriter writer, IFormatter formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CharArrayResourceData : UserResourceData {
|
public class CharArrayResourceData : UserResourceData {
|
||||||
public static readonly string ReflectionTypeName = "System.Char[],mscorlib";
|
public static readonly string ReflectionTypeName = "System.Char[],mscorlib";
|
||||||
char[] data;
|
char[] data;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IconResourceData : UserResourceData {
|
public class IconResourceData : UserResourceData {
|
||||||
public static readonly string ReflectionTypeName = "System.Drawing.Icon,System.Drawing";
|
public static readonly string ReflectionTypeName = "System.Drawing.Icon,System.Drawing";
|
||||||
Icon icon;
|
Icon icon;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImageResourceData : UserResourceData {
|
public class ImageResourceData : UserResourceData {
|
||||||
public static readonly string ReflectionTypeName = "System.Drawing.Bitmap,System.Drawing";
|
public static readonly string ReflectionTypeName = "System.Drawing.Bitmap,System.Drawing";
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BinaryResourceData : UserResourceData {
|
public class BinaryResourceData : UserResourceData {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
|
||||||
public BinaryResourceData(UserResourceType type, byte[] data)
|
public BinaryResourceData(UserResourceType type, byte[] data)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class UserResourceType {
|
public class UserResourceType {
|
||||||
readonly string name;
|
readonly string name;
|
||||||
readonly ResourceTypeCode code;
|
readonly ResourceTypeCode code;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ using System.Text;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using de4dot.code;
|
using de4dot.code;
|
||||||
using de4dot.code.deobfuscators;
|
using de4dot.code.deobfuscators;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace de4dot.cui {
|
namespace de4dot.cui {
|
||||||
class ExitException : Exception {
|
class ExitException : Exception {
|
||||||
|
@ -35,8 +37,35 @@ namespace de4dot.cui {
|
||||||
class Program {
|
class Program {
|
||||||
static IList<IDeobfuscatorInfo> deobfuscatorInfos = CreateDeobfuscatorInfos();
|
static IList<IDeobfuscatorInfo> deobfuscatorInfos = CreateDeobfuscatorInfos();
|
||||||
|
|
||||||
|
static IList<IDeobfuscatorInfo> LoadPlugin(string assembly) {
|
||||||
|
var plugins = new List<IDeobfuscatorInfo>();
|
||||||
|
try {
|
||||||
|
foreach (Type item in Assembly.LoadFile(assembly).GetTypes()) {
|
||||||
|
var interfaces = new List<Type>(item.GetInterfaces());
|
||||||
|
if (item.IsClass && interfaces.Contains(typeof(IDeobfuscatorInfo)))
|
||||||
|
plugins.Add((IDeobfuscatorInfo)Activator.CreateInstance(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetPlugins(string directory, ref Dictionary<string, IDeobfuscatorInfo> result) {
|
||||||
|
var plugins = new List<IDeobfuscatorInfo>();
|
||||||
|
try {
|
||||||
|
var files = Directory.GetFiles(directory, "deobfuscator.*.dll", SearchOption.TopDirectoryOnly);
|
||||||
|
foreach (var file in files)
|
||||||
|
plugins.AddRange(LoadPlugin(Path.GetFullPath(file)));
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
foreach(var p in plugins)
|
||||||
|
result[p.Type] = p;
|
||||||
|
}
|
||||||
|
|
||||||
static IList<IDeobfuscatorInfo> CreateDeobfuscatorInfos() {
|
static IList<IDeobfuscatorInfo> CreateDeobfuscatorInfos() {
|
||||||
return new List<IDeobfuscatorInfo> {
|
var local = new List<IDeobfuscatorInfo> {
|
||||||
new de4dot.code.deobfuscators.Unknown.DeobfuscatorInfo(),
|
new de4dot.code.deobfuscators.Unknown.DeobfuscatorInfo(),
|
||||||
new de4dot.code.deobfuscators.Agile_NET.DeobfuscatorInfo(),
|
new de4dot.code.deobfuscators.Agile_NET.DeobfuscatorInfo(),
|
||||||
new de4dot.code.deobfuscators.Babel_NET.DeobfuscatorInfo(),
|
new de4dot.code.deobfuscators.Babel_NET.DeobfuscatorInfo(),
|
||||||
|
@ -59,6 +88,12 @@ namespace de4dot.cui {
|
||||||
new de4dot.code.deobfuscators.Spices_Net.DeobfuscatorInfo(),
|
new de4dot.code.deobfuscators.Spices_Net.DeobfuscatorInfo(),
|
||||||
new de4dot.code.deobfuscators.Xenocode.DeobfuscatorInfo(),
|
new de4dot.code.deobfuscators.Xenocode.DeobfuscatorInfo(),
|
||||||
};
|
};
|
||||||
|
var dict = new Dictionary<string, IDeobfuscatorInfo>();
|
||||||
|
foreach (var d in local)
|
||||||
|
dict[d.Type] = d;
|
||||||
|
string pluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");
|
||||||
|
GetPlugins(pluginDir, ref dict);
|
||||||
|
return new List<IDeobfuscatorInfo>(dict.Values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Main(string[] args) {
|
public static int Main(string[] args) {
|
||||||
|
@ -74,6 +109,7 @@ namespace de4dot.cui {
|
||||||
Logger.n("");
|
Logger.n("");
|
||||||
Logger.n("de4dot v{0} Copyright (C) 2011-2014 de4dot@gmail.com", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
|
Logger.n("de4dot v{0} Copyright (C) 2011-2014 de4dot@gmail.com", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
|
||||||
Logger.n("Latest version and source code: https://github.com/0xd4d/de4dot");
|
Logger.n("Latest version and source code: https://github.com/0xd4d/de4dot");
|
||||||
|
Logger.n("{0} deobfuscator modules loaded!", deobfuscatorInfos.Count);
|
||||||
Logger.n("");
|
Logger.n("");
|
||||||
|
|
||||||
var options = new FilesDeobfuscator.Options();
|
var options = new FilesDeobfuscator.Options();
|
||||||
|
|
33
deobfuscator.Template/Properties/AssemblyInfo.cs
Normal file
33
deobfuscator.Template/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("deobfuscator.Template")]
|
||||||
|
[assembly: AssemblyDescription("de4dot Deobfuscator Template Module")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("deobfuscator.Template")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright (C) 2011-2014 de4dot@gmail.com")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
72
deobfuscator.Template/deobfuscator.Template.csproj
Normal file
72
deobfuscator.Template/deobfuscator.Template.csproj
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.30703</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{88AC39C0-4CCF-44C4-9C24-301459E6C0D1}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>deobfuscator.Template</RootNamespace>
|
||||||
|
<AssemblyName>deobfuscator.Template</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\Debug\bin\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>..\Release\bin\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AssemblyData\AssemblyData.csproj">
|
||||||
|
<Project>{FBD84077-9D35-41FE-89DF-8D79EFE0B595}</Project>
|
||||||
|
<Name>AssemblyData</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\de4dot.blocks\de4dot.blocks.csproj">
|
||||||
|
<Project>{045B96F2-AF80-4C4C-8D27-E38635AC705E}</Project>
|
||||||
|
<Name>de4dot.blocks</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\de4dot.code\de4dot.code.csproj">
|
||||||
|
<Project>{4D10B9EB-3BF1-4D61-A389-CB019E8C9622}</Project>
|
||||||
|
<Name>de4dot.code</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\de4dot.mdecrypt\de4dot.mdecrypt.csproj">
|
||||||
|
<Project>{5C93C5E2-196F-4877-BF65-96FEBFCEFCA1}</Project>
|
||||||
|
<Name>de4dot.mdecrypt</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\dnlib\src\dnlib.csproj">
|
||||||
|
<Project>{FDFC1237-143F-4919-8318-4926901F4639}</Project>
|
||||||
|
<Name>dnlib</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
1
deobfuscator.Template/readme.txt
Normal file
1
deobfuscator.Template/readme.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This is a template deobfuscator module. Make a copy and rename it to create your own deobfuscator modules with the required references and the correct build directories.
|
Loading…
Reference in New Issue
Block a user