-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodParser.cs
More file actions
312 lines (299 loc) · 11.8 KB
/
MethodParser.cs
File metadata and controls
312 lines (299 loc) · 11.8 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using MSC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace MSC.Script
{
public class MethodParser
{
public Controller Controller = new Controller();
public CommendLine CMD;
public void ParseMethods(List<Method> list, CommendLine cmd)
{
CMD = cmd;
foreach (Method method in list)
ExecuteMethod(method);
}
public void ExecuteMethod(Method method)
{
switch (method.Type)
{
case MethodType.Config:
Controller.NewConfigDef();
ExecuteInstructions(method);
break;
case MethodType.Request:
Controller.NewRequestDef();
ExecuteInstructions(method);
break;
case MethodType.Print:
case MethodType.Base:
ExecuteInstructions(method);
break;
}
}
public void ExecuteInstructions(Method method)
{
foreach (Instruction inst in method.Instructions)
ExecuteInstruction(inst, method.Type);
}
public void ExecuteInstruction(Instruction inst, MethodType type)
{
inst = ReplaceMemoryStringsOnValue(inst);
switch (type)
{
case MethodType.Base:
ExecuteBaseInstruction(inst);
break;
case MethodType.Request:
ExecuteRequestInstruction(inst);
break;
case MethodType.Print:
ExecutePrintInstruction(inst);
break;
case MethodType.Config:
ExecuteConfigInstruction(inst);
break;
}
}
public void ExecuteRequestInstruction(Instruction line)
{
RequestDef RD = Controller.GetLastRequestDef();
switch (line.Type)
{
case OpCode.RequestManage:
string[] Rs = line.Value.Split('.');
ConfigDef cd = Controller.GetConfigdef(int.Parse(Rs[0]));
RequestDef helper = null;
if (Rs.Length >= 3)
{
try
{
if (Rs[2] == "this")
helper = RD;
else
helper = Controller.GetRequestDef(int.Parse(Rs[2]));
}
catch { }
}
if (Rs[1].ToLower() == "getdata")
RD = GetData(cd, helper);
else if (Rs[1].ToLower() == "postdata")
RD = PostData(cd, helper);
break;
case OpCode.MemoryString:
if (line.Value.ToLower().StartsWith("regex"))
Controller.AddMemodyString(ParseRegex(line.Value));
else if (line.Value.ToLower() == "sourcepage")
Controller.AddMemodyString(RD.GetSourcePage());
else if (line.Value.ToLower() == "cookies")
Controller.AddMemodyString(RD.GetCookies());
else
Controller.AddMemodyString(line.Value);
break;
case OpCode.Ret:
string val = line.Value;
if (line.Value.ToLower().StartsWith("regex"))
val = ParseRegex(line.Value);
else if (line.Value.ToLower() == "sourcepage")
val = RD.GetSourcePage();
else if (line.Value.ToLower() == "cookies")
val = RD.GetCookies();
line.Value = val;
ParseRetModule(line);
break;
case OpCode.SetConfig:
string[] Res = line.Value.Split(':');
ConfigDef cr = Controller.GetConfigdef(int.Parse(Res[0]));
int indexd = line.Value.IndexOf(':');
Instruction doc = Instruction.ReadLine(line.Value.Substring(indexd + 1, line.Value.Length - indexd - 1));
SetConfig(doc, cr);
break;
default:
CMD.OutPuter.AddMessage("The" + line.Type.ToString() + " Module not support on Request method");
break;
}
Controller.SetLastRequestDef(RD);
}
private string ParseRegex(string value)
{
int startindex = value.IndexOf("{");
string[] arr = value.Substring(0, startindex).Split('-');
string indexmemroy = arr[1];
string input = ParseMemoryString("MemoryString-" + indexmemroy);
string pattern = value.Substring(value.IndexOf('{') + 1, value.LastIndexOf("}") - value.IndexOf('{') - indexmemroy.Length);
int indexmatch = 0;
if (arr.Length >= 3) indexmatch = int.Parse(arr[2]);
int grpmatch = 1;
if (arr.Length >= 4) int.Parse(arr[3]);
MatchCollection mc = Regex.Matches(input, pattern);
return mc[indexmatch].Groups[grpmatch].Value;
}
private RequestDef GetData(ConfigDef Cd, RequestDef helper)
{
RequestDef R = new RequestDef();
R.configdef = Cd;
R.Helper = helper;
R.GetData();
return R;
}
private RequestDef PostData(ConfigDef Cd, RequestDef helper)
{
RequestDef R = new RequestDef();
R.configdef = Cd;
R.Helper = helper;
R.PostData();
return R;
}
public string ParseMemoryString(string Script)
{
string[] strRet1 = Script.Split('-');
if (strRet1.Length == 2)
{
if (strRet1[1].ToLower() == "all")
{
string[] strings = Controller.GetAllMemoryString();
foreach (string item in strings)
{
CMD.OutPuter.AddMessage(item, Log.Type.OutPut);
}
return strings.ToString();
}
else if (strRet1[1].ToLower().Contains(":"))
{
string[] startend = strRet1[1].Split(':');
string[] strings = Controller.GetHovertMemoryString(int.Parse(startend[0]), int.Parse(startend[1]));
return strings.ToString();
}
else
{
string outs = Controller.GetMemoryString(int.Parse(strRet1[1]));
return outs;
}
}
else
{
return Script;
}
}
public void ExecutePrintInstruction(Instruction line)
{
switch (line.Type)
{
case OpCode.MemoryString:
Controller.AddMemodyString(line.Value);
break;
case OpCode.Ret:
ParseRetModule(line);
break;
default:
CMD.OutPuter.AddMessage("The " + line.Type.ToString() + " Module not support on Print method");
break;
}
}
private void ParseRetModule(Instruction line)
{
if (line.Value.ToLower().StartsWith(OpCode.MemoryString.ToString().ToLower()))
ParseMemoryString(line.Value);
else CMD.OutPuter.AddMessage(line.Value, Log.Type.OutPut);
}
public void ExecuteBaseInstruction(Instruction line)
{
switch (line.Type)
{
case OpCode.MemoryString:
Controller.AddMemodyString(line.Value);
break;
case OpCode.Ret:
ParseRetModule(line);
break;
default:
CMD.OutPuter.AddMessage("The " + line.Type.ToString() + " Module not support on Base method");
break;
}
}
private void SetConfig(Instruction line, ConfigDef config)
{
switch (line.Type)
{
case OpCode.URL:
string[] URLs = line.Value.Split('|');
if (URLs.Length == 2 && URLs[1] == "1")
config.SetURL(line.Value, true);
else config.SetURL(line.Value);
break;
case OpCode.UserAgent:
config.SetUserAgent(line.Value);
break;
case OpCode.Referer:
config.SetReferer(line.Value);
break;
case OpCode.KeepAlive:
config.SetKeepAlive(line.Value);
break;
case OpCode.Method:
config.SetMethod(line.Value);
break;
case OpCode.DataSet:
config.SetDataSet(line.Value);
break;
case OpCode.PostData:
config.SetPostData(line.Value);
break;
case OpCode.Cookies:
config.SetCookes(line.Value);
break;
case OpCode.ContectType:
config.SetContectType(line.Value);
break;
case OpCode.AllowAutoRedirect:
config.SetAllowAutoRedirect(line.Value);
break;
case OpCode.AddAuthorization:
config.AddAuthorization(line.Value);
break;
case OpCode.Headers:
config.SetHeaders(line.Value);
break;
case OpCode.AddHeader:
config.AddHeaders(line.Value);
break;
case OpCode.TimeOut:
config.SetTimeOut(line.Value);
break;
case OpCode.Gzip:
config.SetGzipDecomprossor(line.Value);
break;
default:
CMD.OutPuter.AddMessage("The " + line.Type.ToString() + " Module not support on Config method");
break;
}
}
public void ExecuteConfigInstruction(Instruction line)
{
if (line.Type == OpCode.MemoryString)
Controller.AddMemodyString(line.Value);
else
SetConfig(line, Controller.GetLastConfigdef());
}
public Instruction ReplaceMemoryStringsOnValue(Instruction line)
{
string pattern = @"\|memorystring-(.*?)\|";
foreach (Match m in Regex.Matches(line.Value, pattern, RegexOptions.IgnoreCase))
{
if (m.Groups.Count == 0)
continue;
if (m.Groups[1].Value == "")
continue;
try {
line.Value = line.Value.Replace(m.Value, ParseMemoryString("memorystring-" + m.Groups[1].Value));
}
catch { }
}
return line;
}
}
}