(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestParseFile(t *testing.T) { |
| 32 | var tests = []struct { |
| 33 | file string |
| 34 | hasSymbols bool |
| 35 | hasSections bool |
| 36 | hasImports bool |
| 37 | versionResources map[string]string |
| 38 | }{ |
| 39 | {filepath.Join(os.Getenv("windir"), "notepad.exe"), true, true, true, map[string]string{"OriginalFilename": "NOTEPAD.EXE", "CompanyName": "Microsoft Corporation"}}, |
| 40 | {filepath.Join(os.Getenv("windir"), "regedit.exe"), true, true, true, nil}, |
| 41 | {filepath.Join(os.Getenv("windir"), "system32", "svchost.exe"), true, true, true, map[string]string{"OriginalFilename": "svchost.exe"}}, |
| 42 | {filepath.Join(os.Getenv("windir"), "system32", "kernel32.dll"), true, true, true, map[string]string{"CompanyName": "Microsoft Corporation"}}, |
| 43 | } |
| 44 | |
| 45 | for _, n := range tests { |
| 46 | tt := n |
| 47 | t.Run(tt.file, func(t *testing.T) { |
| 48 | pe, err := ParseFile(tt.file, |
| 49 | WithSections(), |
| 50 | WithSymbols(), |
| 51 | WithVersionResources(), |
| 52 | WithSectionEntropy(), |
| 53 | WithSectionMD5(), |
| 54 | ) |
| 55 | if err != nil { |
| 56 | t.Fatalf("%s: %v", tt.file, err) |
| 57 | } |
| 58 | if pe == nil { |
| 59 | t.Fatalf("%s: PE metadata is nil", tt.file) |
| 60 | } |
| 61 | if len(pe.Symbols) > 0 != tt.hasSymbols { |
| 62 | t.Errorf("%s: expected to have symbols", tt.file) |
| 63 | } |
| 64 | if len(pe.Sections) > 0 != tt.hasSections { |
| 65 | t.Errorf("%s: expected to have sections", tt.file) |
| 66 | } |
| 67 | if len(pe.Imports) > 0 != tt.hasImports { |
| 68 | t.Errorf("%s: expected to have imports", tt.file) |
| 69 | } |
| 70 | sec := pe.Sections[0] |
| 71 | if sec.Md5 == "" { |
| 72 | t.Errorf("%s: section should have MD5 hash", tt.file) |
| 73 | } |
| 74 | if sec.Entropy == 0.0 { |
| 75 | t.Errorf("%s: section should have entropy value", tt.file) |
| 76 | } |
| 77 | if tt.versionResources != nil { |
| 78 | for k, v := range tt.versionResources { |
| 79 | vers := pe.VersionResources |
| 80 | val, ok := vers[k] |
| 81 | if !ok { |
| 82 | t.Errorf("%s: should have %s version resource", tt.file, k) |
| 83 | } |
| 84 | if val != v { |
| 85 | t.Errorf("%s: expected: %s version resource got: %s. Available resources: %v", tt.file, v, val, vers) |
| 86 | } |
| 87 | } |
| 88 | } |
nothing calls this directly
no test coverage detected