github.com/saferwall/pe@v1.5.2/version_test.go (about)

     1  // Copyright 2021 Saferwall. All rights reserved.
     2  // Use of this source code is governed by Apache v2 license
     3  // license that can be found in the LICENSE file.
     4  
     5  package pe
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  var peVersionResourceTests = []struct {
    12  	in               string
    13  	out              error
    14  	versionResources map[string]string
    15  }{
    16  	{
    17  		getAbsoluteFilePath("test/putty.exe"),
    18  		nil,
    19  		map[string]string{"CompanyName": "Simon Tatham", "FileDescription": "SSH, Telnet and Rlogin client", "FileVersion": "Release 0.73 (with embedded help)", "InternalName": "PuTTY", "OriginalFilename": "PuTTY", "ProductName": "PuTTY suite", "ProductVersion": "Release 0.73"},
    20  	},
    21  	{
    22  		getAbsoluteFilePath("test/brave.exe"),
    23  		nil,
    24  		map[string]string{"CompanyName": "Brave Software, Inc.", "FileDescription": "Brave Browser", "FileVersion": "80.1.7.92", "InternalName": "chrome_exe"},
    25  	},
    26  	{
    27  		getAbsoluteFilePath("test/impbyord.exe"),
    28  		nil,
    29  		map[string]string{},
    30  	},
    31  	{
    32  		getAbsoluteFilePath("test/WdBoot.sys"),
    33  		nil,
    34  		map[string]string{"CompanyName": "Microsoft Corporation", "FileDescription": "Microsoft antimalware boot driver", "FileVersion": "4.18.1906.3 (GitEnlistment(winpbld).190621-1227)", "InternalName": "WdBoot"},
    35  	},
    36  	{
    37  		getAbsoluteFilePath("test/shimeng.dll"),
    38  		nil,
    39  		map[string]string{"CompanyName": "Microsoft Corporation", "FileDescription": "Shim Engine DLL", "FileVersion": "10.0.17763.1 (WinBuild.160101.0800)", "OriginalFilename": "Shim Engine DLL (IAT)", "LegalCopyright": "© Microsoft Corporation. All rights reserved.", "InternalName": "Shim Engine DLL (IAT)", "ProductName": "Microsoft® Windows® Operating System", "ProductVersion": "10.0.17763.1"},
    40  	},
    41  	{
    42  		getAbsoluteFilePath("test/pwsh.exe"),
    43  		nil,
    44  		map[string]string{"Assembly Version": "7.3.4.500", "Comments": "PowerShell on Windows top-level project", "CompanyName": "Microsoft Corporation", "FileDescription": "pwsh", "FileVersion": "7.3.4.500", "InternalName": "pwsh.dll", "LegalCopyright": "(c) Microsoft Corporation.", "OriginalFilename": "pwsh.dll", "ProductName": "PowerShell", "ProductVersion": "7.3.4 SHA: b59f05d5a1b2fceca231f75c53c203a02edf6203"},
    45  	},
    46  }
    47  
    48  func TestParseVersionResources(t *testing.T) {
    49  	for _, tt := range peVersionResourceTests {
    50  		t.Run(tt.in, func(t *testing.T) {
    51  			file, err := New(tt.in, &Options{})
    52  			if err != nil {
    53  				t.Fatalf("New(%s) failed, reason: %v", tt.in, err)
    54  			}
    55  
    56  			got := file.Parse()
    57  			if got != nil {
    58  				t.Errorf("Parse(%s) got %v, want %v", tt.in, got, tt.out)
    59  			}
    60  			vers, err := file.ParseVersionResources()
    61  			if err != nil {
    62  				t.Fatalf("ParseVersionResurces(%s) failed, reason: %v", tt.in, err)
    63  			}
    64  			for k, v := range tt.versionResources {
    65  				val, ok := vers[k]
    66  				if !ok {
    67  					t.Errorf("%s: should have %s version resource", tt.in, k)
    68  				}
    69  				if val != v {
    70  					t.Errorf("%s: expected: %s version resource got: %s. Available resources: %v", tt.in, v, val, vers)
    71  				}
    72  			}
    73  		})
    74  	}
    75  }