winapi

package
v0.0.0-...-e06cd52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	SystemThreadStateInitialized uint32 = iota
	SystemThreadStateReady
	SystemThreadStateRunning
	SystemThreadStateStandby
	SystemThreadStateTerminated
	SystemThreadStateWait
	SystemThreadStateTransition
	SystemThreadStateUnknown
)
View Source
const (
	SystemThreadWaitReasonExecutive kWaitReason = iota
	SystemThreadWaitReasonFreePage
	SystemThreadWaitReasonPageIn
	SystemThreadWaitReasonSystemAllocation
	SystemThreadWaitReasonExecutionDelay
	SystemThreadWaitReasonSuspended
	SystemThreadWaitReasonUserRequest
	SystemThreadWaitReasonEventPairHigh
	SystemThreadWaitReasonEventPairLow
	SystemThreadWaitReasonLpcReceive
	SystemThreadWaitReasonLpcReply
	SystemThreadWaitReasonVirtualMemory
	SystemThreadWaitReasonPageOut
	SystemThreadWaitReasonUnknown
)
View Source
const (
	// Attempt to automatically discover the URL of the PAC file using both DHCP and DNS queries to the local network.
	WINHTTP_AUTOPROXY_AUTO_DETECT = 0x00000001
	// Download the PAC file from the URL specified by lpszAutoConfigUrl in the WINHTTP_AUTOPROXY_OPTIONS structure.
	WINHTTP_AUTOPROXY_CONFIG_URL = 0x00000002
	// Use DHCP to locate the proxy auto-configuration file.
	WINHTTP_AUTO_DETECT_TYPE_DHCP = 0x00000001
	// Use DNS to attempt to locate the proxy auto-configuration file at a well-known location on the domain of the local computer.
	WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002
	// Resolves all host names directly without a proxy.
	WINHTTP_ACCESS_TYPE_NO_PROXY = 0x00000001
)

WINHTTP_AUTOPROXY_OPTIONS https://docs.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_autoproxy_options

View Source
const (
	HundredNSToTick = 0.0000001
)
View Source
const (
	IF_MAX_PHYS_ADDRESS_LENGTH = 32
)

Variables

This section is empty.

Functions

func CalculateProcessCPUUsagePercent

func CalculateProcessCPUUsagePercent(p1, p2 *SystemProcessInformation, delta float64, cpuCount uint8) float64

func EnumWindows

func EnumWindows(enumFunc uintptr, lparam uintptr) (err error)

func GetIfEntry2

func GetIfEntry2(row *MibIfRow2) error

https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getifentry2 On input, the InterfaceLuid or the InterfaceIndex member of the MibIfRow2 must be set to the interface for which to retrieve information.

func GetIsServiceHaveDelayedAutoStartFlag

func GetIsServiceHaveDelayedAutoStartFlag(serviceHandle windows.Handle) (bool, error)

func GetProcessCommandLine

func GetProcessCommandLine(pid uint32) (string, error)

GetProcessCommandLine to read process memory structure called PEB https://docs.microsoft.com/en-us/windows/desktop/api/winternl/ns-winternl-_peb it refers to RTL_USER_PROCESS_PARAMETERS structure, which contains command line string for the process https://docs.microsoft.com/ru-ru/windows/desktop/api/winternl/ns-winternl-_rtl_user_process_parameters

func GetSystemProcessInformation

func GetSystemProcessInformation(omitThreads bool) (map[uint32]*SystemProcessInformation, map[uint32][]*SystemThreadInformation, error)

func GetWindowThreadProcessId

func GetWindowThreadProcessId(hwnd syscall.Handle, str *uint32) (len int32, err error)

func GlobalFree

func GlobalFree(mem *uint16) error

func HttpCloseHandle

func HttpCloseHandle(hInternet HInternet) error

func IsHangWindow

func IsHangWindow(hwnd syscall.Handle) (bool, error)

func ReadProcessMemory

