-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
164 lines (131 loc) · 5.04 KB
/
Main.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System.Text;
using System.Text.RegularExpressions;
namespace halcyon;
public partial class Main : Form
{
public Main()
{
InitializeComponent();
txtSource.Text = Clipboard.GetText();
txtSource.SelectionLength = 0;
txtSource.SelectionStart = 0;
}
private void txtSource_TextChanged(object sender, EventArgs e)
{
var source = txtSource.Text;
txtTarget.Text = Process(source);
}
private static readonly string[] AsyncBullshit = {
"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
"System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult",
"System.Runtime.CompilerServices.TaskAwaiter`1.GetResult",
};
private static readonly string[] KnownMiddleware = {
"Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT.ProcessRequestAsync",
};
private string Process(string source)
{
var exceptions = new List<string>();
var target = new StringBuilder();
target.AppendLine();
var depth = -1;
var previousLineWasReplace = false;
foreach (var sourceLine in source.Split("\r\n"))
{
var line = sourceLine;
if(line.Trim() == "")
continue;
void Remove(string rx, string replacement = "")
{
line = Regex.Replace(line, rx, replacement);
}
var isAt = false;
if (line.TrimStart().StartsWith("at "))
{
line = line[(line.IndexOf("at ", StringComparison.Ordinal) + 3)..];
isAt = true;
}
else
{
if (chkUnwarp.Checked)
{
exceptions.Add(target.ToString());
target = new StringBuilder();
}
depth++;
if(depth > 0)
target.AppendLine();
}
// (System.Private.CoreLib, Version=, Culture=, PublicKeyToken=)
if (chkHideAssembly.Checked)
Remove(@"\((\w+((\.| )\w+)*), Version=[^,]+, Culture=[^,]+, [^)]+\)");
var isAsyncBullshit = AsyncBullshit.Any(asyncBs => line.Trim().StartsWith(asyncBs, StringComparison.OrdinalIgnoreCase));
if (chkDenoise.Checked)
{
// d__7.MoveNext
Remove(@"d(_+\d*)?\.MoveNext");
Remove(@"`1");
// .c__DisplayClass0_0+<<MethodName>b__1>
Remove(@"\.?([a-z]*_*)?DisplayClass([a-z\d_]*)");
// +<MethodName>
Remove(@"\.*\+<(\w*)>", @".$1");
// +<<MethodName>g__Awaited|6_0>
// +<<MethodName>b__1>
Remove(@"\.*\+<<(\w+)>([a-z]*_*Awaited(\|[\d_]*)|[a-z]__\d)>", @".$1");
// .<MethodName>b__0
Remove(@"\.*<(\w+)>[a-z][_\d]*", @".$1");
}
if (chkHideAsync.Checked && isAsyncBullshit)
{
if (previousLineWasReplace)
{
continue;
}
previousLineWasReplace = true;
line = "(async)";
}
if (line.Trim().StartsWith("Inner exception "))
{
line = line[(line.IndexOf("Inner exception ", StringComparison.Ordinal) + 16)..];
}
if (chkHideSystem.Checked && isAt && line.Trim().StartsWith("System."))
{
line = "(system)";
}
if (chkHideMicrosoft.Checked && isAt && line.Trim().StartsWith("Microsoft."))
{
line = "(microsoft)";
}
if(line != "(async)")
previousLineWasReplace = false;
if (new[] { "(async)", "(microsoft)", "(system)" }.Any(x => x == line))
{
if(!chkTagNotHide.Checked)
continue;
}
if (isAt && (KnownMiddleware.Any(x => line.Trim().StartsWith(x)) || line.Contains("Middleware.")))
{
if(chkHideMiddleware.Checked)
continue;
}
if(isAt && chkHideMethodCalls.Checked)
continue;
if (!chkUnwarp.Checked)
{
for (var i = 0; i < depth; i++)
if (!chkHideMethodCalls.Checked)
target.Append(" ");
}
if(isAt)
target.Append(" at ");
target.AppendLine(line.Trim());
if (!isAt && !chkHideMethodCalls.Checked)
target.AppendLine();
}
exceptions.Add(target.ToString());
exceptions.Reverse();
return string.Join("\r\n\r\n", exceptions.Select(x => x.Trim())).Trim();
}
}