Update New API\
This commit is contained in:
parent
40b9dba9f0
commit
739e939fc3
49
kernel32.go
49
kernel32.go
@ -3,6 +3,7 @@ package win32api
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func WTSGetActiveConsoleSessionId() (DWORD, error) {
|
||||
@ -34,3 +35,51 @@ func CloseHandle(hObject HANDLE) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateToolhelp32Snapshot(dwFlags, th32ProcessID DWORD) (HANDLE, error) {
|
||||
kernel32, err := syscall.LoadLibrary("kernel32.dll")
|
||||
if err != nil {
|
||||
return 0, errors.New("Can't Load Kernel32 API")
|
||||
}
|
||||
defer syscall.FreeLibrary(kernel32)
|
||||
CTS, err := syscall.GetProcAddress(syscall.Handle(kernel32), "CreateToolhelp32Snapshot")
|
||||
if err != nil {
|
||||
return 0, errors.New("Can't Load CreateToolhelp32Snapshot API")
|
||||
}
|
||||
r, _, err := syscall.Syscall(uintptr(CTS), 2, uintptr(dwFlags), uintptr(th32ProcessID), 0)
|
||||
if int(r) == -1 {
|
||||
return 0, err
|
||||
}
|
||||
return HANDLE(r), nil
|
||||
}
|
||||
|
||||
func Process32Next(hSnapshot HANDLE, lppe *PROCESSENTRY32) error {
|
||||
kernel32, err := syscall.LoadLibrary("kernel32.dll")
|
||||
if err != nil {
|
||||
return errors.New("Can't Load Kernel32 API")
|
||||
}
|
||||
defer syscall.FreeLibrary(kernel32)
|
||||
PN, err := syscall.GetProcAddress(syscall.Handle(kernel32), "Process32Next")
|
||||
if err != nil {
|
||||
return errors.New("Can't Load Process32Next API")
|
||||
}
|
||||
r, _, err := syscall.Syscall(uintptr(PN), 2, uintptr(hSnapshot), uintptr(unsafe.Pointer(lppe)), 0)
|
||||
if int(r) != 1 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetProcessId(Process HANDLE) uint32 {
|
||||
kernel32, err := syscall.LoadLibrary("kernel32.dll")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer syscall.FreeLibrary(kernel32)
|
||||
GPI, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetProcessId")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
r, _, _ := syscall.Syscall(uintptr(GPI), 1, uintptr(Process), 0, 0)
|
||||
return uint32(r)
|
||||
}
|
||||
|
17
kernel32typedef.go
Normal file
17
kernel32typedef.go
Normal file
@ -0,0 +1,17 @@
|
||||
package win32api
|
||||
|
||||
type Ulong int32
|
||||
type Ulong_ptr uintptr
|
||||
|
||||
type PROCESSENTRY32 struct {
|
||||
DwSize Ulong
|
||||
CntUsage Ulong
|
||||
Th32ProcessID Ulong
|
||||
Th32DefaultHeapID Ulong_ptr
|
||||
Th32ModuleID Ulong
|
||||
CntThreads Ulong
|
||||
Th32ParentProcessID Ulong
|
||||
PcPriClassBase Ulong
|
||||
DwFlags Ulong
|
||||
SzExeFile [260]byte
|
||||
}
|
@ -69,7 +69,7 @@ func ShellExecuteEX2(hwnd HWND, lpVerb, lpFile, lpParameters, lpDirectory string
|
||||
}
|
||||
*/
|
||||
|
||||
func ShellExecuteEx(muzika SHELLEXECUTEINFOW) error {
|
||||
func ShellExecuteEx(muzika *SHELLEXECUTEINFOW) error {
|
||||
shell32, err := syscall.LoadLibrary("shell32.dll")
|
||||
|
||||
if err != nil {
|
||||
@ -80,9 +80,9 @@ func ShellExecuteEx(muzika SHELLEXECUTEINFOW) error {
|
||||
if err != nil {
|
||||
return errors.New("Can't Load ShellExecuteEx API")
|
||||
}
|
||||
r, _, _ := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(&muzika)), 0, 0, 0, 0, 0)
|
||||
if r != 0 {
|
||||
return errors.New("Error Recured")
|
||||
r, _, err := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(muzika)), 0, 0, 0, 0, 0)
|
||||
if r == 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package win32api
|
||||
|
||||
type SHELLEXECUTEINFOW struct {
|
||||
cbSize DWORD
|
||||
fMask ULONG
|
||||
hwnd HWND
|
||||
lpVerb string
|
||||
lpFile string
|
||||
lpParameters string
|
||||
lpDirectory string
|
||||
nShow int
|
||||
hInstApp HINSTANCE
|
||||
lpIDList LPVOID
|
||||
lpClass string
|
||||
hkeyClass HKEY
|
||||
dwHotKey DWORD
|
||||
union UNION
|
||||
hProcess HANDLE
|
||||
CbSize DWORD
|
||||
FMask ULONG
|
||||
Hwnd HWND
|
||||
LpVerb uintptr
|
||||
LpFile uintptr
|
||||
LpParameters uintptr
|
||||
LpDirectory uintptr
|
||||
NShow int
|
||||
HInstApp HINSTANCE
|
||||
LpIDList LPVOID
|
||||
LpClass uintptr
|
||||
HkeyClass HKEY
|
||||
DwHotKey DWORD
|
||||
UnionorHMonitor HANDLE
|
||||
HProcess HANDLE
|
||||
}
|
||||
|
||||
type UNION struct {
|
||||
hIcon HANDLE
|
||||
hMonitor HANDLE
|
||||
HIcon HANDLE
|
||||
HMonitor HANDLE
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user