func ReadProcessMemory(processHandle windows.Handle, srcAddr uintptr, dstAddr uintptr, size uintptr) (int, error)

func SetTimeouts

func SetTimeouts(hInternet HInternet, resolveTimeout int, connectTimeout int, sendTimeout int, receiveTimeout int) error

Types

type DiskPerformance

type DiskPerformance struct {
	BytesRead           int64
	BytesWritten        int64
	ReadTime            int64
	WriteTime           int64
	IdleTime            int64
	ReadCount           uint32
	WriteCount          uint32
	QueueDepth          uint32
	SplitCount          uint32
	QueryTime           int64
	StorageDeviceNumber uint32
	StorageManagerName  [8]uint16
}

DISK_PERFORMANCE https://docs.microsoft.com/ru-ru/windows/win32/api/winioctl/ns-winioctl-disk_performance

func GetDiskPerformance

func GetDiskPerformance(uncPath string) (*DiskPerformance, error)

GetDiskPerformance calls syscall func CreateFile to generate a handler then executes the DeviceIoControl func in order to retrieve the metrics.

type HInternet

type HInternet uintptr

func HttpOpen

func HttpOpen(pszAgentW *uint16, dwAccessType uint32, pszProxyW *uint16, pszProxyBypassW *uint16, dwFlags uint32) (HInternet, error)

type HttpAutoProxyOptions

type HttpAutoProxyOptions struct {
	DwFlags           uint32 // DWORD
	DwAutoDetectFlags uint32 // DWORD
	LpszAutoConfigUrl LPWSTR // LPCWSTR (same as LPWSTR, but const)

	FAutoLogonIfChallenged bool // BOOL
	// contains filtered or unexported fields
}

WINHTTP_AUTOPROXY_OPTIONS https://docs.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_autoproxy_options#syntax

func (HttpAutoProxyOptions) Free

func (c HttpAutoProxyOptions) Free() error

type HttpCurrentUserIEProxyConfig

type HttpCurrentUserIEProxyConfig struct {
	FAutoDetect       bool   // BOOL
	LpszAutoConfigUrl LPWSTR // LPWSTR
	LpszProxy         LPWSTR // LPWSTR
	LpszProxyBypass   LPWSTR // LPWSTR
}

WINHTTP_CURRENT_USER_IE_PROXY_CONFIG https://docs.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_connection_info

func HttpGetIEProxyConfigForCurrentUser

func HttpGetIEProxyConfigForCurrentUser() (*HttpCurrentUserIEProxyConfig, error)

func (HttpCurrentUserIEProxyConfig) Free

type HttpProxyInfo

type HttpProxyInfo struct {
	DwAccessType    uint32 // DWORD
	LpszProxy       LPWSTR // LPWSTR
	LpszProxyBypass LPWSTR // LPWSTR
}

WINHTTP_PROXY_INFO https://docs.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_proxy_info

func HttpGetDefaultProxyConfiguration

func HttpGetDefaultProxyConfiguration() (*HttpProxyInfo, error)

func HttpGetProxyForUrl

func HttpGetProxyForUrl(hInternet HInternet, targetUrl string, pAutoProxyOptions *HttpAutoProxyOptions) (*HttpProxyInfo, error)

func (HttpProxyInfo) Free

func (c HttpProxyInfo) Free() error

type IPAdapterAddresses

