Skip to content

Instantly share code, notes, and snippets.

@Jire
Created July 18, 2016 05:01
Show Gist options
  • Save Jire/d3611b9e4f79aad952f011fddbe4de84 to your computer and use it in GitHub Desktop.
Save Jire/d3611b9e4f79aad952f011fddbe4de84 to your computer and use it in GitHub Desktop.
val snapshot = JNAKernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPMODULE, Windows.DWORD_ZERO)
val entry = Tlhelp32.MODULEENTRY32W.ByReference()
try {
while (JNAKernel32.Module32NextW(snapshot, entry)) {
val bytes = ByteArray(256)
Psapi.GetModuleBaseNameA(snapshot.pointer, entry.pointer, bytes, bytes.size)
val name = Native.toString(bytes)
println(name)
}
throw IllegalStateException("Could not find module matching \"$moduleName\"")
} finally {
JNAKernel32.CloseHandle(snapshot)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment