Skip to content

Commit e5c58bc

Browse files
committed
Updated module searching
1 parent 0d561db commit e5c58bc

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/java/com/beaudoin/jmm/process/impl/win32/Win32Process.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import com.beaudoin.jmm.misc.Cacheable;
2828
import com.beaudoin.jmm.misc.MemoryBuffer;
2929
import com.beaudoin.jmm.natives.win32.Kernel32;
30-
import com.beaudoin.jmm.natives.win32.Psapi;
3130
import com.beaudoin.jmm.process.Module;
3231
import com.beaudoin.jmm.process.NativeProcess;
3332
import com.sun.jna.Native;
3433
import com.sun.jna.Pointer;
34+
import com.sun.jna.platform.win32.Tlhelp32;
3535
import com.sun.jna.platform.win32.Win32Exception;
3636

37+
import java.util.HashMap;
3738
import java.util.Map;
3839

3940
/**
@@ -43,7 +44,7 @@ public final class Win32Process implements NativeProcess {
4344

4445
private final int id;
4546
private final Pointer handle;
46-
private Map<String, Module> modules;
47+
private Map<String, Module> modules = new HashMap<>();
4748

4849
public Win32Process(int id, Pointer handle) {
4950
this.id = id;
@@ -62,7 +63,16 @@ public int id() {
6263

6364
@Override
6465
public void initModules() {
65-
modules = Psapi.getModules(this);
66+
Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPMODULE32.intValue() | Tlhelp32.TH32CS_SNAPMODULE.intValue(), id());
67+
Kernel32.MODULEENTRY32W entry = new Kernel32.MODULEENTRY32W.ByReference();
68+
try {
69+
while (Kernel32.Module32NextW(snapshot, entry)) {
70+
String name = entry.szModule();
71+
modules.put(name, new Module(this, name, entry.getPointer(), entry.modBaseSize.intValue()));
72+
}
73+
} finally {
74+
Kernel32.CloseHandle(snapshot);
75+
}
6676
}
6777

6878
@Override

0 commit comments

Comments
 (0)