Detect anti dump version
This commit is contained in:
parent
f7c1676d1d
commit
5376c74919
|
@ -17,6 +17,7 @@
|
||||||
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
using Mono.Cecil.Cil;
|
using Mono.Cecil.Cil;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
|
@ -25,6 +26,18 @@ namespace de4dot.code.deobfuscators.Confuser {
|
||||||
class AntiDumping : IVersionProvider {
|
class AntiDumping : IVersionProvider {
|
||||||
ModuleDefinition module;
|
ModuleDefinition module;
|
||||||
MethodDefinition initMethod;
|
MethodDefinition initMethod;
|
||||||
|
ConfuserVersion version = ConfuserVersion.Unknown;
|
||||||
|
|
||||||
|
enum ConfuserVersion {
|
||||||
|
Unknown,
|
||||||
|
v14_r58564,
|
||||||
|
v14_r58852,
|
||||||
|
v16_r69339,
|
||||||
|
v17_r74708,
|
||||||
|
v18_r75257,
|
||||||
|
v19_r75725,
|
||||||
|
v19_r76186,
|
||||||
|
}
|
||||||
|
|
||||||
public MethodDefinition InitMethod {
|
public MethodDefinition InitMethod {
|
||||||
get { return initMethod; }
|
get { return initMethod; }
|
||||||
|
@ -57,11 +70,16 @@ namespace de4dot.code.deobfuscators.Confuser {
|
||||||
var calledMethod = instr.Operand as MethodDefinition;
|
var calledMethod = instr.Operand as MethodDefinition;
|
||||||
if (calledMethod == null)
|
if (calledMethod == null)
|
||||||
continue;
|
continue;
|
||||||
|
if (calledMethod == null || !calledMethod.IsStatic)
|
||||||
|
continue;
|
||||||
if (!DotNetUtils.isMethod(calledMethod, "System.Void", "()"))
|
if (!DotNetUtils.isMethod(calledMethod, "System.Void", "()"))
|
||||||
continue;
|
continue;
|
||||||
|
var type = calledMethod.DeclaringType;
|
||||||
|
if (type.NestedTypes.Count > 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
simpleDeobfuscator.deobfuscate(calledMethod, true);
|
simpleDeobfuscator.deobfuscate(calledMethod, true);
|
||||||
if (checkInitMethod_v14_r58852(calledMethod) || checkInitMethod_v14_r58564(calledMethod)) {
|
if (checkType(type, calledMethod)) {
|
||||||
initMethod = calledMethod;
|
initMethod = calledMethod;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -69,54 +87,159 @@ namespace de4dot.code.deobfuscators.Confuser {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkInitMethod_v14_r58564(MethodDefinition method) {
|
bool checkType(TypeDefinition type, MethodDefinition initMethod) {
|
||||||
if (method == null || method.Body == null || !method.IsStatic)
|
return checkType_v14_r58564(type, initMethod) ||
|
||||||
|
checkType_v14_r58852(type, initMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkType_v14_r58564(TypeDefinition type, MethodDefinition initMethod) {
|
||||||
|
var virtualProtect = DotNetUtils.getPInvokeMethod(type, "VirtualProtect");
|
||||||
|
if (virtualProtect == null)
|
||||||
return false;
|
return false;
|
||||||
if (!DotNetUtils.isMethod(method, "System.Void", "()"))
|
if (!DotNetUtils.callsMethod(initMethod, "System.IntPtr System.Runtime.InteropServices.Marshal::GetHINSTANCE(System.Reflection.Module)"))
|
||||||
return false;
|
return false;
|
||||||
if (DotNetUtils.getPInvokeMethod(method.DeclaringType, "kernel32", "VirtualProtect") == null)
|
if (ConfuserUtils.countCalls(initMethod, virtualProtect) != 3)
|
||||||
return false;
|
return false;
|
||||||
if (!DeobUtils.hasInteger(method, 224))
|
if (!DeobUtils.hasInteger(initMethod, 224))
|
||||||
return false;
|
return false;
|
||||||
if (!DeobUtils.hasInteger(method, 240))
|
if (!DeobUtils.hasInteger(initMethod, 240))
|
||||||
return false;
|
return false;
|
||||||
if (!DeobUtils.hasInteger(method, 267))
|
if (!DeobUtils.hasInteger(initMethod, 267))
|
||||||
return false;
|
return false;
|
||||||
var type = method.DeclaringType;
|
|
||||||
if (type.Methods.Count != 2)
|
version = ConfuserVersion.v14_r58564;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkType_v14_r58852(TypeDefinition type, MethodDefinition initMethod) {
|
||||||
|
var virtualProtect = DotNetUtils.getPInvokeMethod(type, "VirtualProtect");
|
||||||
|
if (virtualProtect == null)
|
||||||
return false;
|
return false;
|
||||||
if (type.Fields.Count != 0)
|
if (!DotNetUtils.callsMethod(initMethod, "System.IntPtr System.Runtime.InteropServices.Marshal::GetHINSTANCE(System.Reflection.Module)"))
|
||||||
return false;
|
return false;
|
||||||
if (type.Properties.Count != 0)
|
int virtualProtectCalls = ConfuserUtils.countCalls(initMethod, virtualProtect);
|
||||||
|
if (virtualProtectCalls != 14 && virtualProtectCalls != 16)
|
||||||
|
return false;
|
||||||
|
if (!DeobUtils.hasInteger(initMethod, 0x3C))
|
||||||
|
return false;
|
||||||
|
if (!DeobUtils.hasInteger(initMethod, 0x6c64746e))
|
||||||
|
return false;
|
||||||
|
if (!DeobUtils.hasInteger(initMethod, 0x6c642e6c))
|
||||||
|
return false;
|
||||||
|
if (!DeobUtils.hasInteger(initMethod, 0x6f43744e))
|
||||||
|
return false;
|
||||||
|
if (!DeobUtils.hasInteger(initMethod, 0x6e69746e))
|
||||||
|
return false;
|
||||||
|
int locallocs = ConfuserUtils.countOpCode(initMethod, Code.Localloc);
|
||||||
|
|
||||||
|
if (DeobUtils.hasInteger(initMethod, 0x18))
|
||||||
|
version = ConfuserVersion.v14_r58852;
|
||||||
|
else if (virtualProtectCalls == 16)
|
||||||
|
version = ConfuserVersion.v16_r69339;
|
||||||
|
else if (virtualProtectCalls == 14) {
|
||||||
|
if (locallocs == 2)
|
||||||
|
version = ConfuserVersion.v17_r74708;
|
||||||
|
else if (locallocs == 1) {
|
||||||
|
if (DotNetUtils.hasString(initMethod, "<Unknown>"))
|
||||||
|
version = ConfuserVersion.v18_r75257;
|
||||||
|
else if (isRev75725(initMethod))
|
||||||
|
version = ConfuserVersion.v19_r75725;
|
||||||
|
else
|
||||||
|
version = ConfuserVersion.v19_r76186;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkInitMethod_v14_r58852(MethodDefinition method) {
|
static bool isRev75725(MethodDefinition method) {
|
||||||
if (method == null || method.Body == null || !method.IsStatic)
|
var instrs = method.Body.Instructions;
|
||||||
return false;
|
for (int i = 0; i < instrs.Count - 9; i++) {
|
||||||
if (!DotNetUtils.isMethod(method, "System.Void", "()"))
|
if (!DotNetUtils.isLdcI4(instrs[i]) || DotNetUtils.getLdcI4Value(instrs[i]) != 8)
|
||||||
return false;
|
continue;
|
||||||
if (!DeobUtils.hasInteger(method, 0x3C))
|
if (!DotNetUtils.isLdcI4(instrs[i + 1]) || DotNetUtils.getLdcI4Value(instrs[i + 1]) != 64)
|
||||||
return false;
|
continue;
|
||||||
if (!DeobUtils.hasInteger(method, 0x6c64746e))
|
if (instrs[i + 2].OpCode.Code != Code.Ldloca && instrs[i + 2].OpCode.Code != Code.Ldloca_S)
|
||||||
return false;
|
continue;
|
||||||
if (!DeobUtils.hasInteger(method, 0x6c642e6c))
|
var call = instrs[i + 3];
|
||||||
return false;
|
if (call.OpCode.Code != Code.Call)
|
||||||
if (!DeobUtils.hasInteger(method, 0x6f43744e))
|
continue;
|
||||||
return false;
|
var calledMethod = call.Operand as MethodDefinition;
|
||||||
if (!DeobUtils.hasInteger(method, 0x6e69746e))
|
if (calledMethod == null || calledMethod.PInvokeInfo == null || calledMethod.PInvokeInfo.EntryPoint != "VirtualProtect")
|
||||||
return false;
|
continue;
|
||||||
if (DotNetUtils.getPInvokeMethod(method.DeclaringType, "kernel32", "VirtualProtect") == null)
|
if (instrs[i + 4].OpCode.Code != Code.Pop)
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
return true;
|
var ldloc = instrs[i + 5];
|
||||||
|
if (!DotNetUtils.isLdloc(ldloc))
|
||||||
|
continue;
|
||||||
|
var local = DotNetUtils.getLocalVar(method.Body.Variables, ldloc);
|
||||||
|
if (local == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!DotNetUtils.isLdcI4(instrs[i + 6]) || DotNetUtils.getLdcI4Value(instrs[i + 6]) != 0)
|
||||||
|
continue;
|
||||||
|
if (instrs[i + 7].OpCode.Code != Code.Stind_I4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ldloc = instrs[i + 8];
|
||||||
|
if (!DotNetUtils.isLdloc(ldloc) || local != DotNetUtils.getLocalVar(method.Body.Variables, ldloc))
|
||||||
|
continue;
|
||||||
|
if (!DotNetUtils.isLdcI4(instrs[i + 9]) || DotNetUtils.getLdcI4Value(instrs[i + 9]) != 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool getRevisionRange(out int minRev, out int maxRev) {
|
public bool getRevisionRange(out int minRev, out int maxRev) {
|
||||||
minRev = maxRev = 0;
|
switch (version) {
|
||||||
return false;
|
case ConfuserVersion.Unknown:
|
||||||
|
minRev = maxRev = 0;
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case ConfuserVersion.v14_r58564:
|
||||||
|
minRev = 58564;
|
||||||
|
maxRev = 58817;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v14_r58852:
|
||||||
|
minRev = 58852;
|
||||||
|
maxRev = 67058;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v16_r69339:
|
||||||
|
minRev = 69339;
|
||||||
|
maxRev = 74637;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v17_r74708:
|
||||||
|
minRev = 74708;
|
||||||
|
maxRev = 75184;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v18_r75257:
|
||||||
|
minRev = 75257;
|
||||||
|
maxRev = 75720;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v19_r75725:
|
||||||
|
minRev = 75725;
|
||||||
|
maxRev = 76163;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ConfuserVersion.v19_r76186:
|
||||||
|
minRev = 76186;
|
||||||
|
maxRev = int.MaxValue;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default: throw new ApplicationException("Invalid version");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user