de4dot-cex/de4dot.code/deobfuscators/dotNET_Reactor/v4/BooleanDecrypter.cs

97 lines
2.7 KiB
C#
Raw Normal View History

2011-10-27 02:23:45 +08:00
/*
2014-03-12 05:15:43 +08:00
Copyright (C) 2011-2014 de4dot@gmail.com
2011-10-27 02:23:45 +08:00
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 dnlib.DotNet;
2011-10-27 02:23:45 +08:00
using de4dot.blocks;
namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
2011-10-27 02:23:45 +08:00
class BooleanDecrypter {
2012-11-18 01:57:36 +08:00
ModuleDefMD module;
2011-10-27 02:23:45 +08:00
EncryptedResource encryptedResource;
byte[] fileData;
byte[] decryptedData;
public bool Detected {
2011-11-06 22:24:30 +08:00
get { return encryptedResource.Method != null; }
2011-10-27 02:23:45 +08:00
}
public TypeDef DecrypterType {
get { return encryptedResource.Type; }
}
public MethodDef Method {
2011-11-06 22:24:30 +08:00
get { return encryptedResource.Method; }
2011-10-27 03:05:35 +08:00
}
2011-11-06 22:24:30 +08:00
public EmbeddedResource Resource {
get { return encryptedResource.Resource; }
}
2012-11-18 01:57:36 +08:00
public BooleanDecrypter(ModuleDefMD module) {
2011-10-27 02:23:45 +08:00
this.module = module;
this.encryptedResource = new EncryptedResource(module);
}
2012-11-18 01:57:36 +08:00
public BooleanDecrypter(ModuleDefMD module, BooleanDecrypter oldOne) {
2011-10-27 02:23:45 +08:00
this.module = module;
this.encryptedResource = new EncryptedResource(module, oldOne.encryptedResource);
}
2013-01-19 20:03:57 +08:00
public void Find() {
2011-10-27 02:23:45 +08:00
var additionalTypes = new string[] {
"System.Boolean",
};
foreach (var type in module.Types) {
if (type.BaseType == null || type.BaseType.FullName != "System.Object")
continue;
foreach (var method in type.Methods) {
if (!method.IsStatic || !method.HasBody)
continue;
2013-01-19 20:03:57 +08:00
if (!DotNetUtils.IsMethod(method, "System.Boolean", "(System.Int32)"))
2011-10-27 02:23:45 +08:00
continue;
2013-01-19 20:03:57 +08:00
if (!encryptedResource.CouldBeResourceDecrypter(method, additionalTypes))
2011-10-27 02:23:45 +08:00
continue;
2011-11-06 22:24:30 +08:00
encryptedResource.Method = method;
2011-10-29 08:25:31 +08:00
return;
2011-10-27 02:23:45 +08:00
}
}
}
2013-01-19 20:03:57 +08:00
public void Initialize(byte[] fileData, ISimpleDeobfuscator simpleDeobfuscator) {
2011-11-06 22:24:30 +08:00
if (encryptedResource.Method == null)
2011-10-27 02:23:45 +08:00
return;
this.fileData = fileData;
2013-01-19 20:03:57 +08:00
encryptedResource.Initialize(simpleDeobfuscator);
if (!encryptedResource.FoundResource)
return;
2013-01-19 20:03:57 +08:00
Logger.v("Adding boolean decrypter. Resource: {0}", Utils.ToCsharpString(encryptedResource.Resource.Name));
decryptedData = encryptedResource.Decrypt();
2011-10-27 02:23:45 +08:00
}
2013-01-19 20:03:57 +08:00
public bool Decrypt(int offset) {
2011-10-27 02:23:45 +08:00
uint byteOffset = BitConverter.ToUInt32(decryptedData, offset);
return fileData[byteOffset] == 0x80;
}
}
}