From 1135bf6150a5a2cec2ea005c8a6d27fa75581f31 Mon Sep 17 00:00:00 2001 From: Ramiz Polic Date: Fri, 9 Feb 2024 11:00:36 +0100 Subject: [PATCH] feat: fix windows analyzer test --- cli/analyzer/windows/registry.go | 6 ++++-- cli/analyzer/windows/registry_test.go | 2 +- ...OFTWARE => W10_21H2_Pro_20211012_19044.SOFTWARE} | Bin 3 files changed, 5 insertions(+), 3 deletions(-) rename cli/analyzer/windows/testdata/{W10_21H2_Pro/SOFTWARE => W10_21H2_Pro_20211012_19044.SOFTWARE} (100%) diff --git a/cli/analyzer/windows/registry.go b/cli/analyzer/windows/registry.go index c53e5de010..f21a382c1d 100644 --- a/cli/analyzer/windows/registry.go +++ b/cli/analyzer/windows/registry.go @@ -48,7 +48,7 @@ import ( // - system apps: WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* // // User NTUSER.DAT registry keys accessed: -// - user apps: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall +// - user apps: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* var defaultRegistryRootPaths = []string{ "/Windows/System32/config/SOFTWARE", // Windows Vista and newer @@ -78,6 +78,7 @@ func NewRegistryForMount(mountPath string, logger *log.Entry) (*Registry, error) } func NewRegistry(registryFilePath string, logger *log.Entry) (*Registry, error) { + // Use filepath clean to ensure path is platform-independent registryFile, err := os.Open(filepath.Clean(registryFilePath)) if err != nil { return nil, fmt.Errorf("cannot open registry file: %w", err) @@ -210,7 +211,8 @@ func (r *Registry) GetUsersApps() ([]map[string]string, error) { return // silent skip, not a user profile } - // Open profile registry file to access profile-specific registry + // Open profile registry file to access profile-specific registry. + // Use filepath clean to ensure path is platform-independent. profileRegPath := path.Join(profileLocation, "NTUSER.DAT") profileRegFile, err := os.Open(filepath.Clean(profileRegPath)) if err != nil { diff --git a/cli/analyzer/windows/registry_test.go b/cli/analyzer/windows/registry_test.go index e326ade5e8..816576baf5 100644 --- a/cli/analyzer/windows/registry_test.go +++ b/cli/analyzer/windows/registry_test.go @@ -35,7 +35,7 @@ import ( func TestRegistry(t *testing.T) { // from https://github.com/AndrewRathbun/VanillaWindowsRegistryHives/tree/d12ba60d8dd283a4a17b1a02295356a6bed093cf/Windows10/21H2/W10_21H2_Pro_20211012_19044.1288 - registryFilePath := "testdata/W10_21H2_Pro/SOFTWARE" + registryFilePath := "testdata/W10_21H2_Pro_20211012_19044.SOFTWARE" // when reg, err := NewRegistry(registryFilePath, log.NewEntry(&log.Logger{})) diff --git a/cli/analyzer/windows/testdata/W10_21H2_Pro/SOFTWARE b/cli/analyzer/windows/testdata/W10_21H2_Pro_20211012_19044.SOFTWARE similarity index 100% rename from cli/analyzer/windows/testdata/W10_21H2_Pro/SOFTWARE rename to cli/analyzer/windows/testdata/W10_21H2_Pro_20211012_19044.SOFTWARE