-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
66 lines (59 loc) · 2.23 KB
/
Utils.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace TransformiceSWFExtractor
{
static class Utils
{
public static void Each<T>(this IEnumerable<T> ie, Action<T, int> action)
{
var i = 0;
foreach (var e in ie) action(e, i++);
}
public static String findStringByParam(String param, String input)
{
var regex = new Regex(Regex.Escape(param) + @":<q>\[public\]::(.*?) = (.*?)\r\n");
var match = regex.Match(input);
return match.Success ? match.Groups[2].Value : null;
}
public static int findIntByParam(String param, String input)
{
String strvalue = findStringByParam(param, input);
strvalue = strvalue.Split('.')[0];
int intvalue;
return int.TryParse(strvalue, out intvalue) ? intvalue : -1;
}
public static int getFunctionValueInt(String functionName, List<String> input)
{
// todo: search with params number
var regex = new Regex(Regex.Escape(functionName) + @"=\(\)\(0 params, 0 optional\)", RegexOptions.Compiled);
var declarationRegex = new Regex(@"push(byte|short|int) (-|)(\d+)$", RegexOptions.Compiled);
int output = 0;
input.Each((line, n) =>
{
var match = regex.Match(line);
if (match.Success)
{
// function found
for (int i = 0; i < 20; i++)
{
// search for values
var thisline = input[n + i];
if (thisline.Contains("returnvalue")) {
break;
}
var declarationMatch = declarationRegex.Match(thisline);
if (declarationMatch.Success)
{
output += int.Parse(declarationMatch.Groups[2].Value + declarationMatch.Groups[3].Value);
}
}
}
});
return output;
}
}
}