new func add

master
兔子 3 years ago
parent 3271c16a9a
commit 87c33de7de
Signed by: b612
GPG Key ID: 481225A74DEB62A1

@ -144,6 +144,29 @@ func LockFileEx(hFile HANDLE, dwFlags DWORD, dwReserved DWORD, nNumberOfBytesToL
return true, nil return true, nil
} }
func OpenFileById(hVolumeHint HANDLE, lpFileId *FILE_ID_DESCRIPTOR, dwDesiredAccess DWORD, dwShareMode DWORD,
lpSecurityAttributes *syscall.SecurityAttributes, dwFlagsAndAttributes DWORD) (HANDLE, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return 0, err
}
defer syscall.FreeLibrary(kernel32)
ofb, err := syscall.GetProcAddress(syscall.Handle(kernel32), "OpenFileById")
if err != nil {
return 0, err
}
r, _, errno := syscall.Syscall6(ofb, 6, uintptr(hVolumeHint),
uintptr(unsafe.Pointer(lpFileId)), uintptr(dwDesiredAccess), uintptr(dwShareMode),
uintptr(unsafe.Pointer(lpSecurityAttributes)), uintptr(dwFlagsAndAttributes))
if r == syscall.INVALID_FILE_ATTRIBUTES {
if errno != 0 {
return HANDLE(r), error(errno)
}
return HANDLE(r), syscall.EINVAL
}
return HANDLE(r), nil
}
func CreateEventW(lpEventAttributes *syscall.SecurityAttributes, bManualReset bool, func CreateEventW(lpEventAttributes *syscall.SecurityAttributes, bManualReset bool,
bInitialState bool, lpName LPCWSTR) (HANDLE, error) { bInitialState bool, lpName LPCWSTR) (HANDLE, error) {
var intBManualReset, intBInitialState int var intBManualReset, intBInitialState int
@ -172,3 +195,90 @@ func CreateEventW(lpEventAttributes *syscall.SecurityAttributes, bManualReset bo
} }
return HANDLE(r), nil return HANDLE(r), nil
} }
func GetLogicalDriveStringsW(nBufferLength DWORD, lpBuffer LPWSTR) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return err
}
defer syscall.FreeLibrary(kernel32)
glds, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetLogicalDriveStringsW")
if err != nil {
return err
}
_, _, errno := syscall.Syscall(uintptr(glds), 2, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer)), 0)
if errno != 0 {
return error(errno)
}
return nil
}
func GetVolumeInformationW(lpRootPathName LPCWSTR, lpVolumeNameBuffer LPWSTR, nVolumeNameSize DWORD,
lpVolumeSerialNumber LPDWORD, lpMaximumComponentLength LPDWORD, lpFileSystemFlags LPDWORD,
lpFileSystemNameBuffer LPWSTR, nFileSystemNameSize DWORD) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return err
}
defer syscall.FreeLibrary(kernel32)
glds, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetVolumeInformationW")
if err != nil {
return err
}
_, _, errno := syscall.Syscall9(uintptr(glds), 8, uintptr(unsafe.Pointer(lpRootPathName)),
uintptr(unsafe.Pointer(lpVolumeNameBuffer)), uintptr(nVolumeNameSize), uintptr(unsafe.Pointer(lpVolumeSerialNumber)),
uintptr(unsafe.Pointer(lpMaximumComponentLength)), uintptr(unsafe.Pointer(lpFileSystemFlags)),
uintptr(unsafe.Pointer(lpFileSystemNameBuffer)), uintptr(nFileSystemNameSize), 0)
if errno != 0 {
return error(errno)
}
return nil
}
func DeviceIoControl(hDevice HANDLE, dwIoControlCode DWORD, lpInBuffer LPVOID, nInBufferSize DWORD, lpOutBuffer LPVOID,
nOutBufferSize DWORD, lpBytesReturned LPDWORD, lpOverlapped *syscall.Overlapped) (bool, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return false, err
}
defer syscall.FreeLibrary(kernel32)
dic, err := syscall.GetProcAddress(syscall.Handle(kernel32), "DeviceIoControl")
if err != nil {
return false, err
}
r, _, errno := syscall.Syscall9(uintptr(dic), 8, uintptr(hDevice), uintptr(dwIoControlCode),
uintptr(unsafe.Pointer(lpInBuffer)), uintptr(nInBufferSize), uintptr(unsafe.Pointer(lpOutBuffer)), uintptr(nOutBufferSize),
uintptr(unsafe.Pointer(lpBytesReturned)), uintptr(unsafe.Pointer(lpOverlapped)), 0)
if r == 0 {
if errno != 0 {
return false, error(errno)
} else {
return false, syscall.EINVAL
}
}
return true, nil
}
func DeviceIoControlPtr(hDevice HANDLE, dwIoControlCode DWORD, lpInBuffer uintptr, nInBufferSize DWORD, lpOutBuffer uintptr,
nOutBufferSize DWORD, lpBytesReturned LPDWORD, lpOverlapped *syscall.Overlapped) (bool, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return false, err
}
defer syscall.FreeLibrary(kernel32)
dic, err := syscall.GetProcAddress(syscall.Handle(kernel32), "DeviceIoControl")
if err != nil {
return false, err
}
r, _, errno := syscall.Syscall9(uintptr(dic), 8, uintptr(hDevice), uintptr(dwIoControlCode),
lpInBuffer, uintptr(nInBufferSize), lpOutBuffer, uintptr(nOutBufferSize),
uintptr(unsafe.Pointer(lpBytesReturned)), uintptr(unsafe.Pointer(lpOverlapped)), 0)
if r == 0 {
if errno != 0 {
return false, error(errno)
} else {
return false, syscall.EINVAL
}
}
return true, nil
}

