예제 #1
0
func init() {
	io.WriteString(debugger.Console,
		"Detecting whether Process Monitor is installed")

	path, err := windows.UTF16PtrFromString(`\\.\Global\ProcmonDebugLogger`)
	if nil != err {
		fmt.Fprintf(debugger.Console, "init failed: %v", err)
		return
	}

	processMonitorHandle, err := windows.CreateFile(
		path,
		windows.GENERIC_READ|windows.GENERIC_WRITE,
		windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE,
		nil,
		windows.OPEN_EXISTING,
		windows.FILE_ATTRIBUTE_NORMAL,
		0)
	if nil != err {
		fmt.Fprintf(debugger.Console, "CreateFile failed: %v", err)
		return
	}

	if windows.InvalidHandle == processMonitorHandle {
		io.WriteString(debugger.Console, "Process Monitor is not installed")
		return
	}

	ProcessMonitor =
		&processMonitorWriter{&realProcessMonitor{processMonitorHandle}}
	io.WriteString(debugger.Console, "Process Monitor debug logging is enabled")
}
예제 #2
0
func TestFormatMessage(t *testing.T) {
	dll := windows.MustLoadDLL("pdh.dll")

	pdhOpenQuery := func(datasrc *uint16, userdata uint32, query *windows.Handle) (errno uintptr) {
		r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhOpenQueryW").Addr(), 3, uintptr(unsafe.Pointer(datasrc)), uintptr(userdata), uintptr(unsafe.Pointer(query)))
		return r0
	}

	pdhCloseQuery := func(query windows.Handle) (errno uintptr) {
		r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhCloseQuery").Addr(), 1, uintptr(query), 0, 0)
		return r0
	}

	var q windows.Handle
	name, err := windows.UTF16PtrFromString("no_such_source")
	if err != nil {
		t.Fatal(err)
	}
	errno := pdhOpenQuery(name, 0, &q)
	if errno == 0 {
		pdhCloseQuery(q)
		t.Fatal("PdhOpenQuery succeeded, but expected to fail.")
	}

	const flags uint32 = syscall.FORMAT_MESSAGE_FROM_HMODULE | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
	buf := make([]uint16, 300)
	_, err = windows.FormatMessage(flags, uintptr(dll.Handle), uint32(errno), 0, buf, nil)
	if err != nil {
		t.Fatal("FormatMessage for handle=%x and errno=%x failed: %v", dll.Handle, errno, err)
	}
}
예제 #3
0
파일: client.go 프로젝트: jmptrader/types
func GetIDsOfName(obj interface{}, method uintptr, names []string) (displayIDs []int32, err error) {
	wnames := make([]*uint16, len(names))
	for i := 0; i < len(names); i++ {
		ptr, err := syscall.UTF16PtrFromString(names[i])
		if err != nil {
			return
		}
		wnames[i] = ptr
	}

	displayIDs = make([]int32, len(names))
	dispIDs := make([]int32, len(names))
	namelen := uint32(len(names))

	err = com.HResultToError(syscall.Syscall6(
		method,
		uintptr(6),
		uintptr(unsafe.Pointer(obj)),
		uintptr(unsafe.Pointer(com.NullInterfaceID)),
		uintptr(unsafe.Pointer(&wnames[0])),
		uintptr(namelen),
		uintptr(com.GetDefaultUserLocaleID()),
		uintptr(unsafe.Pointer(&dispIDs[0]))))

	displayIDs = dispIDs[0:namelen]

	return
}
예제 #4
0
파일: windows.go 프로젝트: jmptrader/com
func InterfaceIDFromString(programID string) (classID *GUID, err error) {
	lpsz, err := windows.UTF16PtrFromString(programID)
	if err != nil {
		return
	}
	err = HResultToError(procIIDFromString.Call(uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(&classID))))
	return
}
예제 #5
0
func (d *realOutputDebugString) Write(message string) error {
	msg, err := windows.UTF16PtrFromString(message)
	if nil != err {
		return err
	}

	_, _, err = outputDebugStringWProc.Call(uintptr(unsafe.Pointer(msg)))
	return err
}
예제 #6
0
파일: windows.go 프로젝트: jmptrader/com
func ClassIDFromString(str string) (classID *GUID, err error) {
	ptrStr, err := windows.UTF16PtrFromString(str)
	if err != nil {
		return
	}

	err = HResultToError(procCLSIDFromString.Call(
		uintptr(unsafe.Pointer(ptrStr)),
		uintptr(unsafe.Pointer(&classID))))
	return
}
func newWindowsEvent(name string) (*windowsEvent, error) {
	str, err := windows.UTF16PtrFromString(name)
	if nil != err {
		return nil, err
	}

	handle, err := windows.CreateEvent(nil, 0, 0, str)
	if nil != err {
		return nil, err
	}

	return &windowsEvent{handle: handle}, nil
}
예제 #8
0
func (pm *realProcessMonitor) Write(message string) error {
	msg, err := windows.UTF16PtrFromString(message)
	if nil != err {
		return err
	}

	var bytesReturned uint32
	err = windows.DeviceIoControl(pm.handle,
		debugOut,
		(*byte)(unsafe.Pointer(msg)),
		uint32((len(message)+1)*2),
		nil,
		0,
		&bytesReturned,
		nil)
	if nil != err {
		fmt.Fprintf(debugger.Console, "PROCESS MONITOR ERROR: %v", err)
	}

	return err
}
예제 #9
0
func TestWin32finddata(t *testing.T) {
	dir, err := ioutil.TempDir("", "go-build")
	if err != nil {
		t.Fatalf("failed to create temp directory: %v", err)
	}
	defer os.RemoveAll(dir)

	path := filepath.Join(dir, "long_name.and_extension")
	f, err := os.Create(path)
	if err != nil {
		t.Fatalf("failed to create %v: %v", path, err)
	}
	f.Close()

	type X struct {
		fd  windows.Win32finddata
		got byte
		pad [10]byte // to protect ourselves

	}
	var want byte = 2 // it is unlikely to have this character in the filename
	x := X{got: want}

	pathp, _ := windows.UTF16PtrFromString(path)
	h, err := windows.FindFirstFile(pathp, &(x.fd))
	if err != nil {
		t.Fatalf("FindFirstFile failed: %v", err)
	}
	err = windows.FindClose(h)
	if err != nil {
		t.Fatalf("FindClose failed: %v", err)
	}

	if x.got != want {
		t.Fatalf("memory corruption: want=%d got=%d", want, x.got)
	}
}
func (r *OutputDebugStringReceiver) createMemoryMappedFile() {
	if nil != r.err {
		return
	}

	var str *uint16
	str, r.err = windows.UTF16PtrFromString("DBWIN_BUFFER")
	if nil != r.err {
		return
	}

	r.buffer, r.err = windows.CreateFileMapping(
		windows.InvalidHandle,
		nil,
		0x4,
		0,
		4096,
		str)
	if nil != r.err {
		return
	}

	r.view, r.err = windows.MapViewOfFile(r.buffer, 0x4, 0, 0, 0)
}
예제 #11
-1
파일: windows.go 프로젝트: jmptrader/com
func classIDFromProgramIDHelper(p *syscall.Proc, programID string) (classID *GUID, err error) {
	ptrProgramID, err := windows.UTF16PtrFromString(programID)
	if err != nil {
		return
	}

	err = HResultToError(p.Call(
		uintptr(unsafe.Pointer(ptrProgramID)),
		uintptr(unsafe.Pointer(&classID))))
	return
}