fix: 修复 ConstFieldAllocator和 RvaDataAllocator的encryption level固定取4导致EncryptionVirtualMachine的Opcode个数超过256时打印了大量"OpCode overflow"警告日志的问题
parent
2576236960
commit
4ad3ed76dc
|
@ -172,7 +172,7 @@ namespace Obfuz.Data
|
|||
{
|
||||
ConstFieldInfo constInfo = _field2Fields[field];
|
||||
IRandom localRandom = _randomCreator(HashUtil.ComputePrimitiveOrStringOrBytesHashCode(constInfo.value));
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, _encryptor, 4);
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, _encryptor, EncryptionScopeInfo.MaxEncryptionLevel, false);
|
||||
int salt = localRandom.NextInt();
|
||||
switch (constInfo.value)
|
||||
{
|
||||
|
|
|
@ -238,7 +238,7 @@ namespace Obfuz.Data
|
|||
int verifyIntValue = 0x12345678;
|
||||
EncryptionScopeInfo encryptionScope = this.EncryptionScope;
|
||||
IRandom verifyRandom = encryptionScope.localRandomCreator(verifyIntValue);
|
||||
int verifyOps = EncryptionUtil.GenerateEncryptionOpCodes(verifyRandom, encryptionScope.encryptor, 4);
|
||||
int verifyOps = EncryptionUtil.GenerateEncryptionOpCodes(verifyRandom, encryptionScope.encryptor, EncryptionScopeInfo.MaxEncryptionLevel, false);
|
||||
int verifySalt = verifyRandom.NextInt();
|
||||
int encryptedVerifyIntValue = encryptionScope.encryptor.Encrypt(verifyIntValue, verifyOps, verifySalt);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -44,6 +45,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
public MethodDef proxyMethod;
|
||||
}
|
||||
private readonly Dictionary<MethodKey, CallInfo> _callMethods = new Dictionary<MethodKey, CallInfo>();
|
||||
private CallObfuscationSettingsFacade _settings;
|
||||
|
||||
public DelegateProxyAllocator()
|
||||
{
|
||||
|
@ -53,6 +55,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
public override void Init()
|
||||
{
|
||||
_delegateInstanceHolderType = CreateDelegateInstanceHolderTypeDef();
|
||||
_settings = CallObfusPass.CurrentSettings;
|
||||
}
|
||||
|
||||
private string AllocateDelegateTypeName(MethodSig delegateInvokeSig)
|
||||
|
@ -241,7 +244,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
|
||||
IRandom localRandom = encryptionScope.localRandomCreator(HashUtil.ComputePrimitiveOrStringOrBytesHashCode(ci.key1));
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, encryptionScope.encryptor, 4);
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, encryptionScope.encryptor, _settings.obfuscationLevel);
|
||||
int salt = localRandom.NextInt();
|
||||
|
||||
int encryptedValue = encryptionScope.encryptor.Encrypt(ci.index, ops, salt);
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace Obfuz
|
|||
|
||||
public class EncryptionScopeInfo
|
||||
{
|
||||
public const int MaxEncryptionLevel = 4;
|
||||
|
||||
public readonly IEncryptor encryptor;
|
||||
public readonly RandomCreator localRandomCreator;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Obfuz.Utils
|
|||
return count;
|
||||
}
|
||||
|
||||
public static int GenerateEncryptionOpCodes(IRandom random, IEncryptor encryptor, int encryptionLevel)
|
||||
public static int GenerateEncryptionOpCodes(IRandom random, IEncryptor encryptor, int encryptionLevel, bool logWarningWhenExceedMaxOps = true)
|
||||
{
|
||||
if (encryptionLevel <= 0 || encryptionLevel > 4)
|
||||
{
|
||||
|
@ -31,9 +31,13 @@ namespace Obfuz.Utils
|
|||
int op = random.NextInt(1, vmOpCodeCount);
|
||||
newOps |= (uint)op;
|
||||
if (newOps > uint.MaxValue)
|
||||
{
|
||||
if (logWarningWhenExceedMaxOps)
|
||||
{
|
||||
Debug.LogWarning($"OpCode overflow. encryptionLevel:{encryptionLevel}, vmOpCodeCount:{vmOpCodeCount}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ops = newOps;
|
||||
|
|
Loading…
Reference in New Issue