refactor(capture): screen capture in subprocess

- Move screen capture to child process
- Isolate GDI/BitBlt crashes from agent
- Use -capture flag for internal helper mode
- Add protocol for frame request/response
- Make monitor enumeration thread-safe
This commit is contained in:
2026-09-01 23:25:38 +03:00
parent cc2b1d049b
commit a3c78820ed
14 changed files with 432 additions and 12 deletions
+2
View File
@@ -14,6 +14,8 @@ func filterArgs(args []string) []string {
continue
case lower == "ensure" || strings.HasPrefix(lower, "ensure="):
continue
case lower == "capture" || strings.HasPrefix(lower, "capture="):
continue
}
out = append(out, arg)
}
+1 -1
View File
@@ -7,7 +7,7 @@ import (
func TestFilterArgsDropsLauncherFlags(t *testing.T) {
t.Parallel()
got := filterArgs([]string{"-ensure", "-background", "-foreground", "-addr", "0.0.0.0:5033"})
got := filterArgs([]string{"-ensure", "-background", "-foreground", "-capture", "-addr", "0.0.0.0:5033"})
want := []string{"-addr", "0.0.0.0:5033"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("filterArgs() = %#v, want %#v", got, want)
+13
View File
@@ -14,6 +14,7 @@ var (
procSetConsoleCtrl = kernel32.NewProc("SetConsoleCtrlHandler")
procAllocConsole = kernel32.NewProc("AllocConsole")
procGetStdHandle = kernel32.NewProc("GetStdHandle")
procGetFileType = kernel32.NewProc("GetFileType")
user32 = syscall.NewLazyDLL("user32.dll")
procShowWindow = user32.NewProc("ShowWindow")
consoleCtrlCallback uintptr
@@ -81,6 +82,9 @@ func consoleCtrlHandler(ctrlType uintptr) uintptr {
}
func redirectStdioToNul() {
if stdioIsPipe() {
return
}
nul, err := os.OpenFile("NUL", os.O_RDWR, 0)
if err != nil {
return
@@ -89,3 +93,12 @@ func redirectStdioToNul() {
os.Stdout = nul
os.Stderr = nul
}
func stdioIsPipe() bool {
const fileTypePipe = 3
stdin, _, _ := procGetStdHandle.Call(^uintptr(9))
stdout, _, _ := procGetStdHandle.Call(^uintptr(10))
inType, _, _ := procGetFileType.Call(stdin)
outType, _, _ := procGetFileType.Call(stdout)
return inType == fileTypePipe || outType == fileTypePipe
}