MCPcopy
hub / github.com/hardentools/hardentools / hardenKey

Function hardenKey

registry_utils.go:295–317  ·  view source on GitHub ↗

Harden Dword value including saving the original state.

(rootKey registry.Key, path string, valueName string, hardenedValue uint32)

Source from the content-addressed store, hash-verified

293
294// Harden Dword value including saving the original state.
295func hardenKey(rootKey registry.Key, path string, valueName string, hardenedValue uint32) error {
296 rootKeyName, _ := getRootKeyName(rootKey)
297 key, _, err := registry.CreateKey(rootKey, path, registry.WRITE)
298 if err != nil {
299 return fmt.Errorf("Couldn't create / open registry key for write access: %s\\%s",
300 rootKeyName, path)
301 }
302 defer key.Close()
303
304 // Save current state.
305 err = saveOriginalRegistryDWORD(rootKey, path, valueName)
306 if err != nil {
307 return err
308 }
309 // Harden.
310 err = key.SetDWordValue(valueName, hardenedValue)
311 if err != nil {
312 return fmt.Errorf("Couldn't set registry value: %s \\ %s \\ %s",
313 rootKeyName, path, valueName)
314 }
315
316 return nil
317}
318
319// Harden SZ (String) value including saving the original state.
320func hardenKeySZ(rootKey registry.Key, path string, valueName string, hardenedValue string) error {

Callers 1

HardenMethod · 0.85

Calls 2

getRootKeyNameFunction · 0.85

Tested by

no test coverage detected