(driverName string, driverPath string)
| 17 | } |
| 18 | |
| 19 | func createKextService(driverName string, driverPath string) (*KextService, error) { |
| 20 | // Open the service manager: |
| 21 | manager, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_ALL_ACCESS) |
| 22 | if err != nil { |
| 23 | return nil, fmt.Errorf("failed to open service manager: %d", err) |
| 24 | } |
| 25 | defer windows.CloseServiceHandle(manager) |
| 26 | |
| 27 | // Convert the driver name to a UTF16 string |
| 28 | driverNameU16, err := syscall.UTF16FromString(driverName) |
| 29 | if err != nil { |
| 30 | return nil, fmt.Errorf("failed to convert driver name to UTF16 string: %w", err) |
| 31 | } |
| 32 | |
| 33 | // Check if there is an old service. |
| 34 | service, err := windows.OpenService(manager, &driverNameU16[0], windows.SERVICE_ALL_ACCESS) |
| 35 | if err == nil { |
| 36 | log.Warning("kext: old driver service was found") |
| 37 | oldService := &KextService{handle: service} |
| 38 | err := deleteService(manager, oldService, driverNameU16) |
| 39 | if err != nil { |
| 40 | return nil, fmt.Errorf("failed to delete old driver service: %s", err) |
| 41 | } |
| 42 | |
| 43 | service = winInvalidHandleValue |
| 44 | log.Info("kext: old driver service was deleted successfully") |
| 45 | } |
| 46 | |
| 47 | driverPathU16, err := syscall.UTF16FromString(driverPath) |
| 48 | |
| 49 | // Create the service |
| 50 | service, err = windows.CreateService(manager, &driverNameU16[0], &driverNameU16[0], windows.SERVICE_ALL_ACCESS, windows.SERVICE_KERNEL_DRIVER, windows.SERVICE_DEMAND_START, windows.SERVICE_ERROR_NORMAL, &driverPathU16[0], nil, nil, nil, nil, nil) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | |
| 55 | return &KextService{handle: service}, nil |
| 56 | } |
| 57 | |
| 58 | func deleteService(manager windows.Handle, service *KextService, driverName []uint16) error { |
| 59 | // Stop and wait before deleting |
no test coverage detected