@ -1,5 +1,7 @@
package win32api package win32api
import "syscall"
type Ulong int32 type Ulong int32
type Ulong_ptr uintptr type Ulong_ptr uintptr
@ -32,3 +34,82 @@ type MEMORYSTATUSEX struct {
UllAvailVirtual DWORDLONG UllAvailVirtual DWORDLONG
UllAvailExtendedVirtual DWORDLONG UllAvailExtendedVirtual DWORDLONG
} }
type USN_JOURNAL_DATA struct {
UsnJournalID DWORDLONG
FirstUsn USN
NextUsn USN
LowestValidUsn USN
MaxUsn USN
MaximumSize DWORDLONG
AllocationDelta DWORDLONG
}
type READ_USN_JOURNAL_DATA struct {
StartUsn USN
ReasonMask DWORD
ReturnOnlyOnClose DWORD
Timeout DWORDLONG
BytesToWaitFor DWORDLONG
UsnJournalID DWORDLONG
}
type USN_RECORD struct {
RecordLength DWORD
MajorVersion WORD
MinorVersion WORD
FileReferenceNumber DWORDLONG
ParentFileReferenceNumber DWORDLONG
Usn USN
TimeStamp LARGE_INTEGER
Reason DWORD
SourceInfo DWORD
SecurityId DWORD
FileAttributes DWORD
FileNameLength WORD
FileNameOffset WORD
FileName [1]WCHAR
}
type MFT_ENUM_DATA struct {
StartFileReferenceNumber DWORDLONG
LowUsn USN
HighUsn USN
}
const (
FSCTL_ENUM_USN_DATA = 0x900B3
FSCTL_QUERY_USN_JOURNAL = 0x900F4
FSCTL_READ_USN_JOURNAL = 0x900BB
O_RDONLY = syscall.O_RDONLY
O_RDWR = syscall.O_RDWR
O_CREAT = syscall.O_CREAT
O_WRONLY = syscall.O_WRONLY
GENERIC_READ = syscall.GENERIC_READ
GENERIC_WRITE = syscall.GENERIC_WRITE
FILE_APPEND_DATA = syscall.FILE_APPEND_DATA
FILE_SHARE_READ = syscall.FILE_SHARE_READ
FILE_SHARE_WRITE = syscall.FILE_SHARE_WRITE
ERROR_FILE_NOT_FOUND = syscall.ERROR_FILE_NOT_FOUND
O_APPEND = syscall.O_APPEND
O_CLOEXEC = syscall.O_CLOEXEC
O_EXCL = syscall.O_EXCL
O_TRUNC = syscall.O_TRUNC
CREATE_ALWAYS = syscall.CREATE_ALWAYS
CREATE_NEW = syscall.CREATE_NEW
OPEN_ALWAYS = syscall.OPEN_ALWAYS
TRUNCATE_EXISTING = syscall.TRUNCATE_EXISTING
OPEN_EXISTING = syscall.OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL = syscall.FILE_ATTRIBUTE_NORMAL
FILE_FLAG_BACKUP_SEMANTICS = syscall.FILE_FLAG_BACKUP_SEMANTICS
FILE_ATTRIBUTE_DIRECTORY = syscall.FILE_ATTRIBUTE_DIRECTORY
MAX_LONG_PATH = syscall.MAX_LONG_PATH
)
type FILE_ID_DESCRIPTOR struct {
DwSize DWORD
Type DWORD
FileId DWORDLONG
ObjectId DWORDLONG
ExtendedFileId DWORDLONG
}

@ -10,6 +10,7 @@ type (
COLORREF uint32 COLORREF uint32
DWM_FRAME_COUNT uint64 DWM_FRAME_COUNT uint64
DWORD uint32 DWORD uint32
LPDWORD *uint32
DWORDLONG uint64 DWORDLONG uint64
HACCEL HANDLE HACCEL HANDLE
HANDLE uintptr HANDLE uintptr
@ -52,9 +53,15 @@ type (
WTS_CONNECTSTATE_CLASS int WTS_CONNECTSTATE_CLASS int
TRACEHANDLE uintptr TRACEHANDLE uintptr
TOKEN HANDLE TOKEN HANDLE
LPWSTR *uint16
TOKEN_TYPE int TOKEN_TYPE int
SW int SW int
SECURITY_IMPERSONATION_LEVEL int SECURITY_IMPERSONATION_LEVEL int
WCHAR uint16
WORD uint16
USN int64
LARGE_INTEGER LONGLONG
LONGLONG int64
) )
type WTS_SESSION_INFO struct { type WTS_SESSION_INFO struct {

Loading…
Cancel
Save