temp
parent
10eef16d78
commit
d258738262
|
@ -11,9 +11,14 @@ namespace Obfuz
|
|||
{
|
||||
public class ObfuscationMethodWhitelist
|
||||
{
|
||||
private bool ShouldBeIgnoredByCustomAttribute(IHasCustomAttribute obj)
|
||||
private bool HasObfuzIgnoreScope(IHasCustomAttribute obj, ObfuzScope targetScope)
|
||||
{
|
||||
return MetaUtil.HasObfuzIgnoreAttribute(obj);
|
||||
ObfuzScope? objScope = MetaUtil.GetObfuzIgnoreScope(obj);
|
||||
if (objScope == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (objScope & targetScope) != 0;
|
||||
}
|
||||
|
||||
public bool IsInWhiteList(ModuleDef module)
|
||||
|
@ -23,7 +28,7 @@ namespace Obfuz
|
|||
{
|
||||
return true;
|
||||
}
|
||||
if (ShouldBeIgnoredByCustomAttribute(module))
|
||||
if (HasObfuzIgnoreScope(module, ObfuzScope.Self))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -40,7 +45,7 @@ namespace Obfuz
|
|||
{
|
||||
return true;
|
||||
}
|
||||
if (ShouldBeIgnoredByCustomAttribute(method))
|
||||
if (HasObfuzIgnoreScope(method, ObfuzScope.Self))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -779,11 +779,40 @@ namespace Obfuz.Utils
|
|||
return result.ToString();
|
||||
}
|
||||
|
||||
public static bool HasObfuzIgnoreAttribute(IHasCustomAttribute obj)
|
||||
public static ObfuzScope? GetObfuzIgnoreScope(IHasCustomAttribute obj)
|
||||
{
|
||||
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.ObfuzIgnoreAttribute");
|
||||
var ca = obj.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "Obfuz.ObfuzIgnoreAttribute");
|
||||
if (ca == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var scope = (ObfuzScope)ca.ConstructorArguments[0].Value;
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static ObfuzScope? GetObfuzIgnoreScopeOfSelfOrDeclaringType(TypeDef typeDef)
|
||||
{
|
||||
TypeDef cur = typeDef;
|
||||
while (true)
|
||||
{
|
||||
ObfuzScope? scope = GetObfuzIgnoreScope(cur);
|
||||
if (scope != null)
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
cur = cur.DeclaringType;
|
||||
if (cur == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public static bool HasObfuzIgnoreAttribute(IHasCustomAttribute obj)
|
||||
//{
|
||||
// return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.ObfuzIgnoreAttribute");
|
||||
//}
|
||||
|
||||
public static bool HasCompilerGeneratedAttribute(IHasCustomAttribute obj)
|
||||
{
|
||||
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute");
|
||||
|
@ -794,20 +823,20 @@ namespace Obfuz.Utils
|
|||
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.EncryptFieldAttribute");
|
||||
}
|
||||
|
||||
public static bool HasObfuzIgnoreAttributeInSelfOrParent(TypeDef typeDef)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (HasObfuzIgnoreAttribute(typeDef))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
typeDef = typeDef.DeclaringType;
|
||||
if (typeDef == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//public static bool HasObfuzIgnoreAttributeInSelfOrParent(TypeDef typeDef)
|
||||
//{
|
||||
// while (true)
|
||||
// {
|
||||
// if (HasObfuzIgnoreAttribute(typeDef))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// typeDef = typeDef.DeclaringType;
|
||||
// if (typeDef == null)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,48 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Obfuz
|
||||
{
|
||||
public enum ObfuzScope
|
||||
{
|
||||
None = 0x0,
|
||||
Self = 0x1,
|
||||
Field = 0x2,
|
||||
MethodName = 0x4,
|
||||
MethodParameter = 0x8,
|
||||
MethodBody = 0x10,
|
||||
Method = MethodName | MethodParameter | MethodBody,
|
||||
PropertyName = 020,
|
||||
PropertyGetter = 0x40,
|
||||
PropertySetter = 0x80,
|
||||
Property = PropertyName | PropertyGetter | PropertySetter,
|
||||
EventName = 0x100,
|
||||
EventAdd = 0x200,
|
||||
EventRemove = 0x400,
|
||||
EventFire = 0x800,
|
||||
Event = EventName | EventAdd | EventRemove,
|
||||
|
||||
NestedTypeSelf = 0x1000,
|
||||
NestedTypeField = 0x2000,
|
||||
NestedTypeMethod = 0x4000,
|
||||
NestedTypeProperty = 0x8000,
|
||||
NestedTypeEvent = 0x10000,
|
||||
|
||||
NestedTypeAll = NestedTypeSelf | NestedTypeField | NestedTypeMethod | NestedTypeProperty | NestedTypeEvent,
|
||||
|
||||
Member = Field | Method | Property | Event,
|
||||
MemberAndNestedTypeSelf = Member | NestedTypeSelf,
|
||||
MemberAndNestedTypeAll = Member | NestedTypeAll,
|
||||
SelfAndNestedTypeSelf = Self | NestedTypeSelf,
|
||||
All = Self | MemberAndNestedTypeAll,
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
|
||||
public class ObfuzIgnoreAttribute : Attribute
|
||||
{
|
||||
public ObfuzScope Scope { get; set; }
|
||||
|
||||
public ObfuzIgnoreAttribute(ObfuzScope scope = ObfuzScope.All)
|
||||
{
|
||||
this.Scope = scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue