1 回答
TA贡献1824条经验 获得超5个赞
您的问题是该函数采用节句柄和大小的指针参数。
这似乎有效:
package main
import (
"fmt"
"unsafe"
"golang.org/x/sys/windows"
)
// Why are these not defined in the windows pkg?!
const SEC_COMMIT = 0x8000000
const SECTION_WRITE = 0x2
const SECTION_READ = 0x4
const SECTION_EXECUTE = 0x8
const SECTION_RWX = SECTION_WRITE | SECTION_READ | SECTION_EXECUTE
func createSection() error {
var e error
var err uintptr
var ntdll *windows.LazyDLL
var section uintptr
// Load DLL
ntdll = windows.NewLazySystemDLL("ntdll")
size := int64(4096)
// FIXME Allocate section
err, _, e = ntdll.NewProc("NtCreateSection").Call(
uintptr(unsafe.Pointer(§ion)),
SECTION_RWX,
0,
uintptr(unsafe.Pointer(&size)),
windows.PAGE_EXECUTE_READWRITE,
SEC_COMMIT,
0,
)
if err != 0 {
return fmt.Errorf("%0x: %s", uint32(err), e.Error())
} else if section == 0 {
return fmt.Errorf("NtCreateSection failed for unknown reason")
}
fmt.Printf("%0x\n", section)
return nil
}
func main() {
var e error
if e = createSection(); e != nil {
fmt.Println(e.Error())
}
}
- 1 回答
- 0 关注
- 178 浏览
添加回答
举报