Merge branch 'master' into confuser
This commit is contained in:
commit
0b9e7c7b06
|
@ -26,7 +26,7 @@ using AssemblyData;
|
||||||
|
|
||||||
namespace AssemblyServer {
|
namespace AssemblyServer {
|
||||||
public static class Start {
|
public static class Start {
|
||||||
public static int Main2(string[] args) {
|
public static int Main(string[] args) {
|
||||||
if (args.Length != 3)
|
if (args.Length != 3)
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
var serviceType = (AssemblyServiceType)int.Parse(args[0]);
|
var serviceType = (AssemblyServiceType)int.Parse(args[0]);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_CLR20_x64 {
|
namespace AssemblyServer_CLR20_x64 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_CLR20 {
|
namespace AssemblyServer_CLR20 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_CLR40_x64 {
|
namespace AssemblyServer_CLR40_x64 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_CLR40 {
|
namespace AssemblyServer_CLR40 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_x64 {
|
namespace AssemblyServer_x64 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace AssemblyServer_x86 {
|
namespace AssemblyServer_x86 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return AssemblyServer.Start.Main2(args);
|
return AssemblyServer.Start.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace de4dot_x64 {
|
namespace de4dot_x64 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return de4dot.cui.Program.Main2(args);
|
return de4dot.cui.Program.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ namespace de4dot.code {
|
||||||
var mdFlags = GetMetaDataFlags();
|
var mdFlags = GetMetaDataFlags();
|
||||||
if (!options.ControlFlowDeobfuscation)
|
if (!options.ControlFlowDeobfuscation)
|
||||||
mdFlags |= MetaDataFlags.KeepOldMaxStack;
|
mdFlags |= MetaDataFlags.KeepOldMaxStack;
|
||||||
assemblyModule.Save(options.NewFilename, mdFlags, deob as IModuleWriterListener);
|
assemblyModule.Save(options.NewFilename, mdFlags, new PrintNewTokens(module, deob as IModuleWriterListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<MethodDef> GetAllMethods() {
|
IList<MethodDef> GetAllMethods() {
|
||||||
|
|
107
de4dot.code/PrintNewTokens.cs
Normal file
107
de4dot.code/PrintNewTokens.cs
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2011-2013 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 dnlib.DotNet;
|
||||||
|
using dnlib.DotNet.MD;
|
||||||
|
using dnlib.DotNet.Writer;
|
||||||
|
|
||||||
|
namespace de4dot.code {
|
||||||
|
class PrintNewTokens : IModuleWriterListener {
|
||||||
|
readonly ModuleDef module;
|
||||||
|
readonly IModuleWriterListener otherListener;
|
||||||
|
|
||||||
|
public PrintNewTokens(ModuleDef module, IModuleWriterListener otherListener) {
|
||||||
|
this.module = module;
|
||||||
|
this.otherListener = otherListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) {
|
||||||
|
if (otherListener != null)
|
||||||
|
otherListener.OnWriterEvent(writer, evt);
|
||||||
|
if (evt == ModuleWriterEvent.End)
|
||||||
|
PrintTokens(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintTokens(ModuleWriterBase writer) {
|
||||||
|
if (Logger.Instance.IgnoresEvent(LoggerEvent.Verbose))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var md = writer.MetaData;
|
||||||
|
|
||||||
|
Logger.v("Old -> new tokens: Assembly: {0} (module: {1})", module.Assembly, module.Location);
|
||||||
|
Logger.Instance.Indent();
|
||||||
|
foreach (var type in module.GetTypes()) {
|
||||||
|
uint newRid;
|
||||||
|
|
||||||
|
newRid = md.GetRid(type);
|
||||||
|
if (newRid == 0)
|
||||||
|
continue;
|
||||||
|
Logger.v("{0:X8} -> {1:X8} Type: {2}",
|
||||||
|
type.MDToken.ToUInt32(),
|
||||||
|
new MDToken(Table.TypeDef, newRid).ToUInt32(),
|
||||||
|
Utils.RemoveNewlines(type));
|
||||||
|
|
||||||
|
Logger.Instance.Indent();
|
||||||
|
|
||||||
|
foreach (var method in type.Methods) {
|
||||||
|
newRid = md.GetRid(method);
|
||||||
|
if (newRid == 0)
|
||||||
|
continue;
|
||||||
|
Logger.v("{0:X8} -> {1:X8} Method: {2}",
|
||||||
|
method.MDToken.ToUInt32(),
|
||||||
|
new MDToken(Table.Method, newRid).ToUInt32(),
|
||||||
|
Utils.RemoveNewlines(method));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var field in type.Fields) {
|
||||||
|
newRid = md.GetRid(field);
|
||||||
|
if (newRid == 0)
|
||||||
|
continue;
|
||||||
|
Logger.v("{0:X8} -> {1:X8} Field: {2}",
|
||||||
|
field.MDToken.ToUInt32(),
|
||||||
|
new MDToken(Table.Field, newRid).ToUInt32(),
|
||||||
|
Utils.RemoveNewlines(field));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var prop in type.Properties) {
|
||||||
|
newRid = md.GetRid(prop);
|
||||||
|
if (newRid == 0)
|
||||||
|
continue;
|
||||||
|
Logger.v("{0:X8} -> {1:X8} Property: {2}",
|
||||||
|
prop.MDToken.ToUInt32(),
|
||||||
|
new MDToken(Table.Property, newRid).ToUInt32(),
|
||||||
|
Utils.RemoveNewlines(prop));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var evt in type.Events) {
|
||||||
|
newRid = md.GetRid(evt);
|
||||||
|
if (newRid == 0)
|
||||||
|
continue;
|
||||||
|
Logger.v("{0:X8} -> {1:X8} Event: {2}",
|
||||||
|
evt.MDToken.ToUInt32(),
|
||||||
|
new MDToken(Table.Event, newRid).ToUInt32(),
|
||||||
|
Utils.RemoveNewlines(evt));
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Instance.DeIndent();
|
||||||
|
}
|
||||||
|
Logger.Instance.DeIndent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -266,6 +266,7 @@
|
||||||
<Compile Include="deobfuscators\ILProtector\MainType.cs" />
|
<Compile Include="deobfuscators\ILProtector\MainType.cs" />
|
||||||
<Compile Include="deobfuscators\ILProtector\MethodReader.cs" />
|
<Compile Include="deobfuscators\ILProtector\MethodReader.cs" />
|
||||||
<Compile Include="deobfuscators\ILProtector\MethodsDecrypterBase.cs" />
|
<Compile Include="deobfuscators\ILProtector\MethodsDecrypterBase.cs" />
|
||||||
|
<Compile Include="deobfuscators\ILProtector\RuntimeFileInfo.cs" />
|
||||||
<Compile Include="deobfuscators\ILProtector\StaticMethodsDecrypter.cs" />
|
<Compile Include="deobfuscators\ILProtector\StaticMethodsDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\InitializedDataCreator.cs" />
|
<Compile Include="deobfuscators\InitializedDataCreator.cs" />
|
||||||
<Compile Include="deobfuscators\InlinedMethodsFinder.cs" />
|
<Compile Include="deobfuscators\InlinedMethodsFinder.cs" />
|
||||||
|
@ -339,6 +340,7 @@
|
||||||
<Compile Include="NameRegexes.cs" />
|
<Compile Include="NameRegexes.cs" />
|
||||||
<Compile Include="ObfuscatedFile.cs" />
|
<Compile Include="ObfuscatedFile.cs" />
|
||||||
<Compile Include="Option.cs" />
|
<Compile Include="Option.cs" />
|
||||||
|
<Compile Include="PrintNewTokens.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="renamer\asmmodules\EventDef.cs" />
|
<Compile Include="renamer\asmmodules\EventDef.cs" />
|
||||||
<Compile Include="renamer\asmmodules\FieldDef.cs" />
|
<Compile Include="renamer\asmmodules\FieldDef.cs" />
|
||||||
|
|
|
@ -94,8 +94,17 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
if (mainType.Detected && !staticMethodsDecrypter.Detected)
|
if (mainType.Detected && !staticMethodsDecrypter.Detected)
|
||||||
dynamicMethodsRestorer = new DynamicMethodsRestorer(module, mainType);
|
dynamicMethodsRestorer = new DynamicMethodsRestorer(module, mainType);
|
||||||
|
|
||||||
if (mainType.Detected && staticMethodsDecrypter.Detected && staticMethodsDecrypter.Version != null)
|
if (mainType.Detected) {
|
||||||
obfuscatorName += " " + staticMethodsDecrypter.Version;
|
if (staticMethodsDecrypter.Detected)
|
||||||
|
UpdateObfuscatorNameWith(staticMethodsDecrypter.Version);
|
||||||
|
else
|
||||||
|
UpdateObfuscatorNameWith(mainType.GetRuntimeVersionString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateObfuscatorNameWith(string version) {
|
||||||
|
if (!string.IsNullOrEmpty(version))
|
||||||
|
obfuscatorName += " " + version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DeobfuscateBegin() {
|
public override void DeobfuscateBegin() {
|
||||||
|
@ -107,6 +116,19 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
RemoveObfuscatorJunk(staticMethodsDecrypter);
|
RemoveObfuscatorJunk(staticMethodsDecrypter);
|
||||||
}
|
}
|
||||||
else if (dynamicMethodsRestorer != null) {
|
else if (dynamicMethodsRestorer != null) {
|
||||||
|
Logger.v("Runtime file versions:");
|
||||||
|
Logger.Instance.Indent();
|
||||||
|
bool emailMe = false;
|
||||||
|
foreach (var info in mainType.RuntimeFileInfos) {
|
||||||
|
var version = info.GetVersion();
|
||||||
|
emailMe |= version == null && System.IO.File.Exists(info.PathName);
|
||||||
|
emailMe |= version != null && version == new Version(1, 0, 7, 0);
|
||||||
|
Logger.v("Version: {0} ({1})", version == null ? "UNKNOWN" : version.ToString(), info.PathName);
|
||||||
|
}
|
||||||
|
Logger.Instance.DeIndent();
|
||||||
|
if (emailMe)
|
||||||
|
Logger.n("**** Email me this program! de4dot@gmail.com");
|
||||||
|
|
||||||
dynamicMethodsRestorer.Decrypt();
|
dynamicMethodsRestorer.Decrypt();
|
||||||
RemoveObfuscatorJunk(dynamicMethodsRestorer);
|
RemoveObfuscatorJunk(dynamicMethodsRestorer);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +142,8 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
AddResourceToBeRemoved(methodsDecrypter.Resource, "Encrypted methods resource");
|
AddResourceToBeRemoved(methodsDecrypter.Resource, "Encrypted methods resource");
|
||||||
AddTypeToBeRemoved(mainType.InvokerDelegate, "Invoker delegate type");
|
AddTypeToBeRemoved(mainType.InvokerDelegate, "Invoker delegate type");
|
||||||
AddFieldToBeRemoved(mainType.InvokerInstanceField, "Invoker delegate instance field");
|
AddFieldToBeRemoved(mainType.InvokerInstanceField, "Invoker delegate instance field");
|
||||||
foreach (var pm in mainType.ProtectMethods)
|
foreach (var info in mainType.RuntimeFileInfos)
|
||||||
AddMethodToBeRemoved(pm, "Obfuscator 'Protect' init method");
|
AddMethodToBeRemoved(info.ProtectMethod, "Obfuscator 'Protect' init method");
|
||||||
mainType.CleanUp();
|
mainType.CleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,13 +159,13 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
public abstract byte[] Decrypt(int methodId, uint rid);
|
public abstract byte[] Decrypt(int methodId, uint rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.0.7.1 - 1.0.8.0
|
// 1.0.7.0 - 1.0.8.0
|
||||||
class DecrypterV1_0_7_1 : DecrypterBase {
|
class DecrypterV1_0_7_0 : DecrypterBase {
|
||||||
DecryptMethod decryptMethod;
|
DecryptMethod decryptMethod;
|
||||||
|
|
||||||
unsafe delegate bool DecryptMethod(int appDomainId, int asmHashCode, int methodId, out byte* pMethodCode, out int methodSize);
|
unsafe delegate bool DecryptMethod(int appDomainId, int asmHashCode, int methodId, out byte* pMethodCode, out int methodSize);
|
||||||
|
|
||||||
public DecrypterV1_0_7_1(DynamicMethodsDecrypter dmd, FieldDef delegateField)
|
public DecrypterV1_0_7_0(DynamicMethodsDecrypter dmd, FieldDef delegateField)
|
||||||
: base(dmd) {
|
: base(dmd) {
|
||||||
IntPtr addr = GetDelegateAddress(delegateField);
|
IntPtr addr = GetDelegateAddress(delegateField);
|
||||||
decryptMethod = (DecryptMethod)Marshal.GetDelegateForFunctionPointer(addr, typeof(DecryptMethod));
|
decryptMethod = (DecryptMethod)Marshal.GetDelegateForFunctionPointer(addr, typeof(DecryptMethod));
|
||||||
|
@ -348,7 +348,7 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
if (delegateField == null)
|
if (delegateField == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new DecrypterV1_0_7_1(this, delegateField);
|
return new DecrypterV1_0_7_0(this, delegateField);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDecrypter CreateDecrypterV2_0_0_0() {
|
IDecrypter CreateDecrypterV2_0_0_0() {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using AssemblyData;
|
using AssemblyData;
|
||||||
using de4dot.code.AssemblyClient;
|
using de4dot.code.AssemblyClient;
|
||||||
|
@ -31,6 +32,7 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DecryptInternal() {
|
protected override void DecryptInternal() {
|
||||||
|
CheckRuntimeFiles();
|
||||||
IList<DecryptedMethodInfo> decryptedData;
|
IList<DecryptedMethodInfo> decryptedData;
|
||||||
var serverVersion = NewProcessAssemblyClientFactory.GetServerClrVersion(module);
|
var serverVersion = NewProcessAssemblyClientFactory.GetServerClrVersion(module);
|
||||||
using (var client = new NewProcessAssemblyClientFactory(serverVersion).Create(AssemblyServiceType.Generic)) {
|
using (var client = new NewProcessAssemblyClientFactory(serverVersion).Create(AssemblyServiceType.Generic)) {
|
||||||
|
@ -49,6 +51,13 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
methodInfos[info.id] = info;
|
methodInfos[info.id] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckRuntimeFiles() {
|
||||||
|
foreach (var info in mainType.RuntimeFileInfos) {
|
||||||
|
if (!File.Exists(info.PathName))
|
||||||
|
Logger.w(string.Format("ILProtector runtime file '{0}' is missing.", info.PathName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IList<int> GetMethodIds() {
|
IList<int> GetMethodIds() {
|
||||||
var ids = new List<int>();
|
var ids = new List<int>();
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ using de4dot.blocks;
|
||||||
namespace de4dot.code.deobfuscators.ILProtector {
|
namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
class MainType {
|
class MainType {
|
||||||
ModuleDefMD module;
|
ModuleDefMD module;
|
||||||
List<MethodDef> protectMethods;
|
List<RuntimeFileInfo> runtimeFileInfos;
|
||||||
TypeDef invokerDelegate;
|
TypeDef invokerDelegate;
|
||||||
FieldDef invokerInstanceField;
|
FieldDef invokerInstanceField;
|
||||||
|
|
||||||
public IEnumerable<MethodDef> ProtectMethods {
|
public List<RuntimeFileInfo> RuntimeFileInfos {
|
||||||
get { return protectMethods; }
|
get { return runtimeFileInfos; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeDef InvokerDelegate {
|
public TypeDef InvokerDelegate {
|
||||||
|
@ -42,7 +42,7 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Detected {
|
public bool Detected {
|
||||||
get { return protectMethods != null; }
|
get { return runtimeFileInfos != null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainType(ModuleDefMD module) {
|
public MainType(ModuleDefMD module) {
|
||||||
|
@ -81,7 +81,9 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
if (!GetDelegate(type, out invokerInstanceField, out invokerDelegate))
|
if (!GetDelegate(type, out invokerInstanceField, out invokerDelegate))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
protectMethods = methods;
|
runtimeFileInfos = new List<RuntimeFileInfo>(methods.Count);
|
||||||
|
foreach (var method in methods)
|
||||||
|
runtimeFileInfos.Add(new RuntimeFileInfo(method));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +111,17 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetRuntimeVersionString() {
|
||||||
|
if (runtimeFileInfos == null)
|
||||||
|
return null;
|
||||||
|
foreach (var info in runtimeFileInfos) {
|
||||||
|
var version = info.GetVersion();
|
||||||
|
if (version != null)
|
||||||
|
return version.ToString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void CleanUp() {
|
public void CleanUp() {
|
||||||
var cctor = DotNetUtils.GetModuleTypeCctor(module);
|
var cctor = DotNetUtils.GetModuleTypeCctor(module);
|
||||||
if (cctor != null) {
|
if (cctor != null) {
|
||||||
|
|
166
de4dot.code/deobfuscators/ILProtector/RuntimeFileInfo.cs
Normal file
166
de4dot.code/deobfuscators/ILProtector/RuntimeFileInfo.cs
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2011-2013 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;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using dnlib.DotNet;
|
||||||
|
|
||||||
|
namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
|
class RuntimeFileInfo {
|
||||||
|
const uint HASH_FILE_OFFSET = 0x00040000;
|
||||||
|
const int HASH_SIZE = 0x1000;
|
||||||
|
|
||||||
|
public MethodDef ProtectMethod { get; private set; }
|
||||||
|
public string PathName { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
Version runtimeVersion;
|
||||||
|
bool runtimeVersionInitialized;
|
||||||
|
|
||||||
|
class VersionInfo {
|
||||||
|
public Version Version { get; private set; }
|
||||||
|
public uint FileOffset { get; private set; }
|
||||||
|
public byte[] Hash { get; private set; }
|
||||||
|
|
||||||
|
public VersionInfo(Version version, byte[] hash) {
|
||||||
|
this.Version = version;
|
||||||
|
this.Hash = hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly VersionInfo[] versionInfo32 = new VersionInfo[] {
|
||||||
|
new VersionInfo(new Version(1, 0, 7, 0), new byte[] { 0x94, 0x79, 0x6E, 0xC1, 0x1F, 0x6D, 0xE9, 0xE3, 0x2F, 0x5E, 0xA3, 0x57, 0x71, 0x02, 0x22, 0x6A }),
|
||||||
|
new VersionInfo(new Version(1, 0, 7, 1), new byte[] { 0x8D, 0xCE, 0xAB, 0x0C, 0xA6, 0xA9, 0x4A, 0xA2, 0xCE, 0x43, 0xDE, 0x38, 0xEA, 0xDE, 0x0D, 0x3A }),
|
||||||
|
new VersionInfo(new Version(1, 0, 8, 0), new byte[] { 0x44, 0x09, 0x33, 0xCE, 0x90, 0x43, 0xF9, 0xC2, 0x2F, 0x11, 0x40, 0x1D, 0x18, 0xDA, 0x63, 0x3B }),
|
||||||
|
new VersionInfo(new Version(2, 0, 0, 0), new byte[] { 0xFD, 0x1D, 0x2B, 0x73, 0x2F, 0xD8, 0x27, 0x5F, 0xA3, 0x83, 0x76, 0x36, 0x29, 0x8E, 0x51, 0xA9 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 1, 0), new byte[] { 0x0D, 0x5E, 0xC2, 0xA5, 0x0D, 0x7C, 0xE1, 0x8B, 0x57, 0x9F, 0xC8, 0x16, 0x25, 0x95, 0x70, 0xEB }),
|
||||||
|
new VersionInfo(new Version(2, 0, 2, 0), new byte[] { 0x9C, 0xED, 0x53, 0x3A, 0x97, 0x4B, 0x9E, 0xC7, 0xF4, 0x82, 0xE9, 0x84, 0xB4, 0x9A, 0xEB, 0xA6 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 3, 0), new byte[] { 0x0C, 0xDD, 0xCF, 0x04, 0x20, 0x6E, 0x7A, 0x48, 0x26, 0x8B, 0x97, 0x8E, 0x58, 0x17, 0x9B, 0x51 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 4, 0), new byte[] { 0x1D, 0x41, 0xE7, 0x6D, 0x17, 0xED, 0x51, 0x37, 0xA0, 0xFC, 0x98, 0x5F, 0x19, 0x97, 0xEF, 0x9D }),
|
||||||
|
new VersionInfo(new Version(2, 0, 5, 0), new byte[] { 0x60, 0xD8, 0x1D, 0x1C, 0x0C, 0xBF, 0x46, 0x82, 0x9C, 0xE3, 0x73, 0x8D, 0x88, 0x2E, 0x0E, 0xBA }),
|
||||||
|
new VersionInfo(new Version(2, 0, 6, 0), new byte[] { 0x85, 0x89, 0x66, 0x39, 0xC3, 0x04, 0x3D, 0x3F, 0xFD, 0xBC, 0xFA, 0x70, 0x1D, 0x04, 0x59, 0x89 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 0), new byte[] { 0x16, 0x5C, 0xE1, 0xA4, 0x30, 0xF7, 0x55, 0x26, 0x45, 0xB8, 0x43, 0x99, 0x2A, 0xC9, 0x6F, 0xD9 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 5), new byte[] { 0x11, 0x50, 0x25, 0x2C, 0x26, 0x03, 0x8B, 0xDA, 0xBC, 0x98, 0x7E, 0x81, 0x97, 0x3E, 0xCE, 0x31 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 6), new byte[] { 0x6F, 0x9C, 0xF2, 0xDB, 0x83, 0x76, 0x92, 0x6A, 0xC4, 0xAA, 0xAE, 0xFA, 0x3D, 0xB3, 0x69, 0x59 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 8, 0), new byte[] { 0x96, 0x84, 0xA0, 0x32, 0x3A, 0xB5, 0xAD, 0x89, 0xD7, 0xCD, 0x69, 0x34, 0xF1, 0x5D, 0xF3, 0x3A }),
|
||||||
|
new VersionInfo(new Version(2, 0, 8, 5), new byte[] { 0xB8, 0xCF, 0xEA, 0xBA, 0xB6, 0xAD, 0xE5, 0xCC, 0xFB, 0xA4, 0xE4, 0xFE, 0x1A, 0x83, 0xE5, 0x85 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 9, 0), new byte[] { 0xA4, 0x68, 0x70, 0xA2, 0x1E, 0xBB, 0x99, 0xAB, 0xDD, 0x8C, 0xCA, 0x55, 0x32, 0x12, 0x95, 0xB5 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 10, 0), new byte[] { 0xC5, 0xDC, 0x27, 0x22, 0x8F, 0x09, 0xFB, 0x56, 0x84, 0x6E, 0x07, 0x62, 0x4E, 0xBF, 0x71, 0xA6 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 11, 0), new byte[] { 0x57, 0xAD, 0xBC, 0xB0, 0x7F, 0x80, 0xEF, 0xEA, 0xC3, 0xB7, 0x9F, 0x27, 0x87, 0x0A, 0x4B, 0xFF }),
|
||||||
|
};
|
||||||
|
|
||||||
|
static readonly VersionInfo[] versionInfo64 = new VersionInfo[] {
|
||||||
|
// No sig for 1.0.7.0 x64 since I don't have it yet.
|
||||||
|
new VersionInfo(new Version(1, 0, 7, 1), new byte[] { 0x68, 0x4C, 0xC0, 0xC2, 0x55, 0x75, 0x72, 0x09, 0x12, 0x10, 0xA4, 0xF3, 0xFE, 0x95, 0x4D, 0x7A }),
|
||||||
|
new VersionInfo(new Version(1, 0, 8, 0), new byte[] { 0x99, 0xAF, 0x3D, 0x39, 0x16, 0xC2, 0xD6, 0x10, 0x6E, 0x09, 0x64, 0xDE, 0xA4, 0xB3, 0x30, 0xE5 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 0, 0), new byte[] { 0x02, 0x90, 0xDA, 0xBD, 0x37, 0xEE, 0x20, 0x86, 0xA7, 0x30, 0x31, 0x6D, 0x92, 0xEF, 0xB3, 0x01 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 1, 0), new byte[] { 0xE8, 0xE7, 0x11, 0x6B, 0x52, 0x60, 0x5A, 0x4D, 0x5A, 0xC6, 0x76, 0xF5, 0xD3, 0x64, 0xB1, 0x03 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 2, 0), new byte[] { 0xD3, 0x37, 0xA1, 0x69, 0xF4, 0x25, 0x86, 0x19, 0xC6, 0x89, 0x70, 0x82, 0x9A, 0x3E, 0xCC, 0x04 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 3, 0), new byte[] { 0xB1, 0xF8, 0xCB, 0xFD, 0x2D, 0x47, 0x36, 0xF1, 0x8A, 0x1D, 0xEF, 0xA7, 0x07, 0x0C, 0xD9, 0x74 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 4, 0), new byte[] { 0x53, 0xC7, 0xA8, 0x3F, 0xD8, 0x9D, 0xA1, 0x85, 0x04, 0x50, 0x1D, 0x19, 0xF4, 0x1F, 0xF4, 0x44 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 5, 0), new byte[] { 0x32, 0x82, 0x4B, 0xC7, 0xBB, 0x32, 0xBF, 0x9F, 0xB7, 0x9B, 0x06, 0x90, 0x7B, 0xB0, 0x7B, 0x7C }),
|
||||||
|
new VersionInfo(new Version(2, 0, 6, 0), new byte[] { 0x4F, 0x02, 0x86, 0xA6, 0xCA, 0xFD, 0xC1, 0x47, 0xA1, 0xDB, 0x2F, 0x73, 0x94, 0x38, 0x2B, 0xA7 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 0), new byte[] { 0x43, 0xA4, 0xC1, 0xA8, 0xC7, 0x36, 0x55, 0xEB, 0x3F, 0xFF, 0xA0, 0xB3, 0x85, 0x00, 0x21, 0x99 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 5), new byte[] { 0x6A, 0xA8, 0x2B, 0x28, 0x0B, 0xEE, 0x4C, 0xF0, 0x57, 0x3F, 0x43, 0xD4, 0xFB, 0xBC, 0x5E, 0x8C }),
|
||||||
|
new VersionInfo(new Version(2, 0, 7, 6), new byte[] { 0xE5, 0xD7, 0x81, 0xBD, 0x85, 0x02, 0x10, 0xAC, 0x92, 0x4A, 0xF0, 0x35, 0xD2, 0x4C, 0x50, 0xA5 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 8, 0), new byte[] { 0x14, 0x44, 0xD1, 0x34, 0x69, 0x4D, 0xC7, 0xB7, 0x4D, 0x91, 0x0E, 0x6C, 0x4C, 0x9B, 0x46, 0x8E }),
|
||||||
|
new VersionInfo(new Version(2, 0, 8, 5), new byte[] { 0x5C, 0xEE, 0x47, 0x36, 0x2B, 0x10, 0xAD, 0x5F, 0x66, 0x6D, 0x3F, 0xD4, 0xF4, 0x4A, 0xFF, 0xA1 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 9, 0), new byte[] { 0x2B, 0x80, 0x93, 0x78, 0x22, 0x29, 0x8C, 0xA1, 0xED, 0xE4, 0x59, 0x1A, 0xEC, 0x5B, 0xAF, 0xA7 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 10, 0), new byte[] { 0xE3, 0x56, 0xB4, 0x98, 0x38, 0x27, 0x29, 0x27, 0x56, 0x87, 0x88, 0xAD, 0xA3, 0x50, 0x61, 0x24 }),
|
||||||
|
new VersionInfo(new Version(2, 0, 11, 0), new byte[] { 0x08, 0xDD, 0x40, 0x28, 0x08, 0x61, 0xDA, 0xD3, 0xD1, 0x38, 0x2F, 0x8A, 0xE0, 0x21, 0x0E, 0xE9 }),
|
||||||
|
};
|
||||||
|
|
||||||
|
public RuntimeFileInfo(MethodDef protectMethod) {
|
||||||
|
this.ProtectMethod = protectMethod;
|
||||||
|
Name = !protectMethod.HasImplMap ? "<<UNKNOWN_NAME>>" : protectMethod.ImplMap.Module.Name.String;
|
||||||
|
PathName = Path.Combine(Path.GetDirectoryName(Utils.GetFullPath(protectMethod.Module.Location)), Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version GetVersion() {
|
||||||
|
if (runtimeVersionInitialized)
|
||||||
|
return runtimeVersion;
|
||||||
|
runtimeVersion = GetVersion2();
|
||||||
|
runtimeVersionInitialized = true;
|
||||||
|
return runtimeVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
Version GetVersion2() {
|
||||||
|
try {
|
||||||
|
var hash = GetHash(PathName);
|
||||||
|
var info = GetVersionInfo(hash, versionInfo32);
|
||||||
|
if (info != null)
|
||||||
|
return info.Version;
|
||||||
|
info = GetVersionInfo(hash, versionInfo64);
|
||||||
|
if (info != null)
|
||||||
|
return info.Version;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VersionInfo GetVersionInfo(byte[] hash, VersionInfo[] infos) {
|
||||||
|
foreach (var info in infos) {
|
||||||
|
if (Equals(hash, info.Hash))
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte[] GetHash(string fullPath) {
|
||||||
|
try {
|
||||||
|
using (var reader = new BinaryReader(new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))) {
|
||||||
|
reader.BaseStream.Position = HASH_FILE_OFFSET;
|
||||||
|
var bytes = reader.ReadBytes(HASH_SIZE);
|
||||||
|
if (bytes.Length != HASH_SIZE)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
using (var hasher = MD5.Create()) {
|
||||||
|
using (var outStream = new NullStream()) {
|
||||||
|
using (var csStream = new CryptoStream(outStream, hasher, CryptoStreamMode.Write))
|
||||||
|
new BinaryWriter(csStream).Write(bytes);
|
||||||
|
}
|
||||||
|
return hasher.Hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Equals(byte[] a, byte[] b) {
|
||||||
|
if (a == null && b == null)
|
||||||
|
return true;
|
||||||
|
if (a == null || b == null)
|
||||||
|
return false;
|
||||||
|
if (a.Length != b.Length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < a.Length; i++) {
|
||||||
|
if (a[i] != b[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return PathName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -146,13 +146,13 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.0.6 - 1.0.7.0
|
// 1.0.6.x
|
||||||
class DecrypterV106 : DecrypterBase {
|
class DecrypterV106 : DecrypterBase {
|
||||||
byte[] decryptionKey6;
|
byte[] decryptionKey6;
|
||||||
byte[] decryptionKey7;
|
byte[] decryptionKey7;
|
||||||
|
|
||||||
DecrypterV106(byte[] key0, byte[] key6, byte[] key7, int startOffset) {
|
DecrypterV106(byte[] key0, byte[] key6, byte[] key7, int startOffset) {
|
||||||
this.ilpVersion = "1.0.6 - 1.0.7.0";
|
this.ilpVersion = "1.0.6.x";
|
||||||
this.startOffset = startOffset;
|
this.startOffset = startOffset;
|
||||||
this.decryptionKey = key0;
|
this.decryptionKey = key0;
|
||||||
this.decryptionKey6 = key6;
|
this.decryptionKey6 = key6;
|
||||||
|
@ -178,7 +178,7 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
|
|
||||||
var key0 = DeobUtils.Sha1Sum(sha1Data); // 1.0.6.0
|
var key0 = DeobUtils.Sha1Sum(sha1Data); // 1.0.6.0
|
||||||
var key6 = GetKey(reader, key0, keyXorOffs6); // 1.0.6.6
|
var key6 = GetKey(reader, key0, keyXorOffs6); // 1.0.6.6
|
||||||
var key7 = GetKey(reader, key0, keyXorOffs7); // 1.0.6.7 - 1.0.7.0
|
var key7 = GetKey(reader, key0, keyXorOffs7); // 1.0.6.7
|
||||||
return new DecrypterV106(key0, key6, key7, encryptedOffs);
|
return new DecrypterV106(key0, key6, key7, encryptedOffs);
|
||||||
}
|
}
|
||||||
catch (IOException) {
|
catch (IOException) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ using System.Text.RegularExpressions;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using dnlib.DotNet.Emit;
|
using dnlib.DotNet.Emit;
|
||||||
using de4dot.code.renamer.asmmodules;
|
using de4dot.code.renamer.asmmodules;
|
||||||
|
using de4dot.code.resources;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
|
@ -187,6 +188,8 @@ namespace de4dot.code.renamer {
|
||||||
public Renamer(IDeobfuscatorContext deobfuscatorContext, IEnumerable<IObfuscatedFile> files, RenamerFlags flags) {
|
public Renamer(IDeobfuscatorContext deobfuscatorContext, IEnumerable<IObfuscatedFile> files, RenamerFlags flags) {
|
||||||
RenamerFlags = flags;
|
RenamerFlags = flags;
|
||||||
|
|
||||||
|
WarnIfXaml(files);
|
||||||
|
|
||||||
modules = new Modules(deobfuscatorContext);
|
modules = new Modules(deobfuscatorContext);
|
||||||
isDelegateClass = new DerivedFrom(delegateClasses);
|
isDelegateClass = new DerivedFrom(delegateClasses);
|
||||||
mergeStateHelper = new MergeStateHelper(memberInfos);
|
mergeStateHelper = new MergeStateHelper(memberInfos);
|
||||||
|
@ -195,6 +198,39 @@ namespace de4dot.code.renamer {
|
||||||
modules.Add(new Module(file));
|
modules.Add(new Module(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void WarnIfXaml(IEnumerable<IObfuscatedFile> files) {
|
||||||
|
foreach (var file in files) {
|
||||||
|
foreach (var tmp in file.ModuleDefMD.Resources) {
|
||||||
|
var rsrc = tmp as EmbeddedResource;
|
||||||
|
if (rsrc == null)
|
||||||
|
continue;
|
||||||
|
if (UTF8String.IsNullOrEmpty(rsrc.Name))
|
||||||
|
continue;
|
||||||
|
if (!rsrc.Name.String.EndsWith(".g.resources"))
|
||||||
|
continue;
|
||||||
|
if (!HasXamlFiles(file.ModuleDefMD, rsrc))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Logger.w("File '{0}' contains XAML which isn't supported. Use --dont-rename.", file.Filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HasXamlFiles(ModuleDef module, EmbeddedResource rsrc) {
|
||||||
|
try {
|
||||||
|
rsrc.Data.Position = 0;
|
||||||
|
var rsrcSet = ResourceReader.Read(module, rsrc.Data);
|
||||||
|
foreach (var elem in rsrcSet.ResourceElements) {
|
||||||
|
if (elem.Name.EndsWith(".baml"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void Rename() {
|
public void Rename() {
|
||||||
if (modules.Empty)
|
if (modules.Empty)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -109,6 +109,7 @@ namespace de4dot.code.resources {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ResourceTypeCode.ByteArray:
|
case ResourceTypeCode.ByteArray:
|
||||||
|
case ResourceTypeCode.Stream:
|
||||||
var ary = (byte[])data;
|
var ary = (byte[])data;
|
||||||
writer.Write(ary.Length);
|
writer.Write(ary.Length);
|
||||||
writer.Write(ary);
|
writer.Write(ary);
|
||||||
|
@ -118,5 +119,40 @@ namespace de4dot.code.resources {
|
||||||
throw new ApplicationException("Unknown resource type code");
|
throw new ApplicationException("Unknown resource type code");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
switch (code) {
|
||||||
|
case ResourceTypeCode.Null:
|
||||||
|
return "NULL";
|
||||||
|
|
||||||
|
case ResourceTypeCode.String:
|
||||||
|
case ResourceTypeCode.Boolean:
|
||||||
|
case ResourceTypeCode.Char:
|
||||||
|
case ResourceTypeCode.Byte:
|
||||||
|
case ResourceTypeCode.SByte:
|
||||||
|
case ResourceTypeCode.Int16:
|
||||||
|
case ResourceTypeCode.UInt16:
|
||||||
|
case ResourceTypeCode.Int32:
|
||||||
|
case ResourceTypeCode.UInt32:
|
||||||
|
case ResourceTypeCode.Int64:
|
||||||
|
case ResourceTypeCode.UInt64:
|
||||||
|
case ResourceTypeCode.Single:
|
||||||
|
case ResourceTypeCode.Double:
|
||||||
|
case ResourceTypeCode.Decimal:
|
||||||
|
case ResourceTypeCode.DateTime:
|
||||||
|
case ResourceTypeCode.TimeSpan:
|
||||||
|
return string.Format("{0}: '{1}'", code, data);
|
||||||
|
|
||||||
|
case ResourceTypeCode.ByteArray:
|
||||||
|
case ResourceTypeCode.Stream:
|
||||||
|
var ary = data as byte[];
|
||||||
|
if (ary != null)
|
||||||
|
return string.Format("{0}: Length: {1}", code, ary.Length);
|
||||||
|
return string.Format("{0}: '{1}'", code, data);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return string.Format("{0}: '{1}'", code, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,14 @@ using dnlib.DotNet;
|
||||||
|
|
||||||
namespace de4dot.code.resources {
|
namespace de4dot.code.resources {
|
||||||
class ResourceDataCreator {
|
class ResourceDataCreator {
|
||||||
ModuleDefMD module;
|
readonly ModuleDef module;
|
||||||
Dictionary<string, UserResourceType> dict = new Dictionary<string, UserResourceType>(StringComparer.Ordinal);
|
readonly ModuleDefMD moduleMD;
|
||||||
Dictionary<string, string> asmNameToAsmFullName = new Dictionary<string, string>(StringComparer.Ordinal);
|
readonly Dictionary<string, UserResourceType> dict = new Dictionary<string, UserResourceType>(StringComparer.Ordinal);
|
||||||
|
readonly Dictionary<string, string> asmNameToAsmFullName = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public ResourceDataCreator(ModuleDefMD module) {
|
public ResourceDataCreator(ModuleDef module) {
|
||||||
this.module = module;
|
this.module = module;
|
||||||
|
this.moduleMD = module as ModuleDefMD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count {
|
public int Count {
|
||||||
|
@ -110,16 +112,20 @@ namespace de4dot.code.resources {
|
||||||
return new BuiltInResourceData(ResourceTypeCode.ByteArray, value);
|
return new BuiltInResourceData(ResourceTypeCode.ByteArray, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BuiltInResourceData CreateStream(byte[] value) {
|
||||||
|
return new BuiltInResourceData(ResourceTypeCode.Stream, value);
|
||||||
|
}
|
||||||
|
|
||||||
public CharArrayResourceData Create(char[] value) {
|
public CharArrayResourceData Create(char[] value) {
|
||||||
return new CharArrayResourceData(CreateUserResourceType(CharArrayResourceData.typeName), value);
|
return new CharArrayResourceData(CreateUserResourceType(CharArrayResourceData.ReflectionTypeName), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IconResourceData CreateIcon(byte[] value) {
|
public IconResourceData CreateIcon(byte[] value) {
|
||||||
return new IconResourceData(CreateUserResourceType(IconResourceData.typeName), value);
|
return new IconResourceData(CreateUserResourceType(IconResourceData.ReflectionTypeName), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageResourceData CreateImage(byte[] value) {
|
public ImageResourceData CreateImage(byte[] value) {
|
||||||
return new ImageResourceData(CreateUserResourceType(ImageResourceData.typeName), value);
|
return new ImageResourceData(CreateUserResourceType(ImageResourceData.ReflectionTypeName), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BinaryResourceData CreateSerialized(byte[] value) {
|
public BinaryResourceData CreateSerialized(byte[] value) {
|
||||||
|
@ -210,9 +216,11 @@ namespace de4dot.code.resources {
|
||||||
string TryGetRealAssemblyName(string assemblyName) {
|
string TryGetRealAssemblyName(string assemblyName) {
|
||||||
var simpleName = Utils.GetAssemblySimpleName(assemblyName);
|
var simpleName = Utils.GetAssemblySimpleName(assemblyName);
|
||||||
|
|
||||||
var asmRef = module.GetAssemblyRef(simpleName);
|
if (moduleMD != null) {
|
||||||
|
var asmRef = moduleMD.GetAssemblyRef(simpleName);
|
||||||
if (asmRef != null)
|
if (asmRef != null)
|
||||||
return asmRef.FullName;
|
return asmRef.FullName;
|
||||||
|
}
|
||||||
|
|
||||||
var asm = TheAssemblyResolver.Instance.Resolve(new AssemblyNameInfo(simpleName), module);
|
var asm = TheAssemblyResolver.Instance.Resolve(new AssemblyNameInfo(simpleName), module);
|
||||||
return asm == null ? null : asm.FullName;
|
return asm == null ? null : asm.FullName;
|
||||||
|
|
|
@ -21,5 +21,9 @@ namespace de4dot.code.resources {
|
||||||
class ResourceElement {
|
class ResourceElement {
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public IResourceData ResourceData { get; set; }
|
public IResourceData ResourceData { get; set; }
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("N: {0}, V: {1}", Name, ResourceData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,17 +34,15 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResourceReader {
|
struct ResourceReader {
|
||||||
ModuleDefMD module;
|
|
||||||
IBinaryReader reader;
|
IBinaryReader reader;
|
||||||
ResourceDataCreator resourceDataCreator;
|
ResourceDataCreator resourceDataCreator;
|
||||||
|
|
||||||
ResourceReader(ModuleDefMD module, IBinaryReader reader) {
|
ResourceReader(ModuleDef module, IBinaryReader reader) {
|
||||||
this.module = module;
|
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.resourceDataCreator = new ResourceDataCreator(module);
|
this.resourceDataCreator = new ResourceDataCreator(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceElementSet Read(ModuleDefMD module, IBinaryReader reader) {
|
public static ResourceElementSet Read(ModuleDef module, IBinaryReader reader) {
|
||||||
return new ResourceReader(module, reader).Read();
|
return new ResourceReader(module, reader).Read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +139,7 @@ namespace de4dot.code.resources {
|
||||||
case ResourceTypeCode.DateTime: return resourceDataCreator.Create(new DateTime(reader.ReadInt64()));
|
case ResourceTypeCode.DateTime: return resourceDataCreator.Create(new DateTime(reader.ReadInt64()));
|
||||||
case ResourceTypeCode.TimeSpan: return resourceDataCreator.Create(new TimeSpan(reader.ReadInt64()));
|
case ResourceTypeCode.TimeSpan: return resourceDataCreator.Create(new TimeSpan(reader.ReadInt64()));
|
||||||
case ResourceTypeCode.ByteArray: return resourceDataCreator.Create(reader.ReadBytes(reader.ReadInt32()));
|
case ResourceTypeCode.ByteArray: return resourceDataCreator.Create(reader.ReadBytes(reader.ReadInt32()));
|
||||||
|
case ResourceTypeCode.Stream: return resourceDataCreator.CreateStream(reader.ReadBytes(reader.ReadInt32()));
|
||||||
default:
|
default:
|
||||||
int userTypeIndex = (int)(code - (uint)ResourceTypeCode.UserTypes);
|
int userTypeIndex = (int)(code - (uint)ResourceTypeCode.UserTypes);
|
||||||
if (userTypeIndex < 0 || userTypeIndex >= userTypes.Count)
|
if (userTypeIndex < 0 || userTypeIndex >= userTypes.Count)
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace de4dot.code.resources {
|
||||||
DateTime,
|
DateTime,
|
||||||
TimeSpan,
|
TimeSpan,
|
||||||
ByteArray = 0x20,
|
ByteArray = 0x20,
|
||||||
|
Stream = 0x21,
|
||||||
UserTypes = 0x40,
|
UserTypes = 0x40,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CharArrayResourceData : UserResourceData {
|
class CharArrayResourceData : UserResourceData {
|
||||||
public static readonly string typeName = "System.Char[],mscorlib";
|
public static readonly string ReflectionTypeName = "System.Char[],mscorlib";
|
||||||
char[] data;
|
char[] data;
|
||||||
|
|
||||||
public CharArrayResourceData(UserResourceType type, char[] data)
|
public CharArrayResourceData(UserResourceType type, char[] data)
|
||||||
|
@ -52,10 +52,14 @@ namespace de4dot.code.resources {
|
||||||
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
||||||
formatter.Serialize(writer.BaseStream, data);
|
formatter.Serialize(writer.BaseStream, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("char[]: Length: {0}", data.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IconResourceData : UserResourceData {
|
class IconResourceData : UserResourceData {
|
||||||
public static readonly string typeName = "System.Drawing.Icon,System.Drawing";
|
public static readonly string ReflectionTypeName = "System.Drawing.Icon,System.Drawing";
|
||||||
Icon icon;
|
Icon icon;
|
||||||
|
|
||||||
public IconResourceData(UserResourceType type, byte[] data)
|
public IconResourceData(UserResourceType type, byte[] data)
|
||||||
|
@ -66,10 +70,14 @@ namespace de4dot.code.resources {
|
||||||
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
||||||
formatter.Serialize(writer.BaseStream, icon);
|
formatter.Serialize(writer.BaseStream, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("Icon: {0}", icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImageResourceData : UserResourceData {
|
class ImageResourceData : UserResourceData {
|
||||||
public static readonly string typeName = "System.Drawing.Bitmap,System.Drawing";
|
public static readonly string ReflectionTypeName = "System.Drawing.Bitmap,System.Drawing";
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
|
|
||||||
public ImageResourceData(UserResourceType type, byte[] data)
|
public ImageResourceData(UserResourceType type, byte[] data)
|
||||||
|
@ -80,6 +88,10 @@ namespace de4dot.code.resources {
|
||||||
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
||||||
formatter.Serialize(writer.BaseStream, bitmap);
|
formatter.Serialize(writer.BaseStream, bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Bitmap";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BinaryResourceData : UserResourceData {
|
class BinaryResourceData : UserResourceData {
|
||||||
|
@ -93,5 +105,9 @@ namespace de4dot.code.resources {
|
||||||
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
public override void WriteData(BinaryWriter writer, IFormatter formatter) {
|
||||||
writer.Write(data);
|
writer.Write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("Binary: Length: {0}", data.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,9 +247,10 @@ namespace de4dot.cui {
|
||||||
fileOptions.Add(new OneArgOption("o", null, "Name of output file", "file", (val) => {
|
fileOptions.Add(new OneArgOption("o", null, "Name of output file", "file", (val) => {
|
||||||
if (newFileOptions == null)
|
if (newFileOptions == null)
|
||||||
ExitError("Missing input file");
|
ExitError("Missing input file");
|
||||||
if (string.Equals(Utils.GetFullPath(newFileOptions.Filename), Utils.GetFullPath(val), StringComparison.OrdinalIgnoreCase))
|
var newFilename = Utils.GetFullPath(val);
|
||||||
ExitError(string.Format("Output file can't be same as input file ({0})", val));
|
if (string.Equals(Utils.GetFullPath(newFileOptions.Filename), newFilename, StringComparison.OrdinalIgnoreCase))
|
||||||
newFileOptions.NewFilename = val;
|
ExitError(string.Format("Output file can't be same as input file ({0})", newFilename));
|
||||||
|
newFileOptions.NewFilename = newFilename;
|
||||||
}));
|
}));
|
||||||
fileOptions.Add(new OneArgOption("p", null, "Obfuscator type (see below)", "type", (val) => {
|
fileOptions.Add(new OneArgOption("p", null, "Obfuscator type (see below)", "type", (val) => {
|
||||||
if (newFileOptions == null)
|
if (newFileOptions == null)
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace de4dot.cui {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Main2(string[] args) {
|
public static int Main(string[] args) {
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
|
|
||||||
const string showAllMessagesEnvName = "SHOWALLMESSAGES";
|
const string showAllMessagesEnvName = "SHOWALLMESSAGES";
|
||||||
|
@ -96,16 +96,15 @@ namespace de4dot.cui {
|
||||||
else {
|
else {
|
||||||
Logger.Instance.LogErrorDontIgnore("\n\n");
|
Logger.Instance.LogErrorDontIgnore("\n\n");
|
||||||
Logger.Instance.LogErrorDontIgnore("Hmmmm... something didn't work. Try the latest version.");
|
Logger.Instance.LogErrorDontIgnore("Hmmmm... something didn't work. Try the latest version.");
|
||||||
Logger.Instance.LogErrorDontIgnore(" EX: {0} : message: {1}", ex.GetType(), ex.Message);
|
|
||||||
Logger.Instance.LogErrorDontIgnore("If it's a supported obfuscator, it could be a bug or a new obfuscator version.");
|
|
||||||
Logger.Instance.LogErrorDontIgnore("If it's an unsupported obfuscator, make sure the methods are decrypted!");
|
|
||||||
}
|
}
|
||||||
Logger.Instance.LogErrorDontIgnore("Send bug reports to de4dot@gmail.com or go to https://bitbucket.org/0xd4d/de4dot/issues");
|
Logger.Instance.LogErrorDontIgnore("Email me all files / installer: de4dot@gmail.com");
|
||||||
Logger.Instance.LogErrorDontIgnore("I will need the original files, so email me a link to the installer or a zip/rar file.");
|
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Logger.Instance.NumIgnoredMessages > 0) {
|
if (Logger.Instance.NumIgnoredMessages > 0) {
|
||||||
|
if (Logger.Instance.NumIgnoredMessages == 1)
|
||||||
|
Logger.n("Ignored {0} warning/error", Logger.Instance.NumIgnoredMessages);
|
||||||
|
else
|
||||||
Logger.n("Ignored {0} warnings/errors", Logger.Instance.NumIgnoredMessages);
|
Logger.n("Ignored {0} warnings/errors", Logger.Instance.NumIgnoredMessages);
|
||||||
Logger.n("Use -v/-vv option or set environment variable {0}=1 to see all messages", showAllMessagesEnvName);
|
Logger.n("Use -v/-vv option or set environment variable {0}=1 to see all messages", showAllMessagesEnvName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace de4dot_x86 {
|
namespace de4dot_x86 {
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
return de4dot.cui.Program.Main2(args);
|
return de4dot.cui.Program.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user