[windows] Use windows.NewLazySystemDLL to (possibly) prevent DLL hijacking

Might be useless because of https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications
but better be safe than sorry.

Ref: https://github.com/shirou/gopsutil/issues/570#issuecomment-413951653
pull/576/head
Lomanic 7 years ago
parent 68ff0e2996
commit ef54649286

@ -47,10 +47,10 @@ const (
) )
var ( var (
Modkernel32 = windows.NewLazyDLL("kernel32.dll") Modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
ModNt = windows.NewLazyDLL("ntdll.dll") ModNt = windows.NewLazySystemDLL("ntdll.dll")
ModPdh = windows.NewLazyDLL("pdh.dll") ModPdh = windows.NewLazySystemDLL("pdh.dll")
ModPsapi = windows.NewLazyDLL("psapi.dll") ModPsapi = windows.NewLazySystemDLL("psapi.dll")
ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes")
ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation")

@ -13,7 +13,7 @@ import (
) )
var ( var (
modiphlpapi = windows.NewLazyDLL("iphlpapi.dll") modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable") procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable")
procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable") procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable")
) )

@ -25,7 +25,7 @@ const (
) )
var ( var (
modpsapi = windows.NewLazyDLL("psapi.dll") modpsapi = windows.NewLazySystemDLL("psapi.dll")
procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo") procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo")
) )

Loading…
Cancel
Save