github.com/saferwall/pe@v1.5.2/anomaly_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  func TestGetAnomalies(t *testing.T) {
    12  
    13  	tests := []struct {
    14  		in      string
    15  		out []string
    16  	}{
    17  		{
    18  			getAbsoluteFilePath(
    19  			"test/050708404553416d103652a7ca1f887ab81f533a019a0eeff0e6bb460a202cde"),
    20  			[]string{AnoReservedDataDirectoryEntry},
    21  		},
    22  		{
    23  			getAbsoluteFilePath(
    24  			"test/0585495341e0ffaae1734acb78708ff55cd3612d844672d37226ef63d12652d0"),
    25  			[]string{AnoAddressOfEntryPointNull, AnoMajorSubsystemVersion},
    26  		},
    27  	}
    28  
    29  	for _, tt := range tests {
    30  		t.Run(tt.in, func(t *testing.T) {
    31  			file, err := New(tt.in, &Options{})
    32  			if err != nil {
    33  				t.Fatalf("New(%s) failed, reason: %v", tt.in, err)
    34  			}
    35  			err = file.Parse()
    36  			if err != nil {
    37  				t.Fatalf("Parse(%s) failed, reason: %v", tt.in, err)
    38  			}
    39  
    40  			err = file.GetAnomalies()
    41  			if err != nil {
    42  				t.Fatalf("GetAnomalies(%s) failed, reason: %v", tt.in, err)
    43  			}
    44  
    45  			for _, ano := range tt.out {
    46  				if !stringInSlice(ano, file.Anomalies) {
    47  					t.Errorf("anomaly(%s) not found in anomalies, got: %v", ano, file.Anomalies)
    48  				}
    49  			}
    50  
    51  		})
    52  	}
    53  }