-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
44 lines (41 loc) · 1.69 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace PrivacyRootPatcher
{
class Utils
{
public static TypeDef[] GetAllNestedTypes(TypeDef type)
{
List<TypeDef> result = new List<TypeDef>();
foreach (TypeDef nsType in type.NestedTypes)
{
if (nsType.HasNestedTypes) { result.AddRange(GetAllNestedTypes(nsType)); }
result.Add(nsType);
}
return result.ToArray();
}
public static TypeDef[] GetAllTypes(ModuleDefMD asm)
{
List<TypeDef> result = new List<TypeDef>();
foreach (TypeDef type in asm.Types)
{
if (type.HasNestedTypes) { result.AddRange(GetAllNestedTypes(type)); }
result.Add(type);
}
return result.ToArray();
}
public static bool CompareMemberRef(Instruction srcInst, Type matchType, string methodName, Type[] methodArgs = null, bool isConstructor = false)
{
string instNamespace = ((MemberRef)srcInst.Operand).DeclaringType.FullName + "." + ((MemberRef)srcInst.Operand).Name,
matchClassNamespace = matchType.FullName,
matchMethodName = "";
if (methodArgs == null) { matchMethodName = matchType.GetMethod(methodName).Name; }
else { matchMethodName = !isConstructor ? matchType.GetMethod(methodName, methodArgs).Name : matchType.GetConstructor(methodArgs).Name; }
return instNamespace == matchClassNamespace + "." + matchMethodName;
}
}
}