fix: fix the bug that ConstEncryptPass::TryObfuscateInstruction didn't obfuscation ldc_i4_xxx because their OperandType is None

before-split
walon 2025-05-19 12:55:26 +08:00
parent 6306a5604a
commit a40a45e8aa
1 changed files with 51 additions and 65 deletions

View File

@ -49,85 +49,71 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
{
bool currentInLoop = block.inLoop;
ConstCachePolicy constCachePolicy = _dataObfuscatorPolicy.GetMethodConstCachePolicy(method);
switch (inst.OpCode.OperandType)
{
case OperandType.InlineI:
case OperandType.InlineI8:
case OperandType.ShortInlineI:
case OperandType.ShortInlineR:
case OperandType.InlineR:
{
bool needCache = currentInLoop ? constCachePolicy.cacheConstInLoop : constCachePolicy.cacheConstNotInLoop;
object operand = inst.Operand;
if (operand is int)
switch (inst.OpCode.Code)
{
int value = (int)operand;
case Code.Ldc_I4:
case Code.Ldc_I4_S:
case Code.Ldc_I4_0:
case Code.Ldc_I4_1:
case Code.Ldc_I4_2:
case Code.Ldc_I4_3:
case Code.Ldc_I4_4:
case Code.Ldc_I4_5:
case Code.Ldc_I4_6:
case Code.Ldc_I4_7:
case Code.Ldc_I4_8:
case Code.Ldc_I4_M1:
{
int value = inst.GetLdcI4Value();
if (_dataObfuscatorPolicy.NeedObfuscateInt(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateInt(method, needCache, value, outputInstructions);
return true;
}
return false;
}
else if (operand is sbyte)
case Code.Ldc_I8:
{
int value = (sbyte)operand;
if (_dataObfuscatorPolicy.NeedObfuscateInt(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateInt(method, needCache, value, outputInstructions);
return true;
}
}
else if (operand is byte)
{
int value = (byte)operand;
if (_dataObfuscatorPolicy.NeedObfuscateInt(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateInt(method, needCache, value, outputInstructions);
return true;
}
}
else if (operand is long)
{
long value = (long)operand;
long value = (long)inst.Operand;
if (_dataObfuscatorPolicy.NeedObfuscateLong(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateLong(method, needCache, value, outputInstructions);
return true;
}
return false;
}
else if (operand is float)
case Code.Ldc_R4:
{
float value = (float)operand;
float value = (float)inst.Operand;
if (_dataObfuscatorPolicy.NeedObfuscateFloat(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateFloat(method, needCache, value, outputInstructions);
return true;
}
return false;
}
else if (operand is double)
case Code.Ldc_R8:
{
double value = (double)operand;
double value = (double)inst.Operand;
if (_dataObfuscatorPolicy.NeedObfuscateDouble(method, currentInLoop, value))
{
_dataObfuscator.ObfuscateDouble(method, needCache, value, outputInstructions);
return true;
}
}
return false;
}
case OperandType.InlineString:
case Code.Ldstr:
{
//RuntimeHelpers.InitializeArray
string value = (string)inst.Operand;
if (_dataObfuscatorPolicy.NeedObfuscateString(method, currentInLoop, value))
{
bool needCache = currentInLoop ? constCachePolicy.cacheStringInLoop : constCachePolicy.cacheStringNotInLoop;
_dataObfuscator.ObfuscateString(method, needCache, value, outputInstructions);
return true;
}
return false;
}
case OperandType.InlineMethod:
case Code.Call:
{
//if (((IMethod)inst.Operand).FullName == "System.Void System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(System.Array,System.RuntimeFieldHandle)")
//{