type IPAdapterAddresses struct {
	Length                uint32
	IfIndex               uint32
	Next                  *IPAdapterAddresses
	AdapterName           *byte
	FirstUnicastAddress   *windows.IpAdapterUnicastAddress
	FirstAnycastAddress   *windows.IpAdapterAnycastAddress
	FirstMulticastAddress *windows.IpAdapterMulticastAddress
	FirstDNSServerAddress *windows.IpAdapterDnsServerAdapter
	DNSSuffix             *uint16
	Description           *uint16
	FriendlyName          *uint16
	PhysicalAddress       [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
	PhysicalAddressLength uint32
	Flags                 uint32
	Mtu                   uint32
	IfType                uint32
	OperStatus            uint32
	Ipv6IfIndex           uint32
	ZoneIndices           [16]uint32
	FirstPrefix           *windows.IpAdapterPrefix
	TransmitLinkSpeed     uint64
	ReceiveLinkSpeed      uint64
}

IP_ADAPTER_ADDRESSES_LH https://docs.microsoft.com/ru-ru/windows/win32/api/iptypes/ns-iptypes-_ip_adapter_addresses_lh

func GetAdaptersAddresses

func GetAdaptersAddresses() ([]*IPAdapterAddresses, error)

GetAdaptersAddresses returns a list of IP adapter and address structures. The structure contains an IP adapter and flattened multiple IP addresses including unicast, anycast and multicast addresses.

func (*IPAdapterAddresses) GetInterfaceName

func (a *IPAdapterAddresses) GetInterfaceName() string

type LPWSTR

type LPWSTR struct {
	Value *uint16
}

Wrap it to provide useful String() method syscall sets the inline struct's field as it was same-level field

func (LPWSTR) Free

func (l LPWSTR) Free() error

func (LPWSTR) Set

func (l LPWSTR) Set(s string) error

func (LPWSTR) String

func (l LPWSTR) String() string

func (LPWSTR) UTF16Ptr

func (l LPWSTR) UTF16Ptr() *uint16

type LPWSTRs

type LPWSTRs []LPWSTR

func (LPWSTRs) Free

func (strs LPWSTRs) Free() error

type MibIfRow2

type MibIfRow2 struct {
	InterfaceLuid               NET_LUID
	InterfaceIndex              uint32
	InterfaceGuid               NET_IF_GUID
	Alias                       [windows.MAX_ADAPTER_NAME_LENGTH + 1]uint16
	Description                 [windows.MAX_ADAPTER_NAME_LENGTH + 1]uint16
	PhysicalAddressLength       uint32
	PhysicalAddress             [IF_MAX_PHYS_ADDRESS_LENGTH]byte
	PermanentPhysicalAddress    [IF_MAX_PHYS_ADDRESS_LENGTH]byte
	Mtu                         uint32
	Type                        uint32
	TunnelType                  int32
	MediaType                   int32
	PhysicalMediumType          int32
	AccessType                  int32
	DirectionType               int32
	InterfaceAndOperStatusFlags bool
	OperStatus                  int32
	AdminStatus                 int32
	MediaConnectState           int32
	NetworkGuid                 NET_IF_NETWORK_GUID
	ConnectionType              int32

	TransmitLinkSpeed  uint64
	ReceiveLinkSpeed   uint64
	InOctets           uint64
	InUcastPkts        uint64
	InNUcastPkts       uint64
	InDiscards         uint64
	InErrors           uint64
	InUnknownProtos    uint64
	InUcastOctets      uint64
	InMulticastOctets  uint64
	InBroadcastOctets  uint64
	OutOctets          uint64
	OutUcastPkts       uint64
	OutNUcastPkts      uint64
	OutDiscards        uint64
	OutErrors          uint64
	OutUcastOctets     uint64
	OutMulticastOctets uint64
	OutBroadcastOctets uint64
	OutQLen            uint64
	// contains filtered or unexported fields
}

MIB_IF_ROW2 https://docs.microsoft.com/ru-ru/windows/win32/api/netioapi/ns-netioapi-_mib_if_row2

type NET_IF_GUID

type NET_IF_GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

type NET_IF_NETWORK_GUID

type NET_IF_NETWORK_GUID NET_IF_GUID

GUID

type NET_LUID

type NET_LUID NET_LUID_LH

type NET_LUID_LH

type NET_LUID_LH struct {
	Value uint64
}

type SystemProcessInformation

type SystemProcessInformation struct {
	NextEntryOffset              uint32        // ULONG
	NumberOfThreads              uint32        // ULONG
	WorkingSetPrivateSize        int64         // LARGE_INTEGER
	HardFaultCount               uint32        // ULONG
	NumberOfThreadsHighWatermark uint32        // ULONG
	CycleTime                    uint64        // ULONGLONG
	CreateTime                   int64         // LARGE_INTEGER
	UserTime                     int64         // LARGE_INTEGER
	KernelTime                   int64         // LARGE_INTEGER
	ImageName                    unicodeString // UNICODE_STRING
	BasePriority                 kPriority     // KPRIORITY
	UniqueProcessID              uintptr       // HANDLE
	InheritedFromUniqueProcessID uintptr       // HANDLE
	HandleCount                  uint32        // ULONG
	SessionID                    uint32        // ULONG
	UniqueProcessKey             *uint32       // ULONG_PTR
	PeakVirtualSize              uintptr       // SIZE_T
	VirtualSize                  uintptr       // SIZE_T
	PageFaultCount               uint32        // ULONG
	PeakWorkingSetSize           uintptr       // SIZE_T
	WorkingSetSize               uintptr       // SIZE_T
	QuotaPeakPagedPoolUsage      uintptr       // SIZE_T
	QuotaPagedPoolUsage          uintptr       // SIZE_T
	QuotaPeakNonPagedPoolUsage   uintptr       // SIZE_T
	QuotaNonPagedPoolUsage       uintptr       // SIZE_T
	PagefileUsage                uintptr       // SIZE_T
	PeakPagefileUsage            uintptr       // SIZE_T
	PrivatePageCount             uintptr       // SIZE_T
	ReadOperationCount           int64         // LARGE_INTEGER
	WriteOperationCount          int64         // LARGE_INTEGER
	OtherOperationCount          int64         // LARGE_INTEGER
	ReadTransferCount            int64         // LARGE_INTEGER
	WriteTransferCount           int64         // LARGE_INTEGER
	OtherTransferCount           int64         // LARGE_INTEGER
}

SYSTEM_PROCESS_INFORMATION

type SystemProcessorPerformanceInformation

type SystemProcessorPerformanceInformation struct {
	IdleTime       int64 // idle time in 100ns (this is not a filetime).
	KernelTime     int64 // kernel time in 100ns.  kernel time includes idle time. (this is not a filetime).
	UserTime       int64 // usertime in 100ns (this is not a filetime).
	DpcTime        int64 // dpc time in 100ns (this is not a filetime).
	InterruptTime  int64 // interrupt time in 100ns
	InterruptCount uint32
}

SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ex/sysinfo/processor_performance.htm

func GetSystemProcessorPerformanceInformation

func GetSystemProcessorPerformanceInformation() ([]SystemProcessorPerformanceInformation, error)

type SystemThreadInformation

type SystemThreadInformation struct {
	KernelTime      int64       // LARGE_INTEGER
	UserTime        int64       // LARGE_INTEGER
	CreateTime      int64       // LARGE_INTEGER
	WaitTime        uint32      // ULONG
	StartAddress    uintptr     // PVOID
	ClientID        clientID    // CLIENT_ID
	Priority        kPriority   // KPRIORITY
	BasePriority    int32       // LONG
	ContextSwitches uint32      // ULONG
	ThreadState     uint32      // ULONG
	WaitReason      kWaitReason // KWAIT_REASON
}

SYSTEM_THREAD_INFORMATION

type WindowsEnumerator

type WindowsEnumerator struct {
	// contains filtered or unexported fields
}

func NewWindowsEnumerator

func NewWindowsEnumerator() *WindowsEnumerator

NewWindowsEnumerator returns an object for enumerating window handles it's important not to create too many enumerators as there is a runtime limit of how many callback objects can be created

func (*WindowsEnumerator) Enumerate

func (we *WindowsEnumerator) Enumerate() (map[uint32]syscall.Handle, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL