github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/dokan_info.go (about) 1 // Copyright 2018 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package libdokan 6 7 import ( 8 "bytes" 9 "context" 10 "crypto/sha256" 11 "fmt" 12 "io" 13 "os" 14 "os/exec" 15 16 "github.com/keybase/client/go/logger" 17 ) 18 19 const shortPath = `DOKAN1.DLL` 20 const syswow64 = `C:\WINDOWS\SYSWOW64\` 21 const system32 = `C:\WINDOWS\SYSTEM32\` 22 23 type errorPrinter struct { 24 buf bytes.Buffer 25 } 26 27 func (ep *errorPrinter) Printf(s string, os ...interface{}) { 28 fmt.Fprintf(&ep.buf, s, os...) 29 } 30 31 func debugFileInfo(epc *errorPrinter, path string) { 32 f, err := os.Open(path) 33 epc.Printf("debugFileInfo: open(%q) -> %v, %+v\n", path, f, err) 34 if err != nil { 35 return 36 } 37 defer f.Close() 38 fi, err := f.Stat() 39 epc.Printf("debugFileInfo: stat(%q) -> %v, %+v\n", path, fi, err) 40 if fi != nil { 41 epc.Printf("debugFileInfo: modtime is %v\n", fi.ModTime()) 42 } 43 h := sha256.New() 44 n, err := io.Copy(h, f) 45 epc.Printf("debugFileInfo: read bytes -> %d, %+v\n", n, err) 46 if err != nil { 47 return 48 } 49 epc.Printf("debugFileInfo: sha256 %X\n", h.Sum(nil)) 50 } 51 52 func logDokanFilesInfo(epc *errorPrinter) { 53 cwd := `` 54 if d, err := os.Getwd(); err == nil { 55 cwd = d + `\` 56 } 57 for _, d := range []string{syswow64, system32, cwd} { 58 debugFileInfo(epc, d+shortPath) 59 } 60 for _, d := range []string{syswow64, system32} { 61 debugFileInfo(epc, d+`DRIVERS\DOKAN.SYS`) 62 debugFileInfo(epc, d+`DRIVERS\DOKAN1.SYS`) 63 debugFileInfo(epc, d+`DRIVERS\DOKAN2.SYS`) 64 } 65 } 66 67 func logDokanServiceInfo(epc *errorPrinter) { 68 epc.Printf("Running 'sc query dokan1'") 69 bs, err := exec.Command("sc", "query", "dokan1").CombinedOutput() 70 if err != nil { 71 epc.Printf("exec.Command error: %+v\n", err) 72 return 73 } 74 epc.Printf("%s\n", bs) 75 } 76 77 func logDokanInfo(ctx context.Context, log logger.Logger) { 78 var epc errorPrinter 79 logDokanFilesInfo(&epc) 80 logDokanServiceInfo(&epc) 81 log.CDebugf(ctx, "Dokan info:\n%s", epc.buf.Bytes()) 82 }