Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
26b4828094 | |
|
|
2d9782fdb7 | |
|
|
830d61cc48 |
|
|
@ -38,13 +38,20 @@ namespace Obfuz.Emit
|
|||
|
||||
public IList<BasicBlock> Blocks => _blocks;
|
||||
|
||||
public BasicBlockCollection(MethodDef method)
|
||||
public BasicBlockCollection(MethodDef method, bool computeInLoop)
|
||||
{
|
||||
_method = method;
|
||||
HashSet<Instruction> splitPoints = BuildSplitPoint(method);
|
||||
BuildBasicBlocks(method, splitPoints);
|
||||
BuildInOutGraph(method);
|
||||
if (computeInLoop)
|
||||
{
|
||||
ComputeBlocksInLoop();
|
||||
}
|
||||
}
|
||||
|
||||
public void ComputeBlocksInLoop()
|
||||
{
|
||||
var loopBlocks = FindLoopBlocks(_blocks);
|
||||
foreach (var block in loopBlocks)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ namespace Obfuz.ObfusPasses
|
|||
{
|
||||
protected abstract bool NeedObfuscateMethod(MethodDef method);
|
||||
|
||||
protected virtual bool ComputeBlockInLoop => true;
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
|
|
@ -48,7 +50,7 @@ namespace Obfuz.ObfusPasses
|
|||
|
||||
private void ObfuscateData(MethodDef method)
|
||||
{
|
||||
BasicBlockCollection bbc = new BasicBlockCollection(method);
|
||||
BasicBlockCollection bbc = new BasicBlockCollection(method, ComputeBlockInLoop);
|
||||
|
||||
IList<Instruction> instructions = method.Body.Instructions;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,13 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
{
|
||||
public class ReflectionCompatibilityDetector
|
||||
{
|
||||
private readonly HashSet<ModuleDef> _assembliesToObfuscate;
|
||||
private readonly List<ModuleDef> _obfuscatedAndNotObfuscatedModules;
|
||||
private readonly IObfuscationPolicy _renamePolicy;
|
||||
|
||||
public ReflectionCompatibilityDetector(List<ModuleDef> obfuscatedAndNotObfuscatedModules, IObfuscationPolicy renamePolicy)
|
||||
public ReflectionCompatibilityDetector(List<ModuleDef> assembliesToObfuscate, List<ModuleDef> obfuscatedAndNotObfuscatedModules, IObfuscationPolicy renamePolicy)
|
||||
{
|
||||
_assembliesToObfuscate = new HashSet<ModuleDef>(assembliesToObfuscate);
|
||||
_obfuscatedAndNotObfuscatedModules = obfuscatedAndNotObfuscatedModules;
|
||||
_renamePolicy = renamePolicy;
|
||||
}
|
||||
|
|
@ -137,7 +139,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
|
||||
private bool IsAnyEnumItemRenamed(TypeDef typeDef)
|
||||
{
|
||||
return typeDef.Fields.Any(f => _renamePolicy.NeedRename(f));
|
||||
return _assembliesToObfuscate.Contains(typeDef.Module) && typeDef.Fields.Any(f => _renamePolicy.NeedRename(f));
|
||||
}
|
||||
|
||||
private void AnalyzeCallvir(IMethod calledMethod, ITypeDefOrRef constrainedType)
|
||||
|
|
@ -188,20 +190,28 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
private void AnalyzeEnum(IMethod method, TypeDef typeDef)
|
||||
{
|
||||
const int extraSearchInstructionCount = 3;
|
||||
TypeDef parseType = GetMethodGenericParameter(method)?.ToTypeDefOrRef()?.ResolveTypeDef();
|
||||
TypeSig parseTypeSig = GetMethodGenericParameter(method);
|
||||
TypeDef parseType = parseTypeSig?.ToTypeDefOrRef().ResolveTypeDef();
|
||||
switch (method.Name)
|
||||
{
|
||||
case "Parse":
|
||||
{
|
||||
if (parseType != null)
|
||||
if (parseTypeSig != null)
|
||||
{
|
||||
// Enum.Parse<T>(string name) or Enum.Parse<T>(string name, bool caseInsensitive)
|
||||
if (parseType != null)
|
||||
{
|
||||
if (IsAnyEnumItemRenamed(parseType))
|
||||
{
|
||||
Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse<T> field of T:{parseType.FullName} is renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse<T> field of T should not be renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Enum.Parse(Type type, string name) or Enum.Parse(Type type, string name, bool ignoreCase)
|
||||
TypeDef enumType = FindLatestTypeOf(method.GetParamCount() + extraSearchInstructionCount)?.ResolveTypeDef();
|
||||
|
|
@ -218,15 +228,22 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
}
|
||||
case "TryParse":
|
||||
{
|
||||
if (parseType != null)
|
||||
if (parseTypeSig != null)
|
||||
{
|
||||
// Enum.TryParse<T>(string name, out T result) or Enum.TryParse<T>(string name, bool ignoreCase, out T result)
|
||||
if (parseType != null)
|
||||
{
|
||||
if (IsAnyEnumItemRenamed(parseType))
|
||||
{
|
||||
Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse<T> field of T:{parseType.FullName} is renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse<T> field of T should not be renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("impossible");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
PrecomputeNeedRename();
|
||||
if (_detectReflectionCompatibility)
|
||||
{
|
||||
var reflectionCompatibilityDetector = new ReflectionCompatibilityDetector(_obfuscatedAndNotObfuscatedModules, _renamePolicy);
|
||||
var reflectionCompatibilityDetector = new ReflectionCompatibilityDetector(_toObfuscatedModules, _obfuscatedAndNotObfuscatedModules, _renamePolicy);
|
||||
reflectionCompatibilityDetector.Analyze();
|
||||
}
|
||||
RenameTypes();
|
||||
|
|
|
|||
Loading…
Reference in New Issue