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