new function add

master
兔子 3 years ago
parent 7e2261bca5
commit 3271c16a9a

@ -21,10 +21,10 @@ func DuplicateTokenEx(hExistingToken HANDLE, dwDesiredAccess DWORD,
if err != nil {
return errors.New("Can't Load WTSQueryUserToken API")
}
r, _, err := syscall.Syscall6(uintptr(Dup), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), lpTokenAttributes, uintptr(ImpersonationLevel),
r, _, errno := syscall.Syscall6(uintptr(Dup), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), lpTokenAttributes, uintptr(ImpersonationLevel),
uintptr(TokenType), uintptr(unsafe.Pointer(phNewToken)))
if r == 0 {
return err
return error(errno)
}
return nil
}
@ -52,11 +52,11 @@ func CreateProcessAsUser(hToken TOKEN, lpApplicationName, lpCommandLine string,
if len(lpCurrentDirectory) > 0 {
workingDir = uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCurrentDirectory)))
}
r, _, err := syscall.Syscall12(uintptr(CPAU), 11, uintptr(hToken), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpApplicationName))),
r, _, errno := syscall.Syscall12(uintptr(CPAU), 11, uintptr(hToken), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpApplicationName))),
commandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, uintptr(dwCreationFlags), uintptr(lpEnvironment),
workingDir, uintptr(unsafe.Pointer(lpStartupInfo)), uintptr(unsafe.Pointer(lpProcessInformation)), 0)
if r == 0 {
return err
return error(errno)
}
return nil
}
@ -71,9 +71,9 @@ func GetTokenInformation(TokenHandle HANDLE, TokenInformationClass, TokenInforma
if err != nil {
return errors.New("Can't Load GetTokenInformation API")
}
if r, _, err := syscall.Syscall6(uintptr(GTI), 5, uintptr(TokenHandle), TokenInformationClass,
if r, _, errno := syscall.Syscall6(uintptr(GTI), 5, uintptr(TokenHandle), TokenInformationClass,
TokenInformation, TokenInformationLength, uintptr(unsafe.Pointer(ReturnLength)), 0); r == 0 {
return err
return error(errno)
}
return nil
}

@ -30,8 +30,8 @@ func CloseHandle(hObject HANDLE) error {
if err != nil {
return errors.New("Can't Load CloseHandle API")
}
if r, _, err := syscall.Syscall(uintptr(CH), 1, uintptr(hObject), 0, 0); r == 0 {
return err
if r, _, errno := syscall.Syscall(uintptr(CH), 1, uintptr(hObject), 0, 0); r == 0 {
return error(errno)
}
return nil
}
@ -46,9 +46,9 @@ func CreateToolhelp32Snapshot(dwFlags, th32ProcessID DWORD) (HANDLE, error) {
if err != nil {
return 0, errors.New("Can't Load CreateToolhelp32Snapshot API")
}
r, _, err := syscall.Syscall(uintptr(CTS), 2, uintptr(dwFlags), uintptr(th32ProcessID), 0)
r, _, errno := syscall.Syscall(uintptr(CTS), 2, uintptr(dwFlags), uintptr(th32ProcessID), 0)
if int(r) == -1 {
return 0, err
return 0, error(errno)
}
return HANDLE(r), nil
}
@ -63,9 +63,12 @@ func Process32Next(hSnapshot HANDLE, lppe *PROCESSENTRY32) error {
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
r, _, errno := syscall.Syscall(uintptr(PN), 2, uintptr(hSnapshot), uintptr(unsafe.Pointer(lppe)), 0)
if r == 0 {
if errno != 0 {
return error(errno)
}
return syscall.EINVAL
}
return nil
}
@ -109,10 +112,63 @@ func GlobalMemoryStatusEx(data *MEMORYSTATUSEX) (bool, error) {
if err != nil {
return false, err
}
r, _, err := syscall.Syscall(uintptr(GMS), 1, uintptr(unsafe.Pointer(data)), 0, 0)
r, _, errno := syscall.Syscall(uintptr(GMS), 1, uintptr(unsafe.Pointer(data)), 0, 0)
if r == 0 {
if errno != 0 {
return false, error(errno)
}
return false, syscall.EINVAL
}
return true, nil
}
func LockFileEx(hFile HANDLE, dwFlags DWORD, dwReserved DWORD, nNumberOfBytesToLockLow DWORD,
nNumberOfBytesToLockHigh DWORD, lpOverlapped *syscall.Overlapped) (bool, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return false, err
}
defer syscall.FreeLibrary(kernel32)
Lck, err := syscall.GetProcAddress(syscall.Handle(kernel32), "LockFileEx")
if err != nil {
return false, err
} else {
}
r, _, errno := syscall.Syscall6(uintptr(Lck), 6, uintptr(hFile), uintptr(dwFlags), uintptr(dwReserved),
uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), uintptr(unsafe.Pointer(lpOverlapped)))
if r == 0 {
if errno != 0 {
return false, error(errno)
}
return false, syscall.EINVAL
}
return true, nil
}
func CreateEventW(lpEventAttributes *syscall.SecurityAttributes, bManualReset bool,
bInitialState bool, lpName LPCWSTR) (HANDLE, error) {
var intBManualReset, intBInitialState int
if bManualReset {
intBManualReset = 1
}
if bInitialState {
intBInitialState = 1
}
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return 0, err
}
defer syscall.FreeLibrary(kernel32)
Lck, err := syscall.GetProcAddress(syscall.Handle(kernel32), "CreateEventW")
if err != nil {
return 0, err
}
r, _, errno := syscall.Syscall6(uintptr(Lck), 4, uintptr(unsafe.Pointer(lpEventAttributes)),
uintptr(intBManualReset), uintptr(intBInitialState), uintptr(unsafe.Pointer(lpName)), 0, 0)
if HANDLE(r) == 0 {
if errno != 0 {
return HANDLE(r), error(errno)
}
return HANDLE(r), syscall.EINVAL
}
return HANDLE(r), nil
}

