-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathProhibitString.cs
More file actions
54 lines (48 loc) · 1.32 KB
/
ProhibitString.cs
File metadata and controls
54 lines (48 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Reflection;
namespace Waher.Security.CallStack
{
/// <summary>
/// Checks for prohibited sources in the call stack using a string.
/// </summary>
public class ProhibitString : CallStackCheck
{
private readonly string s;
/// <summary>
/// Checks for prohibited sources in the call stack using a string.
/// </summary>
public ProhibitString(string String)
{
this.s = String;
}
/// <summary>
/// Performs a check of a stack frame.
/// </summary>
/// <param name="Frame">Stack frame.</param>
/// <returns>
/// true, if frame represents a valid frame, and the check can conclude positively.
/// false, if frame represents a prohibited frame, and the check can conclude negatively.
/// null, if the frame is not conclusive, and the check should continue with the next frame.
/// </returns>
public override bool? Check(FrameInformation Frame)
{
if (Frame.TypeName + "." + Frame.Method.Name == this.s ||
Frame.TypeName == this.s ||
Frame.AssemblyName == this.s)
{
return false;
}
Type T = Frame.Type;
while (!(T is null) && T.Attributes.HasFlag(TypeAttributes.NestedPrivate))
{
T = T.DeclaringType;
if (T.FullName + "." + Frame.Method.Name == this.s ||
T.FullName == this.s)
{
return false;
}
}
return null;
}
}
}