Skip to content

Commit

Permalink
Rename ofreg.go and close key
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Nov 21, 2022
1 parent adfa0d5 commit 3d6b81e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
23 changes: 17 additions & 6 deletions internal/wclayer/converttobaselayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
var hiveNames = []string{"DEFAULT", "SAM", "SECURITY", "SOFTWARE", "SYSTEM"}

// Ensure the given file exists as an ordinary file, and create a minimal hive file if not.
func ensureHive(path string, root *os.File) error {
_, err := safefile.LstatRelative(path, root)
func ensureHive(path string, root *os.File) (err error) {
_, err = safefile.LstatRelative(path, root)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("accessing %s: %w", path, err)
}
Expand All @@ -31,22 +31,33 @@ func ensureHive(path string, root *os.File) error {
return fmt.Errorf("failed to get OS version")
}

fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
var fullPath string
fullPath, err = longpath.LongAbs(filepath.Join(root.Name(), path))
if err != nil {
return fmt.Errorf("getting path: %w", err)
}

var key syscall.Handle
if err := winapi.ORCreateHive(&key); err != nil {
err = winapi.ORCreateHive(&key)
if err != nil {
return fmt.Errorf("creating hive: %w", err)
}

hivePath, err := syscall.UTF16PtrFromString(fullPath)
defer func() {
closeErr := winapi.ORCloseHive(&key)
if closeErr != nil {
err = fmt.Errorf("closing hive key: %w", closeErr)
}
}()

var hivePath *uint16
hivePath, err = syscall.UTF16PtrFromString(fullPath)
if err != nil {
return fmt.Errorf("getting path: %w", err)
}

if err := winapi.ORSaveHive(key, hivePath, version.MajorVersion, version.MinorVersion); err != nil {
err = winapi.ORSaveHive(key, hivePath, version.MajorVersion, version.MinorVersion)
if err != nil {
return fmt.Errorf("saving hive: %w", err)
}

Expand Down
1 change: 1 addition & 0 deletions internal/winapi/ofregistry.go → internal/winapi/ofreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ package winapi

//sys ORCreateHive(key *syscall.Handle) (regerrno error) = offreg.ORCreateHive
//sys ORSaveHive(key syscall.Handle, file *uint16, OsMajorVersion uint32, OsMinorVersion uint32) (regerrno error) = offreg.ORSaveHive
//sys ORCloseHive(key *syscall.Handle) (regerrno error) = offreg.ORCloseHive
2 changes: 1 addition & 1 deletion internal/winapi/winapi.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package winapi

//go:generate go run ..\..\mksyscall_windows.go -output zsyscall_windows.go bindflt.go user.go console.go system.go net.go path.go thread.go jobobject.go logon.go memory.go process.go processor.go devices.go filesystem.go errors.go ofregistry.go
//go:generate go run ..\..\mksyscall_windows.go -output zsyscall_windows.go bindflt.go user.go console.go system.go net.go path.go thread.go jobobject.go logon.go memory.go process.go processor.go devices.go filesystem.go errors.go ofreg.go
9 changes: 9 additions & 0 deletions internal/winapi/zsyscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d6b81e

Please sign in to comment.