feat: implement security, discovery, history, file transfer, web UI (P0-P3)

This commit is contained in:
2026-08-14 09:45:54 -04:00
parent 8281478f0c
commit 884415c1c1
32 changed files with 1923 additions and 200 deletions
+14 -5
View File
@@ -24,6 +24,7 @@ var (
procGlobalLock = kernel32.NewProc("GlobalLock")
procGlobalUnlock = kernel32.NewProc("GlobalUnlock")
procGlobalFree = kernel32.NewProc("GlobalFree")
procGlobalSize = kernel32.NewProc("GlobalSize")
)
type windowsClipboard struct{}
@@ -52,9 +53,16 @@ func (c *windowsClipboard) Read() (string, error) {
defer func() { _, _, _ = procGlobalUnlock.Call(h) }()
// Query the actual size of the global memory block so we never read past it.
size, _, _ := procGlobalSize.Call(h)
if size == 0 {
return "", nil
}
units := size / 2 // bytes → UTF-16 code units
// Lock and read the global memory block.
// Use a helper to keep the uintptr→unsafe.Pointer conversion close to the syscall.
mem := lockAndRead(h)
mem := lockAndRead(h, units)
if mem == nil {
return "", fmt.Errorf("clipboard read: GlobalLock failed")
}
@@ -103,9 +111,10 @@ func (c *windowsClipboard) Write(text string) error {
return nil
}
// lockAndRead locks a global memory handle and returns its UTF-16 data.
// Returns nil on failure. Caller must call GlobalUnlock after use.
func lockAndRead(h uintptr) []uint16 {
// lockAndRead locks a global memory handle and returns its UTF-16 data of the
// given length (in code units). Returns nil on failure. Caller must call
// GlobalUnlock after use.
func lockAndRead(h uintptr, units uintptr) []uint16 {
p, _, _ := procGlobalLock.Call(h)
if p == 0 {
return nil
@@ -113,7 +122,7 @@ func lockAndRead(h uintptr) []uint16 {
// Use unsafe.Add to derive a pointer from nil; the uintptr came from
// GlobalLock (GMEM_FIXED) and is a valid virtual address, not a Go pointer.
ptr := unsafe.Add(unsafe.Pointer(nil), p)
return unsafe.Slice((*uint16)(ptr), 1<<20)
return unsafe.Slice((*uint16)(ptr), units)
}
// lockAndWrite locks a global memory handle and copies UTF-16 data into it.