-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHelpers.cs
106 lines (87 loc) · 3.15 KB
/
Helpers.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
using Beebyte_Deobfuscator.Lookup;
using System.Linq;
using System.Text.RegularExpressions;
namespace Beebyte_Deobfuscator
{
class Helpers
{
public static bool IsValidRegex(string pattern)
{
if (string.IsNullOrEmpty(pattern) || (pattern.Trim().Length == 0))
{
return false;
}
try
{
Regex.Match("", pattern);
}
catch (System.ArgumentException)
{
return false;
}
return true;
}
public static float CompareFieldOffsets(LookupType t1, LookupType t2, LookupModule lookupModel)
{
if (t1.Il2CppType == null || t2.Il2CppType == null)
{
return 1.0f;
}
float comparative_score = 1.0f;
float score_penalty = comparative_score / t1.Fields.Count(f => !f.IsStatic && !f.IsLiteral);
foreach (var f1 in t1.Fields.Select((Value, Index) => new { Value, Index }))
{
LookupField f2 = t2.Fields[f1.Index];
if (f1.Value.Name == f2.Name)
{
return 1.5f;
}
if (!Regex.Match(f1.Value.Name, lookupModel.NamingRegex).Success && f1.Value.Name != f2.Name)
{
return 0.0f;
}
if (f1.Value.IsStatic || f1.Value.IsLiteral)
{
continue;
}
if (f1.Value.Offset != f2.Offset)
{
comparative_score -= score_penalty;
}
}
return comparative_score;
}
public static float CompareFieldTypes(LookupType t1, LookupType t2, LookupModule lookupModel)
{
float comparative_score = 1.0f;
float score_penalty = comparative_score / t1.Fields.Count(f => !f.IsStatic && !f.IsLiteral);
foreach (var f1 in t1.Fields.Select((Value, Index) => new { Value, Index }))
{
LookupField f2 = t2.Fields[f1.Index];
if (f1.Value.Name == f2.Name)
{
return 1.5f;
}
if (!Regex.Match(f1.Value.Name, lookupModel.NamingRegex).Success && f1.Value.Name != f2.Name)
{
return 0.0f;
}
if (f1.Value.IsStatic || f1.Value.IsLiteral)
{
continue;
}
if (f1.Value.GetType().Namespace == "System" && f2.GetType().Namespace == "System" && f1.Value.Name == f2.Name)
{
comparative_score -= score_penalty;
}
}
return comparative_score;
}
public static string SanitizeFileName(string name)
{
string invalidChars = Regex.Escape(new string(System.IO.Path.GetInvalidFileNameChars()));
string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars);
return Regex.Replace(name, invalidRegStr, "_");
}
}
}