-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAutoDeobfuscator.cs
More file actions
192 lines (145 loc) · 6.08 KB
/
AutoDeobfuscator.cs
File metadata and controls
192 lines (145 loc) · 6.08 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Text.RegularExpressions;
namespace DeobHellper
{
public class AutoDeobfuscator
{
public static string Deobfuscate(string source, string tblSource)
{
string ret;
ret = source;
RenameFunctions(ref ret);
ResolveEB2S(ref ret);
RemoveArrayObfuscation(ref ret, tblSource);
CompactCode(ref source);
ResolveNumbers(ref ret);
ResolveExecute(ref ret);
InsertCredits(ref ret);
return ret;
}
private static void CompactCode(ref string source)
{
// TODO aka neverdo.
}
private static void ResolveNumbers(ref string source)
{
MatchCollection toDo;
toDo = Regex.Matches(source, "Number\\((\"|') (\\w+) (\"|')\\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach(Match tmp in toDo) {
source = source.Replace(tmp.Value, tmp.Groups[2].Value);
}
}
private static void ResolveExecute(ref string source)
{
MatchCollection toDo;
toDo = Regex.Matches(source, "Execute\\((\"|') (\\w+) (\"|')\\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach(Match tmp in toDo) {
source = source.Replace(tmp.Value, tmp.Groups[2].Value);
}
}
private static void RenameFunctions(ref string source)
{
MatchCollection toDo;
toDo = Regex.Matches(source, @"^Func (\w+)\(.*\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
for(int i = 0; i < toDo.Count; i++) {
string replace;
replace = String.Format("{0}\\(",toDo[i].Groups[1].Value);
source = Regex.Replace(source, replace, String.Format("method{0}(", i), RegexOptions.IgnoreCase);
}
}
private static void ResolveEB2S(ref string source)
{
MatchCollection toDo;
toDo = Regex.Matches(source, "Execute\\(BinaryToString\\((\"|')0x[\\dA-F]+(\"|')\\)\\)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
for(int i = 0; i < toDo.Count; i++) {
string workingOn;
Match lastMatch;
workingOn = toDo[i].Value;
while((lastMatch = Regex.Match(workingOn, "Execute\\(BinaryToString\\((\"|')(0x[\\dA-F]+)(\"|')\\)\\)", RegexOptions.IgnoreCase)).Success)
{
workingOn = AutoShit.BinaryToString(lastMatch.Groups[2].Value);
}
source = source.Replace(toDo[i].Value, workingOn);
}
}
private static void RemoveArrayObfuscation(ref string source, string tblSource)
{
string arrayName, decryptName, separator;
string[] values;
MatchCollection toFix;
arrayName = getArrayName(source);
decryptName = getBin2StrName(source, arrayName);
separator = getSeparator(source, arrayName);
values = tblSource.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
toFix = Regex.Matches(source, String.Format("\\$(\\w+) = {0}\\(\\${1}\\[(\\d+)\\]\\)", decryptName, arrayName), RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach(Match tmp in toFix)
{
string varName;
int i;
varName = tmp.Groups[1].Value;
i = int.Parse(tmp.Groups[2].Value);
source = source.Replace(String.Format("${0}", varName), string.Format("\"{0}\"", AutoShit.BinaryToString(values[i-1], false)));
}
// REMOVE THE methodcrypt() CALLS.
toFix = Regex.Matches(source, String.Format("{0}\\((\"|')([\\dA-F]+)(\"|')\\)", decryptName), RegexOptions.Multiline | RegexOptions.IgnoreCase);
foreach(Match tmp in toFix)
{
source = source.Replace(tmp.Value, String.Format("\"{0}\"", AutoShit.BinaryToString(tmp.Groups[2].Value, false)));
}
RemoveArrayRests(ref source);
}
private static string getArrayName(string source)
{
Match match;
match = Regex.Match(source, "(If NOT IsDeclared\\(\"\\w+\"\\) Then )?Global \\$(\\w+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
if(match.Success)
return match.Groups[2].Value;
else
throw new Exception("Can't find the array name");
}
private static string getBin2StrName(string source, string arrayName)
{
Match match;
match = Regex.Match(source, String.Format("= (\\w+)\\(\\${0}\\[\\d+\\]\\)", arrayName), RegexOptions.Multiline | RegexOptions.IgnoreCase);
if(match.Success)
return match.Groups[1].Value;
else
throw new Exception("Can't find the decrypt method name");
}
private static string getSeparator(string source, string arrayName)
{
Match match;
match = Regex.Match(source, string.Format("Global (\\$\\w+, )?\\${0} = StringSplit\\(FileRead\\(\\$\\w+\\),('|\")(.+)('|\")(,\\d+)?\\)", arrayName), RegexOptions.Multiline | RegexOptions.IgnoreCase);
if(match.Success)
return match.Groups[3].Value;
else
throw new Exception("Can't find the separator");
}
private static void RemoveArrayRests(ref string source)
{
source = Regex.Replace(source, "#OnAutoItStartRegister +\"(\\w+)\"", String.Empty, RegexOptions.Multiline | RegexOptions.IgnoreCase);
source = Regex.Replace(source, "Global \".+", String.Empty, RegexOptions.Multiline | RegexOptions.IgnoreCase);
source = Regex.Replace(source, "If NOT IsDeclared\\(\"\\w+\"\\) Then Global \\$\\w+", String.Empty, RegexOptions.Multiline | RegexOptions.IgnoreCase);
}
private static void InsertCredits(ref string source)
{
string credits;
credits = ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"+
"; ;\n"+
"; DEOBFUSCATED WITH DEOBHELLPER ;\n"+
"; ;\n"+
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"+
"; ;\n"+
"; Author: V0K3 (v0k3@inventati.org) ;\n"+
"; Site: http://inforge.net ;\n"+
"; Version: 0.3 ;\n"+
"; ;\n"+
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"+
"; ;\n"+
"; FUCK THE TOY ;\n"+
"; ;\n"+
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";
source = credits + source;
}
}
}