{"record":{"id":"81d1aa7511efc420","repo":"moonD4rk/HackBrowserData","slug":"find-file-handle-for-s-w","errorCode":null,"errorMessage":"find file handle for %s: %w","messagePattern":"find file handle for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"filemanager/copy_windows.go","lineNumber":29,"sourceCode":"\n\t\"github.com/moond4rk/hackbrowserdata/utils/winapi\"\n)\n\n// copyLocked copies a file that is locked by another process (e.g., Chrome's\n// Cookies database with PRAGMA locking_mode=EXCLUSIVE).\n//\n// Approach: DuplicateHandle + FileMapping\n//  1. Enumerate all open file handles via NtQuerySystemInformation\n//  2. Find the handle matching the target file path\n//  3. Duplicate that handle into our process via DuplicateHandle\n//  4. Read file content through memory-mapped I/O (CreateFileMapping + MapViewOfFile)\n//  5. Write content to destination\n//\n// This requires only normal user privileges (no admin needed).\nfunc copyLocked(src, dst string) error {\n\thandle, err := findFileHandle(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"find file handle for %s: %w\", src, err)\n\t}\n\tdefer windows.CloseHandle(handle)\n\n\tdata, err := readFileContent(handle)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read via file mapping: %w\", err)\n\t}\n\n\treturn os.WriteFile(dst, data, 0o600)\n}\n\n// findFileHandle enumerates all system handles, finds the one matching the\n// target file path, and duplicates it into the current process.\nfunc findFileHandle(targetPath string) (windows.Handle, error) {\n\t// Extract a stable suffix for matching that avoids short path name issues\n\t// (e.g., RUNNER~1 vs runneradmin in the username portion).\n\t// We match from AppData onwards, which uniquely identifies each browser:\n\t//   Google\\Chrome\\User Data\\Default\\Network\\Cookies  (Chrome)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/filemanager/copy_windows.go#L11-L47","documentation":"Wrapped error from copyLocked's first step on Windows: findFileHandle failed while enumerating system handles via NtQuerySystemInformation to locate a process holding the source file open. The %s is the locked source path. Failure here means the handle enumeration/duplication machinery could not run or found nothing usable, before any file-mapping read is attempted.","triggerScenarios":"Thrown at filemanager/copy_windows.go:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the target browser process is actually running and holds the file open","Check the underlying NtQuerySystemInformation/DuplicateHandle error for privilege or handle-count limits","Close other heavy-handle processes and retry enumeration","Fall back to closing the browser so the file is no longer exclusively locked"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}