@@ -10,63 +10,6 @@ namespace UnityHelper.ModSystem
1010{
1111 public class ModScanner
1212 {
13- // Instance field to store the setting
14- private readonly bool _banAllInNamespace ;
15-
16- // --- Dangerous Types ---
17- // Use StartsWith for namespaces (include trailing '.' if needed)
18- // Use exact full names for specific classes
19- private static readonly string [ ] DangerousTypes =
20- {
21- // Namespaces (match anything within)
22- "System.IO." ,
23- "System.Net." ,
24- "System.Reflection.Emit." ,
25- "System.Runtime.InteropServices." ,
26- "System.Security.AccessControl." ,
27- "System.Management." ,
28- "System.IO.IsolatedStorage." ,
29-
30- // Specific Classes (match exactly)
31- "System.Diagnostics.Process" ,
32- "System.Reflection.Assembly" // Loading/interacting with assemblies directly
33- // Add other specific dangerous classes here if needed
34- } ;
35-
36- // --- Dangerous Methods ---
37- // These are checked *in combination* with DangerousTypes
38- private static readonly string [ ] DangerousMethods =
39- {
40- // IO Methods
41- "Delete" , "Move" , "CreateDirectory" , "Copy" , "AppendAllText" , "WriteAllBytes" , "WriteAllText" ,
42- "SetAccessControl" , "AddAccessRule" , "RemoveAccessRule" , "SetAccessRule" , "GetAccessControl" ,
43- "Open" , "Create" , // FileStream constructors are often just ".ctor", so check common factory methods too
44-
45- // Process Methods
46- "Start" , "Kill" , "GetProcesses" ,
47-
48- // Reflection/Assembly Methods
49- "Load" , "LoadFrom" , "LoadFile" , "GetExecutingAssembly" , "Invoke" , // Check context carefully
50- "CreateInstance" , // System.Activator
51-
52- // Networking Methods
53- "Connect" , "Bind" , "Listen" , "Send" , "Receive" , "GetResponse" , "DownloadFile" ,
54- "UploadFile" , // Check common methods on Socket, TcpClient, WebClient etc.
55-
56- // Interop Methods
57- "GetDelegateForFunctionPointer" , "PtrToStructure" , "StructureToPtr" ,
58-
59- // Add other specific dangerous method names
60- ".ctor" // Check constructors of dangerous types explicitly if needed
61- } ;
62-
63-
64- // Constructor
65- public ModScanner ( bool banAllInNamespace = false )
66- {
67- _banAllInNamespace = banAllInNamespace ;
68- }
69-
7013 public bool IsModSafe ( string dllPath )
7114 {
7215 try
@@ -152,7 +95,7 @@ public bool IsModSafe(string dllPath)
15295 if ( typeIsDangerous )
15396 {
15497 // If banning all in namespace is enabled, and the type is dangerous, fail immediately.
155- if ( _banAllInNamespace )
98+ if ( UnityHelperAddon . UnityHelper . BanAllNamespaces ( ) )
15699 {
157100 Debug . LogWarning ( $ "[SECURITY] Dangerous type '{ methodRef . DeclaringType . FullName } ' used (namespace ban active). Banned method call: { methodRef . FullName } ") ;
158101 return false ;
@@ -161,7 +104,7 @@ public bool IsModSafe(string dllPath)
161104 else
162105 {
163106 string methodName = methodRef . Name ;
164- bool methodIsDangerous = DangerousMethods . Any ( dangerousMethodName => methodName == dangerousMethodName ) ;
107+ bool methodIsDangerous = UnityHelperAddon . UnityHelper . DangerousMethods ( ) . Any ( dangerousMethodName => methodName == dangerousMethodName ) ;
165108 if ( methodIsDangerous )
166109 {
167110 Debug . LogWarning ( $ "[SECURITY] Dangerous method call detected in '{ method . FullName } ': Call to { methodRef . FullName } (Type and Method match)") ;
@@ -252,7 +195,7 @@ private bool IsDangerousType(TypeReference typeRef)
252195 fullName = fullName . Replace ( "&" , "" ) ; // Remove by-ref marker
253196
254197 // Inside IsDangerousType, before the final return
255- var isMatch = DangerousTypes . Any ( dangerous =>
198+ var isMatch = UnityHelperAddon . UnityHelper . DangerousTypes ( ) . Any ( dangerous =>
256199 fullName . Equals ( dangerous , StringComparison . Ordinal ) ||
257200 ( dangerous . EndsWith ( "." ) && fullName . StartsWith ( dangerous , StringComparison . Ordinal ) )
258201 ) ;
@@ -279,7 +222,7 @@ private bool IsDangerousMethodCall(MethodReference methodRef)
279222 }
280223
281224 string methodName = methodRef . Name ;
282- bool methodIsDangerous = DangerousMethods . Any ( dangerousMethodName => methodName == dangerousMethodName ) ;
225+ bool methodIsDangerous = UnityHelperAddon . UnityHelper . DangerousMethods ( ) . Any ( dangerousMethodName => methodName == dangerousMethodName ) ;
283226 Debug . Log ( $ "[ScannerDebug] IsDangerousMethodCall Check: MethodName='{ methodName } ', NameInList={ methodIsDangerous } ") ;
284227
285228 return methodIsDangerous ;
0 commit comments