@@ -139,6 +139,9 @@ var (
139139 procFlushViewOfFile = modkernel32 .NewProc ("FlushViewOfFile" )
140140 procVirtualLock = modkernel32 .NewProc ("VirtualLock" )
141141 procVirtualUnlock = modkernel32 .NewProc ("VirtualUnlock" )
142+ procVirtualAlloc = modkernel32 .NewProc ("VirtualAlloc" )
143+ procVirtualFree = modkernel32 .NewProc ("VirtualFree" )
144+ procVirtualProtect = modkernel32 .NewProc ("VirtualProtect" )
142145 procTransmitFile = modmswsock .NewProc ("TransmitFile" )
143146 procReadDirectoryChangesW = modkernel32 .NewProc ("ReadDirectoryChangesW" )
144147 procCertOpenSystemStoreW = modcrypt32 .NewProc ("CertOpenSystemStoreW" )
@@ -1384,6 +1387,43 @@ func VirtualUnlock(addr uintptr, length uintptr) (err error) {
13841387 return
13851388}
13861389
1390+ func VirtualAlloc (address uintptr , size uintptr , alloctype uint32 , protect uint32 ) (value uintptr , err error ) {
1391+ r0 , _ , e1 := syscall .Syscall6 (procVirtualAlloc .Addr (), 4 , uintptr (address ), uintptr (size ), uintptr (alloctype ), uintptr (protect ), 0 , 0 )
1392+ value = uintptr (r0 )
1393+ if value == 0 {
1394+ if e1 != 0 {
1395+ err = errnoErr (e1 )
1396+ } else {
1397+ err = syscall .EINVAL
1398+ }
1399+ }
1400+ return
1401+ }
1402+
1403+ func VirtualFree (address uintptr , size uintptr , freetype uint32 ) (err error ) {
1404+ r1 , _ , e1 := syscall .Syscall (procVirtualFree .Addr (), 3 , uintptr (address ), uintptr (size ), uintptr (freetype ))
1405+ if r1 == 0 {
1406+ if e1 != 0 {
1407+ err = errnoErr (e1 )
1408+ } else {
1409+ err = syscall .EINVAL
1410+ }
1411+ }
1412+ return
1413+ }
1414+
1415+ func VirtualProtect (address uintptr , size uintptr , newprotect uint32 , oldprotect * uint32 ) (err error ) {
1416+ r1 , _ , e1 := syscall .Syscall6 (procVirtualProtect .Addr (), 4 , uintptr (address ), uintptr (size ), uintptr (newprotect ), uintptr (unsafe .Pointer (oldprotect )), 0 , 0 )
1417+ if r1 == 0 {
1418+ if e1 != 0 {
1419+ err = errnoErr (e1 )
1420+ } else {
1421+ err = syscall .EINVAL
1422+ }
1423+ }
1424+ return
1425+ }
1426+
13871427func TransmitFile (s Handle , handle Handle , bytesToWrite uint32 , bytsPerSend uint32 , overlapped * Overlapped , transmitFileBuf * TransmitFileBuffers , flags uint32 ) (err error ) {
13881428 r1 , _ , e1 := syscall .Syscall9 (procTransmitFile .Addr (), 7 , uintptr (s ), uintptr (handle ), uintptr (bytesToWrite ), uintptr (bytsPerSend ), uintptr (unsafe .Pointer (overlapped )), uintptr (unsafe .Pointer (transmitFileBuf )), uintptr (flags ), 0 , 0 )
13891429 if r1 == 0 {
0 commit comments