Fix merge
This commit is contained in:
parent
71eddd4689
commit
958ad86ceb
|
@ -49,21 +49,19 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string XorCipher(string text, int key) {
|
public static string XorCipher(string text, int key) {
|
||||||
char[] array = text.ToCharArray();
|
var array = text.ToCharArray();
|
||||||
int num = array.Length;
|
int len = array.Length;
|
||||||
char cKey = Convert.ToChar(key);
|
char cKey = Convert.ToChar(key);
|
||||||
while (--num >= 0) {
|
while (--len >= 0)
|
||||||
array[num] ^= cKey;
|
array[len] ^= cKey;
|
||||||
}
|
|
||||||
return new string(array);
|
return new string(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string DecryptResourceName(string resourceName, int key, byte[] coddedBytes) {
|
public static string DecryptResourceName(string resourceName, int key, byte[] coddedBytes) {
|
||||||
int num = resourceName.Length;
|
int len = resourceName.Length;
|
||||||
char[] array = resourceName.ToCharArray();
|
var array = resourceName.ToCharArray();
|
||||||
while (--num >= 0) {
|
while (--len >= 0)
|
||||||
array[num] = (char)((int)array[num] ^ ((int)coddedBytes[key & 15] | key));
|
array[len] = (char)((int)array[len] ^ ((int)coddedBytes[key & 15] | key));
|
||||||
}
|
|
||||||
return new string(array);
|
return new string(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,29 +70,30 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
MethodDef cctor = method, orginalResMethod = null;
|
MethodDef cctor = method, orginalResMethod = null;
|
||||||
// retrive key and encrypted resource name
|
// retrive key and encrypted resource name
|
||||||
int key = 0;
|
int key = 0;
|
||||||
var ils = cctor.Body.Instructions;
|
var instrs = cctor.Body.Instructions;
|
||||||
for (int i = 0; i < ils.Count - 2; i++) {
|
for (int i = 0; i < instrs.Count - 2; i++) {
|
||||||
if (ils[i].OpCode != OpCodes.Ldstr)
|
if (instrs[i].OpCode != OpCodes.Ldstr)
|
||||||
continue;
|
continue;
|
||||||
if (!ils[i + 1].IsLdcI4())
|
if (!instrs[i + 1].IsLdcI4())
|
||||||
break;
|
break;
|
||||||
key = ils[i + 1].GetLdcI4Value();
|
key = instrs[i + 1].GetLdcI4Value();
|
||||||
resourceName = ils[i].Operand as String;
|
resourceName = instrs[i].Operand as String;
|
||||||
cctor = ils[i + 2].Operand as MethodDef;
|
cctor = instrs[i + 2].Operand as MethodDef;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the method that contains resource name
|
// Find the method that contains resource name
|
||||||
while (orginalResMethod == null) {
|
while (orginalResMethod == null) {
|
||||||
foreach (var IL in cctor.Body.Instructions) {
|
foreach (var instr in cctor.Body.Instructions) {
|
||||||
if (IL.OpCode == OpCodes.Ldftn) {
|
if (instr.OpCode == OpCodes.Ldftn) {
|
||||||
MethodDef tempMethod = IL.Operand as MethodDef;
|
MethodDef tempMethod = instr.Operand as MethodDef;
|
||||||
if (tempMethod.ReturnType.FullName != "System.String")
|
if (tempMethod.ReturnType.FullName != "System.String")
|
||||||
continue;
|
continue;
|
||||||
orginalResMethod = tempMethod;
|
orginalResMethod = tempMethod;
|
||||||
break;
|
break;
|
||||||
} else if (IL.OpCode == OpCodes.Callvirt) {
|
}
|
||||||
cctor = IL.Operand as MethodDef;
|
else if (instr.OpCode == OpCodes.Callvirt) {
|
||||||
|
cctor = instr.Operand as MethodDef;
|
||||||
cctor = cctor.DeclaringType.FindStaticConstructor();
|
cctor = cctor.DeclaringType.FindStaticConstructor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -106,10 +105,9 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
// get Decryption key
|
// get Decryption key
|
||||||
int xorKey = 0;
|
int xorKey = 0;
|
||||||
for (int i = 0; i < orginalResMethod.Body.Instructions.Count; i++) {
|
for (int i = 0; i < orginalResMethod.Body.Instructions.Count; i++) {
|
||||||
if (orginalResMethod.Body.Instructions[i].OpCode == OpCodes.Xor) {
|
if (orginalResMethod.Body.Instructions[i].OpCode == OpCodes.Xor)
|
||||||
xorKey = orginalResMethod.Body.Instructions[i - 1].GetLdcI4Value();
|
xorKey = orginalResMethod.Body.Instructions[i - 1].GetLdcI4Value();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
encResourcename = XorCipher(encResourcename, xorKey);
|
encResourcename = XorCipher(encResourcename, xorKey);
|
||||||
var firstResource = GetResource(module, new string[] { encResourcename });
|
var firstResource = GetResource(module, new string[] { encResourcename });
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using dnlib.IO;
|
using dnlib.IO;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using dnlib.DotNet.Emit;
|
using dnlib.DotNet.Emit;
|
||||||
|
|
|
@ -21,7 +21,6 @@ using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using de4dot.blocks;
|
using de4dot.blocks;
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
|
|
||||||
namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
namespace de4dot.code.deobfuscators.CryptoObfuscator {
|
||||||
class StringDecrypter {
|
class StringDecrypter {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user