RvaData支持加密
parent
0ad6422b7b
commit
6bc9192c13
|
@ -39,6 +39,7 @@ namespace Obfuz.Emit
|
|||
public FieldDef runtimeValueField;
|
||||
public uint size;
|
||||
public List<byte> bytes;
|
||||
public int minorSecret;
|
||||
|
||||
public void FillPadding()
|
||||
{
|
||||
|
@ -118,6 +119,7 @@ namespace Obfuz.Emit
|
|||
runtimeValueField = runtimeValueField,
|
||||
size = dataHolderType.ClassSize,
|
||||
bytes = new List<byte>((int)dataHolderType.ClassSize),
|
||||
minorSecret = _random.NextInt(),
|
||||
};
|
||||
_rvaFields.Add(newRvaField);
|
||||
return newRvaField;
|
||||
|
@ -222,9 +224,10 @@ namespace Obfuz.Emit
|
|||
cctor.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
IMethod method = mod.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
||||
IMethod initializeArrayMethod = mod.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
||||
IMethod decryptArrayMethod = mod.Import(typeof(EncryptionService).GetMethod("DecryptBytes", new[] { typeof(byte[]), typeof(int) }));
|
||||
|
||||
Assert.IsNotNull(method);
|
||||
Assert.IsNotNull(initializeArrayMethod);
|
||||
foreach (var field in _rvaFields)
|
||||
{
|
||||
// ldc
|
||||
|
@ -236,11 +239,13 @@ namespace Obfuz.Emit
|
|||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, (int)field.size));
|
||||
ins.Add(Instruction.Create(OpCodes.Newarr, field.runtimeValueField.FieldType.Next.ToTypeDefOrRef()));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Stsfld, field.runtimeValueField));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldtoken, field.holderDataField));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, method));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, initializeArrayMethod));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, field.minorSecret));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, decryptArrayMethod));
|
||||
|
||||
// TODO Decrpyt
|
||||
}
|
||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Obfuz.Virtualization
|
|||
private static IMethod s_convertDouble;
|
||||
|
||||
private static IMethod s_convertString;
|
||||
private static IField s_Encoding_Utf8;
|
||||
//private static IField s_Encoding_Utf8;
|
||||
private static IMethod s_convertBytes;
|
||||
|
||||
private void InitImportMetadatas(ModuleDef mod)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
public static class EncryptionService
|
||||
{
|
||||
public static void DecryptBytes(byte[] data, int minorSecret)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue