Refactor proxy call fixer classes
This commit is contained in:
parent
8d4ea30b28
commit
7b3dcf8e05
|
@ -69,7 +69,7 @@
|
||||||
<Compile Include="deobfuscators\Babel_NET\MethodReferenceReader.cs" />
|
<Compile Include="deobfuscators\Babel_NET\MethodReferenceReader.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\MethodBodyReaderBase.cs" />
|
<Compile Include="deobfuscators\Babel_NET\MethodBodyReaderBase.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\MethodsDecrypter.cs" />
|
<Compile Include="deobfuscators\Babel_NET\MethodsDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\Babel_NET\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\ResourceDecrypter.cs" />
|
<Compile Include="deobfuscators\Babel_NET\ResourceDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\ResourceResolver.cs" />
|
<Compile Include="deobfuscators\Babel_NET\ResourceResolver.cs" />
|
||||||
<Compile Include="deobfuscators\Babel_NET\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\Babel_NET\StringDecrypter.cs" />
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
<Compile Include="deobfuscators\CliSecure\CsBlowfish.cs" />
|
<Compile Include="deobfuscators\CliSecure\CsBlowfish.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\Deobfuscator.cs" />
|
<Compile Include="deobfuscators\CliSecure\Deobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\MethodsDecrypter.cs" />
|
<Compile Include="deobfuscators\CliSecure\MethodsDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\CliSecure\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\ResourceDecrypter.cs" />
|
<Compile Include="deobfuscators\CliSecure\ResourceDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\StackFrameHelper.cs" />
|
<Compile Include="deobfuscators\CliSecure\StackFrameHelper.cs" />
|
||||||
<Compile Include="deobfuscators\CliSecure\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\CliSecure\StringDecrypter.cs" />
|
||||||
|
@ -105,7 +105,7 @@
|
||||||
<Compile Include="deobfuscators\CodeVeil\ResourceReader.cs" />
|
<Compile Include="deobfuscators\CodeVeil\ResourceReader.cs" />
|
||||||
<Compile Include="deobfuscators\CodeVeil\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\CodeVeil\StringDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\CodeVeil\Deobfuscator.cs" />
|
<Compile Include="deobfuscators\CodeVeil\Deobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\CodeVeil\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\CodeVeil\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\CodeVeil\TamperDetection.cs" />
|
<Compile Include="deobfuscators\CodeVeil\TamperDetection.cs" />
|
||||||
<Compile Include="deobfuscators\CodeWall\AssemblyDecrypter.cs" />
|
<Compile Include="deobfuscators\CodeWall\AssemblyDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\CodeWall\Deobfuscator.cs" />
|
<Compile Include="deobfuscators\CodeWall\Deobfuscator.cs" />
|
||||||
|
@ -118,7 +118,7 @@
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\AntiDebugger.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\AntiDebugger.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\AssemblyResolver.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\AssemblyResolver.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\Deobfuscator.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\Deobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\ResourceDecrypter.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\ResourceDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\ResourceResolver.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\ResourceResolver.cs" />
|
||||||
<Compile Include="deobfuscators\CryptoObfuscator\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\CryptoObfuscator\StringDecrypter.cs" />
|
||||||
|
@ -181,7 +181,7 @@
|
||||||
<Compile Include="deobfuscators\Goliath_NET\IntegerDecrypter.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\IntegerDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\Goliath_NET\LocalsRestorer.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\LocalsRestorer.cs" />
|
||||||
<Compile Include="deobfuscators\Goliath_NET\LogicalExpressionFixer.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\LogicalExpressionFixer.cs" />
|
||||||
<Compile Include="deobfuscators\Goliath_NET\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\Goliath_NET\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\StringDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\Goliath_NET\StrongNameChecker.cs" />
|
<Compile Include="deobfuscators\Goliath_NET\StrongNameChecker.cs" />
|
||||||
<Compile Include="deobfuscators\IDeobfuscatedFile.cs" />
|
<Compile Include="deobfuscators\IDeobfuscatedFile.cs" />
|
||||||
|
@ -212,13 +212,13 @@
|
||||||
<Compile Include="deobfuscators\Spices_Net\StringDecrypter.cs" />
|
<Compile Include="deobfuscators\Spices_Net\StringDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\StringCounts.cs" />
|
<Compile Include="deobfuscators\StringCounts.cs" />
|
||||||
<Compile Include="deobfuscators\Operations.cs" />
|
<Compile Include="deobfuscators\Operations.cs" />
|
||||||
<Compile Include="deobfuscators\ProxyDelegateFinderBase.cs" />
|
<Compile Include="deobfuscators\ProxyCallFixerBase.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolver.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolver.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolverInfo.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolverInfo.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\AutomatedErrorReportingFinder.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\AutomatedErrorReportingFinder.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\Deobfuscator.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\Deobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\MemoryManagerInfo.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\MemoryManagerInfo.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\ProxyDelegateFinder.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\ProxyCallFixer.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\ResolverInfoBase.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\ResolverInfoBase.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\ResourceDecrypter.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\ResourceDecrypter.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\ResourceDecrypterInfo.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\ResourceDecrypterInfo.cs" />
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
Int64ValueInliner int64ValueInliner;
|
Int64ValueInliner int64ValueInliner;
|
||||||
SingleValueInliner singleValueInliner;
|
SingleValueInliner singleValueInliner;
|
||||||
DoubleValueInliner doubleValueInliner;
|
DoubleValueInliner doubleValueInliner;
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
MethodsDecrypter methodsDecrypter;
|
MethodsDecrypter methodsDecrypter;
|
||||||
|
|
||||||
internal class Options : OptionsBase {
|
internal class Options : OptionsBase {
|
||||||
|
@ -118,7 +118,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
toInt32(assemblyResolver.Detected) +
|
toInt32(assemblyResolver.Detected) +
|
||||||
toInt32(stringDecrypter.Detected) +
|
toInt32(stringDecrypter.Detected) +
|
||||||
toInt32(constantsDecrypter.Detected) +
|
toInt32(constantsDecrypter.Detected) +
|
||||||
toInt32(proxyDelegateFinder.Detected) +
|
toInt32(proxyCallFixer.Detected) +
|
||||||
toInt32(methodsDecrypter.Detected) +
|
toInt32(methodsDecrypter.Detected) +
|
||||||
toInt32(hasMetadataStream("Babel"));
|
toInt32(hasMetadataStream("Babel"));
|
||||||
if (sum > 0)
|
if (sum > 0)
|
||||||
|
@ -139,8 +139,8 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
stringDecrypter.find();
|
stringDecrypter.find();
|
||||||
constantsDecrypter = new ConstantsDecrypter(module, initializedDataCreator);
|
constantsDecrypter = new ConstantsDecrypter(module, initializedDataCreator);
|
||||||
constantsDecrypter.find();
|
constantsDecrypter.find();
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module);
|
proxyCallFixer = new ProxyCallFixer(module);
|
||||||
proxyDelegateFinder.findDelegateCreator();
|
proxyCallFixer.findDelegateCreator();
|
||||||
methodsDecrypter = new MethodsDecrypter(module, DeobfuscatedFile.DeobfuscatorContext);
|
methodsDecrypter = new MethodsDecrypter(module, DeobfuscatedFile.DeobfuscatorContext);
|
||||||
methodsDecrypter.find();
|
methodsDecrypter.find();
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
doubleValueInliner.add(constantsDecrypter.DoubleDecrypter, (method, args) => constantsDecrypter.decryptDouble((int)args[0]));
|
doubleValueInliner.add(constantsDecrypter.DoubleDecrypter, (method, args) => constantsDecrypter.decryptDouble((int)args[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpEmbeddedAssemblies() {
|
void dumpEmbeddedAssemblies() {
|
||||||
|
@ -238,7 +238,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodEnd(Blocks blocks) {
|
public override void deobfuscateMethodEnd(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
if (options.DecryptConstants) {
|
if (options.DecryptConstants) {
|
||||||
int32ValueInliner.decrypt(blocks);
|
int32ValueInliner.decrypt(blocks);
|
||||||
int64ValueInliner.decrypt(blocks);
|
int64ValueInliner.decrypt(blocks);
|
||||||
|
@ -255,7 +255,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
||||||
}
|
}
|
||||||
|
|
||||||
removeProxyDelegates(proxyDelegateFinder);
|
removeProxyDelegates(proxyCallFixer);
|
||||||
base.deobfuscateEnd();
|
base.deobfuscateEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.Babel_NET {
|
namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer2 {
|
||||||
MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType> methodToType = new MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType>();
|
MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType> methodToType = new MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType>();
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module)
|
public ProxyCallFixer(ModuleDefinition module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void onFoundProxyDelegate(TypeDefinition type) {
|
protected override Dictionary<FieldDefinition, MethodDefinition> getFieldToMethodDictionary(TypeDefinition type) {
|
||||||
|
var dict = new Dictionary<FieldDefinition, MethodDefinition>();
|
||||||
foreach (var method in type.Methods) {
|
foreach (var method in type.Methods) {
|
||||||
if (!method.IsStatic || !method.HasBody || method.Name == ".cctor")
|
if (!method.IsStatic || !method.HasBody || method.Name == ".cctor")
|
||||||
continue;
|
continue;
|
||||||
|
@ -106,10 +107,11 @@ namespace de4dot.code.deobfuscators.Babel_NET {
|
||||||
if (instr.OpCode.Code != Code.Ldsfld)
|
if (instr.OpCode.Code != Code.Ldsfld)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
add(method, (FieldDefinition)instr.Operand);
|
dict[(FieldDefinition)instr.Operand] = method;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
|
@ -79,7 +79,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
string obfuscatorName = DeobfuscatorInfo.THE_NAME;
|
string obfuscatorName = DeobfuscatorInfo.THE_NAME;
|
||||||
|
|
||||||
List<TypeDefinition> cliSecureAttributes = new List<TypeDefinition>();
|
List<TypeDefinition> cliSecureAttributes = new List<TypeDefinition>();
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
CliSecureRtType cliSecureRtType;
|
CliSecureRtType cliSecureRtType;
|
||||||
StringDecrypter stringDecrypter;
|
StringDecrypter stringDecrypter;
|
||||||
ResourceDecrypter resourceDecrypter;
|
ResourceDecrypter resourceDecrypter;
|
||||||
|
@ -167,7 +167,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
|
|
||||||
int sum = toInt32(cliSecureRtType.Detected) +
|
int sum = toInt32(cliSecureRtType.Detected) +
|
||||||
toInt32(stringDecrypter.Detected) +
|
toInt32(stringDecrypter.Detected) +
|
||||||
toInt32(proxyDelegateFinder.Detected) +
|
toInt32(proxyCallFixer.Detected) +
|
||||||
toInt32(resourceDecrypter.Detected) +
|
toInt32(resourceDecrypter.Detected) +
|
||||||
toInt32(csvm.Detected);
|
toInt32(csvm.Detected);
|
||||||
if (sum > 0)
|
if (sum > 0)
|
||||||
|
@ -186,8 +186,8 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
stringDecrypter.find();
|
stringDecrypter.find();
|
||||||
resourceDecrypter = new ResourceDecrypter(module);
|
resourceDecrypter = new ResourceDecrypter(module);
|
||||||
resourceDecrypter.find();
|
resourceDecrypter.find();
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module);
|
proxyCallFixer = new ProxyCallFixer(module);
|
||||||
proxyDelegateFinder.findDelegateCreator();
|
proxyCallFixer.findDelegateCreator();
|
||||||
csvm = new vm.Csvm(DeobfuscatedFile.DeobfuscatorContext, module);
|
csvm = new vm.Csvm(DeobfuscatedFile.DeobfuscatorContext, module);
|
||||||
csvm.find();
|
csvm.find();
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
newOne.cliSecureRtType = new CliSecureRtType(module, cliSecureRtType);
|
newOne.cliSecureRtType = new CliSecureRtType(module, cliSecureRtType);
|
||||||
newOne.stringDecrypter = new StringDecrypter(module, stringDecrypter);
|
newOne.stringDecrypter = new StringDecrypter(module, stringDecrypter);
|
||||||
newOne.resourceDecrypter = new ResourceDecrypter(module, resourceDecrypter);
|
newOne.resourceDecrypter = new ResourceDecrypter(module, resourceDecrypter);
|
||||||
newOne.proxyDelegateFinder = new ProxyDelegateFinder(module, proxyDelegateFinder);
|
newOne.proxyCallFixer = new ProxyCallFixer(module, proxyCallFixer);
|
||||||
newOne.csvm = new vm.Csvm(DeobfuscatedFile.DeobfuscatorContext, module, csvm);
|
newOne.csvm = new vm.Csvm(DeobfuscatedFile.DeobfuscatorContext, module, csvm);
|
||||||
return newOne;
|
return newOne;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
this.addTypeToBeRemoved(type, "Obfuscator type");
|
this.addTypeToBeRemoved(type, "Obfuscator type");
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
|
|
||||||
staticStringInliner.add(stringDecrypter.Method, (method, args) => stringDecrypter.decrypt((string)args[0]));
|
staticStringInliner.add(stringDecrypter.Method, (method, args) => stringDecrypter.decrypt((string)args[0]));
|
||||||
DeobfuscatedFile.stringDecryptersAdded();
|
DeobfuscatedFile.stringDecryptersAdded();
|
||||||
|
@ -288,7 +288,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodEnd(Blocks blocks) {
|
public override void deobfuscateMethodEnd(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
removeStackFrameHelperCode(blocks);
|
removeStackFrameHelperCode(blocks);
|
||||||
base.deobfuscateMethodEnd(blocks);
|
base.deobfuscateMethodEnd(blocks);
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
public override void deobfuscateEnd() {
|
public override void deobfuscateEnd() {
|
||||||
if (options.SetInitLocals)
|
if (options.SetInitLocals)
|
||||||
setInitLocals();
|
setInitLocals();
|
||||||
removeProxyDelegates(proxyDelegateFinder);
|
removeProxyDelegates(proxyCallFixer);
|
||||||
if (options.RemoveStackFrameHelper) {
|
if (options.RemoveStackFrameHelper) {
|
||||||
if (stackFrameHelper.ExceptionLoggerRemover.NumRemovedExceptionLoggers > 0)
|
if (stackFrameHelper.ExceptionLoggerRemover.NumRemovedExceptionLoggers > 0)
|
||||||
addTypeToBeRemoved(stackFrameHelper.Type, "StackFrameHelper type");
|
addTypeToBeRemoved(stackFrameHelper.Type, "StackFrameHelper type");
|
||||||
|
|
|
@ -24,14 +24,14 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.CliSecure {
|
namespace de4dot.code.deobfuscators.CliSecure {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer1 {
|
||||||
IList<MemberReference> memberReferences;
|
IList<MemberReference> memberReferences;
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module)
|
public ProxyCallFixer(ModuleDefinition module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module, ProxyDelegateFinder oldOne)
|
public ProxyCallFixer(ModuleDefinition module, ProxyCallFixer oldOne)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
foreach (var method in oldOne.delegateCreatorMethods)
|
foreach (var method in oldOne.delegateCreatorMethods)
|
||||||
setDelegateCreatorMethod(lookup(method, "Could not find delegate creator method"));
|
setDelegateCreatorMethod(lookup(method, "Could not find delegate creator method"));
|
|
@ -59,7 +59,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
|
|
||||||
MainType mainType;
|
MainType mainType;
|
||||||
MethodsDecrypter methodsDecrypter;
|
MethodsDecrypter methodsDecrypter;
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
StringDecrypter stringDecrypter;
|
StringDecrypter stringDecrypter;
|
||||||
AssemblyResolver assemblyResolver;
|
AssemblyResolver assemblyResolver;
|
||||||
TypeDefinition killType;
|
TypeDefinition killType;
|
||||||
|
@ -92,7 +92,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
int sum = toInt32(mainType.Detected) +
|
int sum = toInt32(mainType.Detected) +
|
||||||
toInt32(methodsDecrypter.Detected) +
|
toInt32(methodsDecrypter.Detected) +
|
||||||
toInt32(stringDecrypter.Detected) +
|
toInt32(stringDecrypter.Detected) +
|
||||||
toInt32(proxyDelegateFinder.Detected);
|
toInt32(proxyCallFixer.Detected);
|
||||||
if (sum > 0)
|
if (sum > 0)
|
||||||
val += 100 + 10 * (sum - 1);
|
val += 100 + 10 * (sum - 1);
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
findKillType();
|
findKillType();
|
||||||
mainType = new MainType(module);
|
mainType = new MainType(module);
|
||||||
mainType.find();
|
mainType.find();
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module, mainType);
|
proxyCallFixer = new ProxyCallFixer(module, mainType);
|
||||||
proxyDelegateFinder.findDelegateCreator();
|
proxyCallFixer.findDelegateCreator();
|
||||||
methodsDecrypter = new MethodsDecrypter(mainType);
|
methodsDecrypter = new MethodsDecrypter(mainType);
|
||||||
methodsDecrypter.find();
|
methodsDecrypter.find();
|
||||||
stringDecrypter = new StringDecrypter(module, mainType);
|
stringDecrypter = new StringDecrypter(module, mainType);
|
||||||
|
@ -167,7 +167,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
newOne.mainType = new MainType(module, mainType);
|
newOne.mainType = new MainType(module, mainType);
|
||||||
newOne.methodsDecrypter = new MethodsDecrypter(mainType, methodsDecrypter);
|
newOne.methodsDecrypter = new MethodsDecrypter(mainType, methodsDecrypter);
|
||||||
newOne.stringDecrypter = new StringDecrypter(module, newOne.mainType, stringDecrypter);
|
newOne.stringDecrypter = new StringDecrypter(module, newOne.mainType, stringDecrypter);
|
||||||
newOne.proxyDelegateFinder = new ProxyDelegateFinder(module, newOne.mainType, proxyDelegateFinder);
|
newOne.proxyCallFixer = new ProxyCallFixer(module, newOne.mainType, proxyCallFixer);
|
||||||
newOne.killType = DeobUtils.lookup(module, killType, "Could not find KILL type");
|
newOne.killType = DeobUtils.lookup(module, killType, "Could not find KILL type");
|
||||||
return newOne;
|
return newOne;
|
||||||
}
|
}
|
||||||
|
@ -199,8 +199,8 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
|
|
||||||
removeTamperDetection();
|
removeTamperDetection();
|
||||||
|
|
||||||
proxyDelegateFinder.initialize();
|
proxyCallFixer.initialize();
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
|
|
||||||
resourceDecrypter = new ResourceDecrypter(module);
|
resourceDecrypter = new ResourceDecrypter(module);
|
||||||
resourceDecrypter.initialize();
|
resourceDecrypter.initialize();
|
||||||
|
@ -232,7 +232,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodBegin(Blocks blocks) {
|
public override void deobfuscateMethodBegin(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
base.deobfuscateMethodBegin(blocks);
|
base.deobfuscateMethodBegin(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateEnd() {
|
public override void deobfuscateEnd() {
|
||||||
bool canRemoveProxyTypes = proxyDelegateFinder.CanRemoveTypes;
|
bool canRemoveProxyTypes = proxyCallFixer.CanRemoveTypes;
|
||||||
|
|
||||||
if (CanRemoveStringDecrypterType)
|
if (CanRemoveStringDecrypterType)
|
||||||
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
||||||
|
@ -251,7 +251,7 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
if (!mainType.Detected) {
|
if (!mainType.Detected) {
|
||||||
}
|
}
|
||||||
else if (mainType.Version >= ObfuscatorVersion.V5_0) {
|
else if (mainType.Version >= ObfuscatorVersion.V5_0) {
|
||||||
if (!proxyDelegateFinder.FoundProxyType || canRemoveProxyTypes)
|
if (!proxyCallFixer.FoundProxyType || canRemoveProxyTypes)
|
||||||
addTypeToBeRemoved(mainType.Type, "Main CV type");
|
addTypeToBeRemoved(mainType.Type, "Main CV type");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -264,11 +264,11 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeProxyDelegates(proxyDelegateFinder, canRemoveProxyTypes);
|
removeProxyDelegates(proxyCallFixer, canRemoveProxyTypes);
|
||||||
if (canRemoveProxyTypes) {
|
if (canRemoveProxyTypes) {
|
||||||
addTypeToBeRemoved(proxyDelegateFinder.IlGeneratorType, "Obfuscator proxy method ILGenerator type");
|
addTypeToBeRemoved(proxyCallFixer.IlGeneratorType, "Obfuscator proxy method ILGenerator type");
|
||||||
addTypeToBeRemoved(proxyDelegateFinder.FieldInfoType, "Obfuscator proxy method FieldInfo type");
|
addTypeToBeRemoved(proxyCallFixer.FieldInfoType, "Obfuscator proxy method FieldInfo type");
|
||||||
addTypeToBeRemoved(proxyDelegateFinder.MethodInfoType, "Obfuscator proxy method MethodInfo type");
|
addTypeToBeRemoved(proxyCallFixer.MethodInfoType, "Obfuscator proxy method MethodInfo type");
|
||||||
}
|
}
|
||||||
|
|
||||||
addMethodsToBeRemoved(InvalidMethodsFinder.findAll(module), "Anti-reflection method");
|
addMethodsToBeRemoved(InvalidMethodsFinder.findAll(module), "Anti-reflection method");
|
||||||
|
|
|
@ -26,7 +26,7 @@ using Mono.Cecil.Metadata;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.CodeVeil {
|
namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer1 {
|
||||||
MainType mainType;
|
MainType mainType;
|
||||||
Info info = new Info();
|
Info info = new Info();
|
||||||
BinaryReader reader;
|
BinaryReader reader;
|
||||||
|
@ -73,12 +73,12 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
get { return info.methodInfoType; }
|
get { return info.methodInfoType; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module, MainType mainType)
|
public ProxyCallFixer(ModuleDefinition module, MainType mainType)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
this.mainType = mainType;
|
this.mainType = mainType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module, MainType mainType, ProxyDelegateFinder oldOne)
|
public ProxyCallFixer(ModuleDefinition module, MainType mainType, ProxyCallFixer oldOne)
|
||||||
: base(module, oldOne) {
|
: base(module, oldOne) {
|
||||||
this.mainType = mainType;
|
this.mainType = mainType;
|
||||||
info.proxyType = lookup(oldOne.info.proxyType, "Could not find proxyType");
|
info.proxyType = lookup(oldOne.info.proxyType, "Could not find proxyType");
|
||||||
|
@ -112,9 +112,6 @@ namespace de4dot.code.deobfuscators.CodeVeil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void onFoundProxyDelegate(TypeDefinition type) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
||||||
byte flags = reader.ReadByte();
|
byte flags = reader.ReadByte();
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
bool foundObfuscatedSymbols = false;
|
bool foundObfuscatedSymbols = false;
|
||||||
bool foundObfuscatorUserString = false;
|
bool foundObfuscatorUserString = false;
|
||||||
|
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
ResourceDecrypter resourceDecrypter;
|
ResourceDecrypter resourceDecrypter;
|
||||||
ResourceResolver resourceResolver;
|
ResourceResolver resourceResolver;
|
||||||
AssemblyResolver assemblyResolver;
|
AssemblyResolver assemblyResolver;
|
||||||
|
@ -103,7 +103,7 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
|
|
||||||
int sum = toInt32(stringDecrypter.Detected) +
|
int sum = toInt32(stringDecrypter.Detected) +
|
||||||
toInt32(tamperDetection.Detected) +
|
toInt32(tamperDetection.Detected) +
|
||||||
toInt32(proxyDelegateFinder.Detected);
|
toInt32(proxyCallFixer.Detected);
|
||||||
if (sum > 0)
|
if (sum > 0)
|
||||||
val += 100 + 10 * (sum - 1);
|
val += 100 + 10 * (sum - 1);
|
||||||
if (foundCryptoObfuscatorAttribute || foundObfuscatedSymbols || foundObfuscatorUserString)
|
if (foundCryptoObfuscatorAttribute || foundObfuscatedSymbols || foundObfuscatorUserString)
|
||||||
|
@ -123,8 +123,8 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
if (checkCryptoObfuscator())
|
if (checkCryptoObfuscator())
|
||||||
foundObfuscatedSymbols = true;
|
foundObfuscatedSymbols = true;
|
||||||
|
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module);
|
proxyCallFixer = new ProxyCallFixer(module);
|
||||||
proxyDelegateFinder.findDelegateCreator();
|
proxyCallFixer.findDelegateCreator();
|
||||||
stringDecrypter = new StringDecrypter(module);
|
stringDecrypter = new StringDecrypter(module);
|
||||||
stringDecrypter.find();
|
stringDecrypter.find();
|
||||||
tamperDetection = new TamperDetection(module);
|
tamperDetection = new TamperDetection(module);
|
||||||
|
@ -191,18 +191,18 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
addTypeToBeRemoved(tamperDetection.Type, "Tamper detection type");
|
addTypeToBeRemoved(tamperDetection.Type, "Tamper detection type");
|
||||||
addTypeToBeRemoved(antiDebugger.Type, "Anti-debugger type");
|
addTypeToBeRemoved(antiDebugger.Type, "Anti-debugger type");
|
||||||
|
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
|
|
||||||
dumpEmbeddedAssemblies();
|
dumpEmbeddedAssemblies();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodEnd(Blocks blocks) {
|
public override void deobfuscateMethodEnd(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
base.deobfuscateMethodEnd(blocks);
|
base.deobfuscateMethodEnd(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateEnd() {
|
public override void deobfuscateEnd() {
|
||||||
removeProxyDelegates(proxyDelegateFinder);
|
removeProxyDelegates(proxyCallFixer);
|
||||||
if (CanRemoveStringDecrypterType) {
|
if (CanRemoveStringDecrypterType) {
|
||||||
addResourceToBeRemoved(stringDecrypter.Resource, "Encrypted strings");
|
addResourceToBeRemoved(stringDecrypter.Resource, "Encrypted strings");
|
||||||
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
addTypeToBeRemoved(stringDecrypter.Type, "String decrypter type");
|
||||||
|
|
|
@ -24,10 +24,10 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer2 {
|
||||||
Dictionary<MethodDefinition, ProxyCreatorType> methodToType = new Dictionary<MethodDefinition, ProxyCreatorType>();
|
Dictionary<MethodDefinition, ProxyCreatorType> methodToType = new Dictionary<MethodDefinition, ProxyCreatorType>();
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module)
|
public ProxyCallFixer(ModuleDefinition module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,8 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void onFoundProxyDelegate(TypeDefinition type) {
|
protected override Dictionary<FieldDefinition, MethodDefinition> getFieldToMethodDictionary(TypeDefinition type) {
|
||||||
|
var dict = new Dictionary<FieldDefinition, MethodDefinition>();
|
||||||
foreach (var method in type.Methods) {
|
foreach (var method in type.Methods) {
|
||||||
if (!method.IsStatic || !method.HasBody || method.Name == ".cctor")
|
if (!method.IsStatic || !method.HasBody || method.Name == ".cctor")
|
||||||
continue;
|
continue;
|
||||||
|
@ -84,10 +85,11 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
if (instr.OpCode.Code != Code.Ldsfld)
|
if (instr.OpCode.Code != Code.Ldsfld)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
add(method, (FieldDefinition)instr.Operand);
|
dict[(FieldDefinition)instr.Operand] = method;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
|
@ -663,14 +663,14 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeProxyDelegates(ProxyDelegateFinderBase proxyDelegateFinder, bool removeCreators = true) {
|
protected void removeProxyDelegates(ProxyCallFixerBase proxyCallFixer, bool removeCreators = true) {
|
||||||
if (proxyDelegateFinder.Errors != 0) {
|
if (proxyCallFixer.Errors != 0) {
|
||||||
Log.v("Not removing proxy delegates and creator type since errors were detected.");
|
Log.v("Not removing proxy delegates and creator type since errors were detected.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addTypesToBeRemoved(proxyDelegateFinder.DelegateTypes, "Proxy delegate type");
|
addTypesToBeRemoved(proxyCallFixer.DelegateTypes, "Proxy delegate type");
|
||||||
if (removeCreators && proxyDelegateFinder.RemovedDelegateCreatorCalls > 0)
|
if (removeCreators && proxyCallFixer.RemovedDelegateCreatorCalls > 0)
|
||||||
addTypesToBeRemoved(proxyDelegateFinder.DelegateCreatorTypes, "Proxy delegate creator type");
|
addTypesToBeRemoved(proxyCallFixer.DelegateCreatorTypes, "Proxy delegate creator type");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Resource getResource(IEnumerable<string> strings) {
|
protected Resource getResource(IEnumerable<string> strings) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
Options options;
|
Options options;
|
||||||
string obfuscatorName = DeobfuscatorInfo.THE_NAME;
|
string obfuscatorName = DeobfuscatorInfo.THE_NAME;
|
||||||
|
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
LocalsRestorer localsRestorer;
|
LocalsRestorer localsRestorer;
|
||||||
LogicalExpressionFixer logicalExpressionFixer;
|
LogicalExpressionFixer logicalExpressionFixer;
|
||||||
StringDecrypter stringDecrypter;
|
StringDecrypter stringDecrypter;
|
||||||
|
@ -177,8 +177,8 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
public override void deobfuscateBegin() {
|
public override void deobfuscateBegin() {
|
||||||
base.deobfuscateBegin();
|
base.deobfuscateBegin();
|
||||||
|
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module);
|
proxyCallFixer = new ProxyCallFixer(module);
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
localsRestorer = new LocalsRestorer(module);
|
localsRestorer = new LocalsRestorer(module);
|
||||||
if (options.RestoreLocals)
|
if (options.RestoreLocals)
|
||||||
localsRestorer.find();
|
localsRestorer.find();
|
||||||
|
@ -220,7 +220,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodBegin(Blocks blocks) {
|
public override void deobfuscateMethodBegin(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
base.deobfuscateMethodBegin(blocks);
|
base.deobfuscateMethodBegin(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateEnd() {
|
public override void deobfuscateEnd() {
|
||||||
removeProxyDelegates(proxyDelegateFinder);
|
removeProxyDelegates(proxyCallFixer);
|
||||||
removeInlinedMethods();
|
removeInlinedMethods();
|
||||||
addTypesToBeRemoved(localsRestorer.Types, "Method locals obfuscation type");
|
addTypesToBeRemoved(localsRestorer.Types, "Method locals obfuscation type");
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.Goliath_NET {
|
namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer2 {
|
||||||
public ProxyDelegateFinder(ModuleDefinition module)
|
public ProxyCallFixer(ModuleDefinition module)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
Log.indent();
|
Log.indent();
|
||||||
foreach (var info in infos) {
|
foreach (var info in infos) {
|
||||||
var di = info.delegateInfo;
|
var di = info.delegateInfo;
|
||||||
add(info.method, di.field);
|
add(info.method, di);
|
||||||
addDelegateInfo(di);
|
|
||||||
Log.v("Field: {0}, Opcode: {1}, Method: {2} ({3:X8})",
|
Log.v("Field: {0}, Opcode: {1}, Method: {2} ({3:X8})",
|
||||||
Utils.removeNewlines(di.field.Name),
|
Utils.removeNewlines(di.field.Name),
|
||||||
di.callOpcode,
|
di.callOpcode,
|
||||||
|
@ -137,8 +136,8 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void onFoundProxyDelegate(TypeDefinition type) {
|
protected override Dictionary<FieldDefinition, MethodDefinition> getFieldToMethodDictionary(TypeDefinition type) {
|
||||||
throw new System.NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
protected override void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode) {
|
|
@ -24,13 +24,11 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators {
|
namespace de4dot.code.deobfuscators {
|
||||||
abstract class ProxyDelegateFinderBase {
|
abstract class ProxyCallFixerBase {
|
||||||
protected ModuleDefinition module;
|
protected ModuleDefinition module;
|
||||||
protected List<MethodDefinition> delegateCreatorMethods = new List<MethodDefinition>();
|
protected List<MethodDefinition> delegateCreatorMethods = new List<MethodDefinition>();
|
||||||
protected Dictionary<TypeDefinition, bool> delegateTypesDict = new Dictionary<TypeDefinition, bool>();
|
protected Dictionary<TypeDefinition, bool> delegateTypesDict = new Dictionary<TypeDefinition, bool>();
|
||||||
FieldDefinitionAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefinitionAndDeclaringTypeDict<DelegateInfo>();
|
protected int errors = 0;
|
||||||
Dictionary<MethodDefinition, FieldDefinition> proxyMethodToField = new Dictionary<MethodDefinition, FieldDefinition>();
|
|
||||||
int errors = 0;
|
|
||||||
|
|
||||||
public int Errors {
|
public int Errors {
|
||||||
get { return errors; }
|
get { return errors; }
|
||||||
|
@ -64,26 +62,19 @@ namespace de4dot.code.deobfuscators {
|
||||||
get { return delegateCreatorMethods.Count != 0; }
|
get { return delegateCreatorMethods.Count != 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinderBase(ModuleDefinition module) {
|
protected ProxyCallFixerBase(ModuleDefinition module) {
|
||||||
this.module = module;
|
this.module = module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinderBase(ModuleDefinition module, ProxyDelegateFinderBase oldOne) {
|
protected ProxyCallFixerBase(ModuleDefinition module, ProxyCallFixerBase oldOne) {
|
||||||
this.module = module;
|
this.module = module;
|
||||||
foreach (var method in oldOne.delegateCreatorMethods)
|
foreach (var method in oldOne.delegateCreatorMethods)
|
||||||
delegateCreatorMethods.Add(lookup(method, "Could not find delegate creator method"));
|
delegateCreatorMethods.Add(lookup(method, "Could not find delegate creator method"));
|
||||||
foreach (var kv in oldOne.delegateTypesDict)
|
foreach (var kv in oldOne.delegateTypesDict)
|
||||||
delegateTypesDict[lookup(kv.Key, "Could not find delegate type")] = kv.Value;
|
delegateTypesDict[lookup(kv.Key, "Could not find delegate type")] = kv.Value;
|
||||||
foreach (var key in oldOne.fieldToDelegateInfo.getKeys())
|
|
||||||
fieldToDelegateInfo.add(lookup(key, "Could not find field"), copy(oldOne.fieldToDelegateInfo.find(key)));
|
|
||||||
foreach (var kv in oldOne.proxyMethodToField) {
|
|
||||||
var key = lookup(kv.Key, "Could not find proxy method");
|
|
||||||
var value = lookup(kv.Value, "Could not find proxy field");
|
|
||||||
proxyMethodToField[key] = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DelegateInfo copy(DelegateInfo di) {
|
protected DelegateInfo copy(DelegateInfo di) {
|
||||||
var method = lookup(di.methodRef, "Could not find method ref");
|
var method = lookup(di.methodRef, "Could not find method ref");
|
||||||
var field = lookup(di.field, "Could not find delegate field");
|
var field = lookup(di.field, "Could not find delegate field");
|
||||||
return new DelegateInfo(field, method, di.callOpcode);
|
return new DelegateInfo(field, method, di.callOpcode);
|
||||||
|
@ -93,7 +84,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
return DeobUtils.lookup(module, def, errorMessage);
|
return DeobUtils.lookup(module, def, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelegateCreatorMethod(MethodDefinition delegateCreatorMethod) {
|
protected void setDelegateCreatorMethod(MethodDefinition delegateCreatorMethod) {
|
||||||
if (delegateCreatorMethod == null)
|
if (delegateCreatorMethod == null)
|
||||||
return;
|
return;
|
||||||
delegateCreatorMethods.Add(delegateCreatorMethod);
|
delegateCreatorMethods.Add(delegateCreatorMethod);
|
||||||
|
@ -116,6 +107,97 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected class BlockInstr {
|
||||||
|
public Block Block { get; set; }
|
||||||
|
public int Index { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class RemoveInfo {
|
||||||
|
public int Index { get; set; }
|
||||||
|
public DelegateInfo DelegateInfo { get; set; }
|
||||||
|
public bool IsCall {
|
||||||
|
get { return DelegateInfo != null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual bool ProxyCallIsObfuscated {
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deobfuscate(Blocks blocks) {
|
||||||
|
if (blocks.Method.DeclaringType != null && delegateTypesDict.ContainsKey(blocks.Method.DeclaringType))
|
||||||
|
return;
|
||||||
|
var allBlocks = blocks.MethodBlocks.getAllBlocks();
|
||||||
|
int loops = ProxyCallIsObfuscated ? 50 : 1;
|
||||||
|
for (int i = 0; i < loops; i++) {
|
||||||
|
if (!deobfuscate(blocks, allBlocks))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
deobfuscateEnd(blocks, allBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract bool deobfuscate(Blocks blocks, IList<Block> allBlocks);
|
||||||
|
|
||||||
|
protected virtual void deobfuscateEnd(Blocks blocks, IList<Block> allBlocks) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void add(Dictionary<Block, List<RemoveInfo>> removeInfos, Block block, int index, DelegateInfo di) {
|
||||||
|
List<RemoveInfo> list;
|
||||||
|
if (!removeInfos.TryGetValue(block, out list))
|
||||||
|
removeInfos[block] = list = new List<RemoveInfo>();
|
||||||
|
list.Add(new RemoveInfo {
|
||||||
|
Index = index,
|
||||||
|
DelegateInfo = di,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static bool fixProxyCalls(Dictionary<Block, List<RemoveInfo>> removeInfos) {
|
||||||
|
foreach (var block in removeInfos.Keys) {
|
||||||
|
var list = removeInfos[block];
|
||||||
|
var removeIndexes = new List<int>(list.Count);
|
||||||
|
foreach (var info in list) {
|
||||||
|
if (info.IsCall) {
|
||||||
|
var opcode = info.DelegateInfo.callOpcode;
|
||||||
|
var newInstr = Instruction.Create(opcode, info.DelegateInfo.methodRef);
|
||||||
|
block.replace(info.Index, 1, newInstr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
removeIndexes.Add(info.Index);
|
||||||
|
}
|
||||||
|
block.remove(removeIndexes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return removeInfos.Count > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixes proxy calls that call the delegate inline in the code, eg.:
|
||||||
|
// ldsfld delegate_instance
|
||||||
|
// ...push args...
|
||||||
|
// call Invoke
|
||||||
|
abstract class ProxyCallFixer1 : ProxyCallFixerBase {
|
||||||
|
FieldDefinitionAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefinitionAndDeclaringTypeDict<DelegateInfo>();
|
||||||
|
|
||||||
|
protected ProxyCallFixer1(ModuleDefinition module)
|
||||||
|
: base(module) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProxyCallFixer1(ModuleDefinition module, ProxyCallFixer1 oldOne)
|
||||||
|
: base(module, oldOne) {
|
||||||
|
foreach (var key in oldOne.fieldToDelegateInfo.getKeys())
|
||||||
|
fieldToDelegateInfo.add(lookup(key, "Could not find field"), copy(oldOne.fieldToDelegateInfo.find(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addDelegateInfo(DelegateInfo di) {
|
||||||
|
fieldToDelegateInfo.add(di.field, di);
|
||||||
|
}
|
||||||
|
|
||||||
|
DelegateInfo getDelegateInfo(FieldReference field) {
|
||||||
|
if (field == null)
|
||||||
|
return null;
|
||||||
|
return fieldToDelegateInfo.find(field);
|
||||||
|
}
|
||||||
|
|
||||||
public void find() {
|
public void find() {
|
||||||
if (delegateCreatorMethods.Count == 0)
|
if (delegateCreatorMethods.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -134,7 +216,6 @@ namespace de4dot.code.deobfuscators {
|
||||||
|
|
||||||
Log.v("Found proxy delegate: {0} ({1:X8})", Utils.removeNewlines(type), type.MetadataToken.ToUInt32());
|
Log.v("Found proxy delegate: {0} ({1:X8})", Utils.removeNewlines(type), type.MetadataToken.ToUInt32());
|
||||||
RemovedDelegateCreatorCalls++;
|
RemovedDelegateCreatorCalls++;
|
||||||
onFoundProxyDelegate(type);
|
|
||||||
|
|
||||||
Log.indent();
|
Log.indent();
|
||||||
foreach (var field in type.Fields) {
|
foreach (var field in type.Fields) {
|
||||||
|
@ -159,125 +240,41 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addDelegateInfo(DelegateInfo di) {
|
|
||||||
fieldToDelegateInfo.add(di.field, di);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void onFoundProxyDelegate(TypeDefinition type) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract object checkCctor(TypeDefinition type, MethodDefinition cctor);
|
protected abstract object checkCctor(TypeDefinition type, MethodDefinition cctor);
|
||||||
protected abstract void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode);
|
protected abstract void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode);
|
||||||
|
|
||||||
protected void add(MethodDefinition proxyMethod, FieldDefinition proxyField) {
|
protected override bool deobfuscate(Blocks blocks, IList<Block> allBlocks) {
|
||||||
if (proxyMethod == null || proxyField == null)
|
|
||||||
return;
|
|
||||||
proxyMethodToField[proxyMethod] = proxyField;
|
|
||||||
}
|
|
||||||
|
|
||||||
DelegateInfo getDelegateInfo(FieldReference field) {
|
|
||||||
if (field == null)
|
|
||||||
return null;
|
|
||||||
return fieldToDelegateInfo.find(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
class BlockInstr {
|
|
||||||
public Block Block { get; set; }
|
|
||||||
public int Index { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
class RemoveInfo {
|
|
||||||
public int Index { get; set; }
|
|
||||||
public DelegateInfo DelegateInfo { get; set; }
|
|
||||||
public bool IsCall {
|
|
||||||
get { return DelegateInfo != null; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual bool ProxyCallIsObfuscated {
|
|
||||||
get { return false; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deobfuscate(Blocks blocks) {
|
|
||||||
if (blocks.Method.DeclaringType != null && delegateTypesDict.ContainsKey(blocks.Method.DeclaringType))
|
|
||||||
return;
|
|
||||||
var allBlocks = blocks.MethodBlocks.getAllBlocks();
|
|
||||||
int loops = ProxyCallIsObfuscated ? 50 : 1;
|
|
||||||
for (int i = 0; i < loops; i++) {
|
|
||||||
if (!deobfuscate(blocks, allBlocks))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fixBrokenCalls(blocks.Method, allBlocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool deobfuscate(Blocks blocks, IList<Block> allBlocks) {
|
|
||||||
var removeInfos = new Dictionary<Block, List<RemoveInfo>>();
|
var removeInfos = new Dictionary<Block, List<RemoveInfo>>();
|
||||||
|
|
||||||
foreach (var block in allBlocks) {
|
foreach (var block in allBlocks) {
|
||||||
var instrs = block.Instructions;
|
var instrs = block.Instructions;
|
||||||
for (int i = 0; i < instrs.Count; i++) {
|
for (int i = 0; i < instrs.Count; i++) {
|
||||||
var instr = instrs[i];
|
var instr = instrs[i];
|
||||||
if (instr.OpCode == OpCodes.Ldsfld) {
|
if (instr.OpCode != OpCodes.Ldsfld)
|
||||||
var di = getDelegateInfo(instr.Operand as FieldReference);
|
continue;
|
||||||
if (di == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var visited = new Dictionary<Block, bool>();
|
var di = getDelegateInfo(instr.Operand as FieldReference);
|
||||||
var callInfo = findProxyCall(di, block, i, visited, 1);
|
if (di == null)
|
||||||
if (callInfo != null) {
|
continue;
|
||||||
add(removeInfos, block, i, null);
|
|
||||||
add(removeInfos, callInfo.Block, callInfo.Index, di);
|
var visited = new Dictionary<Block, bool>();
|
||||||
}
|
var callInfo = findProxyCall(di, block, i, visited, 1);
|
||||||
else {
|
if (callInfo != null) {
|
||||||
errors++;
|
add(removeInfos, block, i, null);
|
||||||
Log.w("Could not fix proxy call. Method: {0} ({1:X8}), Proxy type: {2} ({3:X8})",
|
add(removeInfos, callInfo.Block, callInfo.Index, di);
|
||||||
Utils.removeNewlines(blocks.Method),
|
|
||||||
blocks.Method.MetadataToken.ToInt32(),
|
|
||||||
Utils.removeNewlines(di.field.DeclaringType),
|
|
||||||
di.field.DeclaringType.MetadataToken.ToInt32());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (instr.OpCode == OpCodes.Call) {
|
else {
|
||||||
var method = instr.Operand as MethodDefinition;
|
errors++;
|
||||||
if (method == null)
|
Log.w("Could not fix proxy call. Method: {0} ({1:X8}), Proxy type: {2} ({3:X8})",
|
||||||
continue;
|
Utils.removeNewlines(blocks.Method),
|
||||||
FieldDefinition field;
|
blocks.Method.MetadataToken.ToInt32(),
|
||||||
if (!proxyMethodToField.TryGetValue(method, out field))
|
Utils.removeNewlines(di.field.DeclaringType),
|
||||||
continue;
|
di.field.DeclaringType.MetadataToken.ToInt32());
|
||||||
var di = getDelegateInfo(field);
|
|
||||||
if (di == null)
|
|
||||||
continue;
|
|
||||||
add(removeInfos, block, i, di);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var block in removeInfos.Keys) {
|
return fixProxyCalls(removeInfos);
|
||||||
var list = removeInfos[block];
|
|
||||||
var removeIndexes = new List<int>(list.Count);
|
|
||||||
foreach (var info in list) {
|
|
||||||
if (info.IsCall) {
|
|
||||||
var opcode = info.DelegateInfo.callOpcode;
|
|
||||||
var newInstr = Instruction.Create(opcode, info.DelegateInfo.methodRef);
|
|
||||||
block.replace(info.Index, 1, newInstr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
removeIndexes.Add(info.Index);
|
|
||||||
}
|
|
||||||
block.remove(removeIndexes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return removeInfos.Count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add(Dictionary<Block, List<RemoveInfo>> removeInfos, Block block, int index, DelegateInfo di) {
|
|
||||||
List<RemoveInfo> list;
|
|
||||||
if (!removeInfos.TryGetValue(block, out list))
|
|
||||||
removeInfos[block] = list = new List<RemoveInfo>();
|
|
||||||
list.Add(new RemoveInfo {
|
|
||||||
Index = index,
|
|
||||||
DelegateInfo = di,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockInstr findProxyCall(DelegateInfo di, Block block, int index, Dictionary<Block, bool> visited, int stack) {
|
BlockInstr findProxyCall(DelegateInfo di, Block block, int index, Dictionary<Block, bool> visited, int stack) {
|
||||||
|
@ -325,6 +322,10 @@ namespace de4dot.code.deobfuscators {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void deobfuscateEnd(Blocks blocks, IList<Block> allBlocks) {
|
||||||
|
fixBrokenCalls(blocks.Method, allBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
// The obfuscator could be buggy and call a proxy delegate without pushing the
|
// The obfuscator could be buggy and call a proxy delegate without pushing the
|
||||||
// instance field. SA has done it, so let's fix it.
|
// instance field. SA has done it, so let's fix it.
|
||||||
void fixBrokenCalls(MethodDefinition obfuscatedMethod, IList<Block> allBlocks) {
|
void fixBrokenCalls(MethodDefinition obfuscatedMethod, IList<Block> allBlocks) {
|
||||||
|
@ -356,4 +357,100 @@ namespace de4dot.code.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fixes proxy calls that call a static method which then calls
|
||||||
|
// Invoke() on a delegate instance, eg.:
|
||||||
|
// ...push args...
|
||||||
|
// call static method
|
||||||
|
abstract class ProxyCallFixer2 : ProxyCallFixerBase {
|
||||||
|
MethodDefinitionAndDeclaringTypeDict<DelegateInfo> proxyMethodToDelegateInfo = new MethodDefinitionAndDeclaringTypeDict<DelegateInfo>();
|
||||||
|
|
||||||
|
protected ProxyCallFixer2(ModuleDefinition module)
|
||||||
|
: base(module) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProxyCallFixer2(ModuleDefinition module, ProxyCallFixer2 oldOne)
|
||||||
|
: base(module, oldOne) {
|
||||||
|
foreach (var oldMethod in oldOne.proxyMethodToDelegateInfo.getKeys()) {
|
||||||
|
var oldDi = oldOne.proxyMethodToDelegateInfo.find(oldMethod);
|
||||||
|
var method = lookup(oldMethod, "Could not find proxy method");
|
||||||
|
proxyMethodToDelegateInfo.add(method, copy(oldDi));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void find() {
|
||||||
|
if (delegateCreatorMethods.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Log.v("Finding all proxy delegates");
|
||||||
|
foreach (var type in getDelegateTypes()) {
|
||||||
|
var cctor = DotNetUtils.getMethod(type, ".cctor");
|
||||||
|
if (cctor == null || !cctor.HasBody)
|
||||||
|
continue;
|
||||||
|
if (!type.HasFields)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
object context = checkCctor(type, cctor);
|
||||||
|
if (context == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Log.v("Found proxy delegate: {0} ({1:X8})", Utils.removeNewlines(type), type.MetadataToken.ToUInt32());
|
||||||
|
RemovedDelegateCreatorCalls++;
|
||||||
|
var fieldToMethod = getFieldToMethodDictionary(type);
|
||||||
|
|
||||||
|
Log.indent();
|
||||||
|
foreach (var field in type.Fields) {
|
||||||
|
MethodDefinition proxyMethod;
|
||||||
|
if (!fieldToMethod.TryGetValue(field, out proxyMethod))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
MethodReference calledMethod;
|
||||||
|
OpCode callOpcode;
|
||||||
|
getCallInfo(context, field, out calledMethod, out callOpcode);
|
||||||
|
|
||||||
|
if (calledMethod == null)
|
||||||
|
continue;
|
||||||
|
add(proxyMethod, new DelegateInfo(field, calledMethod, callOpcode));
|
||||||
|
Log.v("Field: {0}, Opcode: {1}, Method: {2} ({3:X8})",
|
||||||
|
Utils.removeNewlines(field.Name),
|
||||||
|
callOpcode,
|
||||||
|
Utils.removeNewlines(calledMethod),
|
||||||
|
calledMethod.MetadataToken.ToUInt32());
|
||||||
|
}
|
||||||
|
Log.deIndent();
|
||||||
|
delegateTypesDict[type] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void add(MethodDefinition method, DelegateInfo di) {
|
||||||
|
proxyMethodToDelegateInfo.add(method, di);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract object checkCctor(TypeDefinition type, MethodDefinition cctor);
|
||||||
|
protected abstract Dictionary<FieldDefinition, MethodDefinition> getFieldToMethodDictionary(TypeDefinition type);
|
||||||
|
protected abstract void getCallInfo(object context, FieldDefinition field, out MethodReference calledMethod, out OpCode callOpcode);
|
||||||
|
|
||||||
|
protected override bool deobfuscate(Blocks blocks, IList<Block> allBlocks) {
|
||||||
|
var removeInfos = new Dictionary<Block, List<RemoveInfo>>();
|
||||||
|
|
||||||
|
foreach (var block in allBlocks) {
|
||||||
|
var instrs = block.Instructions;
|
||||||
|
for (int i = 0; i < instrs.Count; i++) {
|
||||||
|
var instr = instrs[i];
|
||||||
|
if (instr.OpCode != OpCodes.Call)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var method = instr.Operand as MethodReference;
|
||||||
|
if (method == null)
|
||||||
|
continue;
|
||||||
|
var di = proxyMethodToDelegateInfo.find(method);
|
||||||
|
if (di == null)
|
||||||
|
continue;
|
||||||
|
add(removeInfos, block, i, di);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fixProxyCalls(removeInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -88,7 +88,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
ResourceResolver resourceResolver;
|
ResourceResolver resourceResolver;
|
||||||
MemoryManagerInfo memoryManagerInfo;
|
MemoryManagerInfo memoryManagerInfo;
|
||||||
|
|
||||||
ProxyDelegateFinder proxyDelegateFinder;
|
ProxyCallFixer proxyCallFixer;
|
||||||
AutomatedErrorReportingFinder automatedErrorReportingFinder;
|
AutomatedErrorReportingFinder automatedErrorReportingFinder;
|
||||||
TamperProtectionRemover tamperProtectionRemover;
|
TamperProtectionRemover tamperProtectionRemover;
|
||||||
|
|
||||||
|
@ -142,8 +142,8 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
findSmartAssemblyAttributes();
|
findSmartAssemblyAttributes();
|
||||||
memoryManagerInfo = new MemoryManagerInfo(module);
|
memoryManagerInfo = new MemoryManagerInfo(module);
|
||||||
memoryManagerInfo.find();
|
memoryManagerInfo.find();
|
||||||
proxyDelegateFinder = new ProxyDelegateFinder(module, DeobfuscatedFile);
|
proxyCallFixer = new ProxyCallFixer(module, DeobfuscatedFile);
|
||||||
proxyDelegateFinder.findDelegateCreator(module);
|
proxyCallFixer.findDelegateCreator(module);
|
||||||
|
|
||||||
if (!foundVersion)
|
if (!foundVersion)
|
||||||
guessVersion();
|
guessVersion();
|
||||||
|
@ -187,7 +187,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
if (poweredByAttributeString == "Powered by {smartassembly}") {
|
if (poweredByAttributeString == "Powered by {smartassembly}") {
|
||||||
// It's SA 1.x - 4.x
|
// It's SA 1.x - 4.x
|
||||||
|
|
||||||
if (proxyDelegateFinder.Detected || hasEmptyClassesInEveryNamespace()) {
|
if (proxyCallFixer.Detected || hasEmptyClassesInEveryNamespace()) {
|
||||||
ObfuscatorName = "SmartAssembly 4.x";
|
ObfuscatorName = "SmartAssembly 4.x";
|
||||||
approxVersion = new Version(4, 0, 0, 0);
|
approxVersion = new Version(4, 0, 0, 0);
|
||||||
return;
|
return;
|
||||||
|
@ -303,7 +303,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
}
|
}
|
||||||
|
|
||||||
initDecrypters();
|
initDecrypters();
|
||||||
proxyDelegateFinder.find();
|
proxyCallFixer.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initDecrypters() {
|
void initDecrypters() {
|
||||||
|
@ -430,7 +430,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void deobfuscateMethodEnd(Blocks blocks) {
|
public override void deobfuscateMethodEnd(Blocks blocks) {
|
||||||
proxyDelegateFinder.deobfuscate(blocks);
|
proxyCallFixer.deobfuscate(blocks);
|
||||||
removeAutomatedErrorReportingCode(blocks);
|
removeAutomatedErrorReportingCode(blocks);
|
||||||
removeTamperProtection(blocks);
|
removeTamperProtection(blocks);
|
||||||
removeStringsInitCode(blocks);
|
removeStringsInitCode(blocks);
|
||||||
|
@ -439,7 +439,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
|
|
||||||
public override void deobfuscateEnd() {
|
public override void deobfuscateEnd() {
|
||||||
canRemoveTypes = findBigType() == null;
|
canRemoveTypes = findBigType() == null;
|
||||||
removeProxyDelegates(proxyDelegateFinder, canRemoveTypes);
|
removeProxyDelegates(proxyCallFixer, canRemoveTypes);
|
||||||
removeMemoryManagerStuff();
|
removeMemoryManagerStuff();
|
||||||
removeTamperProtectionStuff();
|
removeTamperProtectionStuff();
|
||||||
removeStringDecryptionStuff();
|
removeStringDecryptionStuff();
|
||||||
|
|
|
@ -24,7 +24,7 @@ using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.SmartAssembly {
|
namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
class ProxyDelegateFinder : ProxyDelegateFinderBase {
|
class ProxyCallFixer : ProxyCallFixer1 {
|
||||||
static readonly Dictionary<char, int> specialCharsDict = new Dictionary<char, int>();
|
static readonly Dictionary<char, int> specialCharsDict = new Dictionary<char, int>();
|
||||||
static readonly char[] specialChars = new char[] {
|
static readonly char[] specialChars = new char[] {
|
||||||
'\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08',
|
'\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08',
|
||||||
|
@ -40,12 +40,12 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
|
||||||
IList<MemberReference> memberReferences;
|
IList<MemberReference> memberReferences;
|
||||||
ISimpleDeobfuscator simpleDeobfuscator;
|
ISimpleDeobfuscator simpleDeobfuscator;
|
||||||
|
|
||||||
static ProxyDelegateFinder() {
|
static ProxyCallFixer() {
|
||||||
for (int i = 0; i < specialChars.Length; i++)
|
for (int i = 0; i < specialChars.Length; i++)
|
||||||
specialCharsDict[specialChars[i]] = i;
|
specialCharsDict[specialChars[i]] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyDelegateFinder(ModuleDefinition module, ISimpleDeobfuscator simpleDeobfuscator)
|
public ProxyCallFixer(ModuleDefinition module, ISimpleDeobfuscator simpleDeobfuscator)
|
||||||
: base(module) {
|
: base(module) {
|
||||||
this.memberReferences = new List<MemberReference>(module.GetMemberReferences());
|
this.memberReferences = new List<MemberReference>(module.GetMemberReferences());
|
||||||
this.simpleDeobfuscator = simpleDeobfuscator;
|
this.simpleDeobfuscator = simpleDeobfuscator;
|
Loading…
Reference in New Issue
Block a user