@@ -10,6 +10,8 @@ namespace Reloaded.Injector.Interop
10
10
{
11
11
internal static unsafe class ModuleCollector
12
12
{
13
+ private static StringBuilder _modulePathBuilder = new StringBuilder ( 32767 ) ;
14
+
13
15
/// <exception cref="DllInjectorException">Bytes to fill module list returned 0. The process is probably not yet initialized.</exception>
14
16
public static List < Module > CollectModules ( Process process )
15
17
{
@@ -18,7 +20,6 @@ public static List<Module> CollectModules(Process process)
18
20
int numberOfModules ;
19
21
int bytesNeeded ;
20
22
21
-
22
23
// Determine number of modules.
23
24
if ( ! EnumProcessModulesEx ( process . Handle , modulePointers , 0 , out bytesNeeded , ( uint ) ModuleFilter . ListModulesAll ) )
24
25
return collectedModules ;
@@ -34,14 +35,13 @@ public static List<Module> CollectModules(Process process)
34
35
{
35
36
for ( int x = 0 ; x < numberOfModules ; x ++ )
36
37
{
37
- StringBuilder modulePathBuilder = new StringBuilder ( 32767 ) ;
38
38
ModuleInformation moduleInformation = new ModuleInformation ( ) ;
39
39
40
- GetModuleFileNameEx ( process . Handle , modulePointers [ x ] , modulePathBuilder , ( uint ) ( modulePathBuilder . Capacity ) ) ;
40
+ GetModuleFileNameEx ( process . Handle , modulePointers [ x ] , _modulePathBuilder , ( uint ) ( _modulePathBuilder . Capacity ) ) ;
41
41
GetModuleInformation ( process . Handle , modulePointers [ x ] , out moduleInformation , ( uint ) sizeof ( ModuleInformation ) ) ;
42
42
43
43
// Convert to a normalized module and add it to our list
44
- string modulePath = modulePathBuilder . ToString ( ) ;
44
+ string modulePath = _modulePathBuilder . ToString ( ) ;
45
45
Module module = new Module ( modulePath , moduleInformation . lpBaseOfDll , moduleInformation . SizeOfImage , moduleInformation . EntryPoint ) ;
46
46
collectedModules . Add ( module ) ;
47
47
}
0 commit comments