@ -3,6 +3,11 @@ package win32api
type Ulong int32
type Ulong_ptr uintptr
const (
LOCKFILE_EXCLUSIVE_LOCK DWORD = 0x00000002
LOCKFILE_FAIL_IMMEDIATELY DWORD = 0x00000001
)
type PROCESSENTRY32 struct {
DwSize Ulong
CntUsage Ulong

@ -80,9 +80,9 @@ func ShellExecuteEx(muzika *SHELLEXECUTEINFOW) error {
if err != nil {
return errors.New("Can't Load ShellExecuteEx API")
}
r, _, err := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(muzika)), 0, 0, 0, 0, 0)
r, _, errno := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(muzika)), 0, 0, 0, 0, 0)
if r == 0 {
return err
return error(errno)
}
return nil
}

@ -24,9 +24,9 @@ func CreateEnvironmentBlock(lpEnvironment *HANDLE, hToken TOKEN, bInherit uintpt
if err != nil {
return errors.New("Can't Load WTSQueryUserToken API")
}
r, _, err := syscall.Syscall6(uintptr(Dup), 3, uintptr(unsafe.Pointer(lpEnvironment)), uintptr(hToken), bInherit, 0, 0, 0)
r, _, errno := syscall.Syscall6(uintptr(Dup), 3, uintptr(unsafe.Pointer(lpEnvironment)), uintptr(hToken), bInherit, 0, 0, 0)
if r == 0 {
return err
return error(errno)
}
return nil
}

@ -43,6 +43,7 @@ type (
LPCVOID unsafe.Pointer
LPVOID unsafe.Pointer
LRESULT uintptr
LPCWSTR *uint16
PVOID unsafe.Pointer
QPC_TIME uint64
ULONG uint32

@ -16,9 +16,9 @@ func WTSQueryUserToken(SessionId HANDLE, phToken *HANDLE) error {
if err != nil {
return errors.New("Can't Load WTSQueryUserToken API")
}
r, _, err := syscall.Syscall(uintptr(WTGet), 2, uintptr(SessionId), uintptr(unsafe.Pointer(phToken)), 0)
r, _, errno := syscall.Syscall(uintptr(WTGet), 2, uintptr(SessionId), uintptr(unsafe.Pointer(phToken)), 0)
if r == 0 {
return err
return error(errno)
} else {
return nil
}
@ -34,9 +34,9 @@ func WTSEnumerateSessions(hServer HANDLE, Reserved, Version DWORD, ppSessionInfo
if err != nil {
return errors.New("Can't Load WTSQueryUserToken API")
}
r, _, err := syscall.Syscall6(uintptr(WT), 5, uintptr(hServer), uintptr(Reserved), uintptr(Version), uintptr(unsafe.Pointer(ppSessionInfo)), uintptr(unsafe.Pointer(pCount)), 0)
r, _, errno := syscall.Syscall6(uintptr(WT), 5, uintptr(hServer), uintptr(Reserved), uintptr(Version), uintptr(unsafe.Pointer(ppSessionInfo)), uintptr(unsafe.Pointer(pCount)), 0)
if r == 0 {
return err
return error(errno)
}
return nil
}

Loading…
Cancel
Save