func (i *Inspector) duplicateHandle(handle SystemHandle) (windows.Handle, error) {
	p, hasCachedHandle := i.processHandles[handle.UniqueProcessID]
	if !hasCachedHandle {
		var err error
		p, err = windows.OpenProcess(
			windows.PROCESS_DUP_HANDLE,
			true,
			uint32(handle.UniqueProcessID),
		)
		i.processHandles[handle.UniqueProcessID] = p
		if err != nil {
			return 0, err
		}
	} else if p == 0 { // Error was cached
		return 0, errors.New("failed to open process")
	}
	var h windows.Handle
	if err := windows.DuplicateHandle(
		p,
		windows.Handle(handle.HandleValue),
		windows.CurrentProcess(),
		&h,
		0,
		false,
		windows.DUPLICATE_SAME_ACCESS,
	); err != nil {
		return 0, err
	}
	return h, nil
}
// duplicateHandle duplicates a handle into our own process. It uses a cache for
// process handles that are used repeatedly.
duplicateHandle duplicates a handle into our own process. It uses a cache for
process handles that are used repeatedly.
// duplicateHandle duplicates a handle into our own process . It uses a cache for // process handles that are used repeatedly .
func (i *Inspector) duplicateHandle(handle SystemHandle) (windows.Handle, error) {
	p, hasCachedHandle := i.processHandles[handle.UniqueProcessID]
	if !hasCachedHandle {
		var err error
		p, err = windows.OpenProcess(
			windows.PROCESS_DUP_HANDLE,
			true,
			uint32(handle.UniqueProcessID),
		)
		i.processHandles[handle.UniqueProcessID] = p
		if err != nil {
			return 0, err
		}
	} else if p == 0 { 
		return 0, errors.New("failed to open process")
	}
	var h windows.Handle
	if err := windows.DuplicateHandle(
		p,
		windows.Handle(handle.HandleValue),
		windows.CurrentProcess(),
		&h,
		0,
		false,
		windows.DUPLICATE_SAME_ACCESS,
	); err != nil {
		return 0, err
	}
	return h, nil
}
func ( i * Inspector ) duplicateHandle ( handle SystemHandle ) ( windows . Handle , error ) { p , hasCachedHandle := i . processHandles [ handle . UniqueProcessID ] if ! hasCachedHandle { var err error p , err = windows . OpenProcess ( windows . PROCESS_DUP_HANDLE , true , uint32 ( handle . UniqueProcessID ) , ) i . processHandles [ handle . UniqueProcessID ] = p if err != nil { return 0 , err } } else if p == 0 { return 0 , errors . New ( " " ) } var h windows . Handle if err := windows . DuplicateHandle ( p , windows . Handle ( handle . HandleValue ) , windows . CurrentProcess ( ) , & h , 0 , false , windows . DUPLICATE_SAME_ACCESS , ) ; err != nil { return 0 , err } return h , nil }
duplicateHandle duplicates a handle into our own process.
duplicateHandle duplicates a handle into our own process .
// Error was cached