@@ -10,6 +10,8 @@ namespace Reloaded.Injector.Interop
1010{
1111 internal static unsafe class ModuleCollector
1212 {
13+ private static StringBuilder _modulePathBuilder = new StringBuilder ( 32767 ) ;
14+
1315 /// <exception cref="DllInjectorException">Bytes to fill module list returned 0. The process is probably not yet initialized.</exception>
1416 public static List < Module > CollectModules ( Process process )
1517 {
@@ -18,7 +20,6 @@ public static List<Module> CollectModules(Process process)
1820 int numberOfModules ;
1921 int bytesNeeded ;
2022
21-
2223 // Determine number of modules.
2324 if ( ! EnumProcessModulesEx ( process . Handle , modulePointers , 0 , out bytesNeeded , ( uint ) ModuleFilter . ListModulesAll ) )
2425 return collectedModules ;
@@ -34,14 +35,13 @@ public static List<Module> CollectModules(Process process)
3435 {
3536 for ( int x = 0 ; x < numberOfModules ; x ++ )
3637 {
37- StringBuilder modulePathBuilder = new StringBuilder ( 32767 ) ;
3838 ModuleInformation moduleInformation = new ModuleInformation ( ) ;
3939
40- GetModuleFileNameEx ( process . Handle , modulePointers [ x ] , modulePathBuilder , ( uint ) ( modulePathBuilder . Capacity ) ) ;
40+ GetModuleFileNameEx ( process . Handle , modulePointers [ x ] , _modulePathBuilder , ( uint ) ( _modulePathBuilder . Capacity ) ) ;
4141 GetModuleInformation ( process . Handle , modulePointers [ x ] , out moduleInformation , ( uint ) sizeof ( ModuleInformation ) ) ;
4242
4343 // Convert to a normalized module and add it to our list
44- string modulePath = modulePathBuilder . ToString ( ) ;
44+ string modulePath = _modulePathBuilder . ToString ( ) ;
4545 Module module = new Module ( modulePath , moduleInformation . lpBaseOfDll , moduleInformation . SizeOfImage , moduleInformation . EntryPoint ) ;
4646 collectedModules . Add ( module ) ;
4747 }
0 commit comments