@@ -15,28 +15,27 @@ var (
15
15
modadvapi32 = syscall .NewLazyDLL ("advapi32.dll" )
16
16
17
17
// procRegSetKeyValue = modadvapi32.NewProc("RegSetKeyValueW")
18
- procRegSetValueEx = modadvapi32 .NewProc ("RegSetValueExW" )
19
- procRegDeleteKeyValue = modadvapi32 .NewProc ("RegDeleteKeyValueW" )
20
- procRegDeleteValue = modadvapi32 .NewProc ("RegDeleteValueW" )
21
- procRegDeleteTree = modadvapi32 .NewProc ("RegDeleteTreeW" )
22
- procOpenEventLog = modadvapi32 .NewProc ("OpenEventLogW" )
23
- procReadEventLog = modadvapi32 .NewProc ("ReadEventLogW" )
24
- procCloseEventLog = modadvapi32 .NewProc ("CloseEventLog" )
25
- procCloseServiceHandle = modadvapi32 .NewProc ("CloseServiceHandle" )
26
- procControlService = modadvapi32 .NewProc ("ControlService" )
27
- procControlTrace = modadvapi32 .NewProc ("ControlTraceW" )
28
- procOpenEventLog = modadvapi32 .NewProc ("OpenEventLogW" )
29
- procOpenSCManager = modadvapi32 .NewProc ("OpenSCManagerW" )
30
- procOpenService = modadvapi32 .NewProc ("OpenServiceW" )
31
- procReadEventLog = modadvapi32 .NewProc ("ReadEventLogW" )
32
- procRegCloseKey = modadvapi32 .NewProc ("RegCloseKey" )
33
- procRegCreateKeyEx = modadvapi32 .NewProc ("RegCreateKeyExW" )
34
- procRegEnumKeyEx = modadvapi32 .NewProc ("RegEnumKeyExW" )
35
- procRegGetValue = modadvapi32 .NewProc ("RegGetValueW" )
36
- procRegOpenKeyEx = modadvapi32 .NewProc ("RegOpenKeyExW" )
37
- procRegSetValueEx = modadvapi32 .NewProc ("RegSetValueExW" )
38
- procStartService = modadvapi32 .NewProc ("StartServiceW" )
39
- procStartTrace = modadvapi32 .NewProc ("StartTraceW" )
18
+ procRegSetValueEx = modadvapi32 .NewProc ("RegSetValueExW" )
19
+ procRegDeleteKeyValue = modadvapi32 .NewProc ("RegDeleteKeyValueW" )
20
+ procRegDeleteValue = modadvapi32 .NewProc ("RegDeleteValueW" )
21
+ procRegDeleteTree = modadvapi32 .NewProc ("RegDeleteTreeW" )
22
+ procOpenEventLog = modadvapi32 .NewProc ("OpenEventLogW" )
23
+ procReadEventLog = modadvapi32 .NewProc ("ReadEventLogW" )
24
+ procCloseEventLog = modadvapi32 .NewProc ("CloseEventLog" )
25
+ procCloseServiceHandle = modadvapi32 .NewProc ("CloseServiceHandle" )
26
+ procControlService = modadvapi32 .NewProc ("ControlService" )
27
+ procControlTrace = modadvapi32 .NewProc ("ControlTraceW" )
28
+ procOpenSCManager = modadvapi32 .NewProc ("OpenSCManagerW" )
29
+ procOpenService = modadvapi32 .NewProc ("OpenServiceW" )
30
+ procRegCloseKey = modadvapi32 .NewProc ("RegCloseKey" )
31
+ procRegCreateKeyEx = modadvapi32 .NewProc ("RegCreateKeyExW" )
32
+ procRegEnumKeyEx = modadvapi32 .NewProc ("RegEnumKeyExW" )
33
+ procRegGetValue = modadvapi32 .NewProc ("RegGetValueW" )
34
+ procRegOpenKeyEx = modadvapi32 .NewProc ("RegOpenKeyExW" )
35
+ procStartService = modadvapi32 .NewProc ("StartServiceW" )
36
+ procStartTrace = modadvapi32 .NewProc ("StartTraceW" )
37
+ procInitializeSecurityDescriptor = modadvapi32 .NewProc ("InitializeSecurityDescriptor" )
38
+ procSetSecurityDescriptorDacl = modadvapi32 .NewProc ("SetSecurityDescriptorDacl" )
40
39
)
41
40
42
41
var (
@@ -396,6 +395,7 @@ func ControlService(hService HANDLE, dwControl uint32, lpServiceStatus *SERVICE_
396
395
}
397
396
398
397
func ControlTrace (hTrace TRACEHANDLE , lpSessionName string , props * EVENT_TRACE_PROPERTIES , dwControl uint32 ) (success bool , e error ) {
398
+
399
399
ret , _ , _ := procControlTrace .Call (
400
400
uintptr (unsafe .Pointer (hTrace )),
401
401
uintptr (unsafe .Pointer (syscall .StringToUTF16Ptr (lpSessionName ))),
@@ -405,11 +405,12 @@ func ControlTrace(hTrace TRACEHANDLE, lpSessionName string, props *EVENT_TRACE_P
405
405
if ret == ERROR_SUCCESS {
406
406
return true , nil
407
407
}
408
- e = errors .New (fmt .Sprintf ("ControlTrace: Error : 0x%x" , ret ))
408
+ e = errors .New (fmt .Sprintf ("error : 0x%x" , ret ))
409
409
return
410
410
}
411
411
412
412
func StartTrace (lpSessionName string , props * EVENT_TRACE_PROPERTIES ) (hTrace TRACEHANDLE , e error ) {
413
+
413
414
ret , _ , _ := procStartTrace .Call (
414
415
uintptr (unsafe .Pointer (& hTrace )),
415
416
uintptr (unsafe .Pointer (syscall .StringToUTF16Ptr (lpSessionName ))),
@@ -418,6 +419,54 @@ func StartTrace(lpSessionName string, props *EVENT_TRACE_PROPERTIES) (hTrace TRA
418
419
if ret == ERROR_SUCCESS {
419
420
return
420
421
}
421
- e = errors .New (fmt .Sprintf ("StartTrace: Error: 0x%x" , ret ))
422
+ e = errors .New (fmt .Sprintf ("error: 0x%x" , ret ))
423
+ return
424
+ }
425
+
426
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/aa378863(v=vs.85).aspx
427
+ func InitializeSecurityDescriptor (rev uint16 ) (pSecurityDescriptor * SECURITY_DESCRIPTOR , e error ) {
428
+
429
+ pSecurityDescriptor = & SECURITY_DESCRIPTOR {}
430
+
431
+ ret , _ , _ := procInitializeSecurityDescriptor .Call (
432
+ uintptr (unsafe .Pointer (pSecurityDescriptor )),
433
+ uintptr (rev ),
434
+ )
435
+
436
+ if ret != 0 {
437
+ return
438
+ }
439
+ e = syscall .GetLastError ()
440
+ return
441
+ }
442
+
443
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/aa379583(v=vs.85).aspx
444
+ func SetSecurityDescriptorDacl (pSecurityDescriptor * SECURITY_DESCRIPTOR , pDacl * ACL ) (e error ) {
445
+
446
+ if pSecurityDescriptor == nil {
447
+ return errors .New ("null descriptor" )
448
+ }
449
+
450
+ var ret uintptr
451
+ if pDacl == nil {
452
+ ret , _ , _ = procSetSecurityDescriptorDacl .Call (
453
+ uintptr (unsafe .Pointer (pSecurityDescriptor )),
454
+ uintptr (0 ), // DaclPresent
455
+ uintptr (0 ), // pDacl
456
+ uintptr (1 ), // DaclDefaulted
457
+ )
458
+ } else {
459
+ ret , _ , _ = procSetSecurityDescriptorDacl .Call (
460
+ uintptr (unsafe .Pointer (pSecurityDescriptor )),
461
+ uintptr (1 ), // DaclPresent
462
+ uintptr (unsafe .Pointer (pDacl )),
463
+ uintptr (0 ), //DaclDefaulted
464
+ )
465
+ }
466
+
467
+ if ret != 0 {
468
+ return
469
+ }
470
+ e = syscall .GetLastError ()
422
471
return
423
472
}
0 commit comments