@@ -8,7 +8,6 @@ package pe
8
8
import (
9
9
"debug/dwarf"
10
10
"encoding/binary"
11
- "errors"
12
11
"fmt"
13
12
"io"
14
13
"os"
58
57
sizeofOptionalHeader64 = uint16 (binary .Size (OptionalHeader64 {}))
59
58
)
60
59
60
+ // TODO(brainman): add Load function, as a replacement for NewFile, that does not call removeAuxSymbols (for performance)
61
+
61
62
// NewFile creates a new File for accessing a PE binary in an underlying reader.
62
63
func NewFile (r io.ReaderAt ) (* File , error ) {
63
64
f := new (File )
@@ -73,7 +74,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
73
74
var sign [4 ]byte
74
75
r .ReadAt (sign [:], signoff )
75
76
if ! (sign [0 ] == 'P' && sign [1 ] == 'E' && sign [2 ] == 0 && sign [3 ] == 0 ) {
76
- return nil , errors . New ("Invalid PE File Format." )
77
+ return nil , fmt . Errorf ("Invalid PE COFF file signature of %v." , sign )
77
78
}
78
79
base = signoff + 4
79
80
} else {
@@ -83,8 +84,10 @@ func NewFile(r io.ReaderAt) (*File, error) {
83
84
if err := binary .Read (sr , binary .LittleEndian , & f .FileHeader ); err != nil {
84
85
return nil , err
85
86
}
86
- if f .FileHeader .Machine != IMAGE_FILE_MACHINE_UNKNOWN && f .FileHeader .Machine != IMAGE_FILE_MACHINE_AMD64 && f .FileHeader .Machine != IMAGE_FILE_MACHINE_I386 {
87
- return nil , errors .New ("Invalid PE File Format." )
87
+ switch f .FileHeader .Machine {
88
+ case IMAGE_FILE_MACHINE_UNKNOWN , IMAGE_FILE_MACHINE_AMD64 , IMAGE_FILE_MACHINE_I386 :
89
+ default :
90
+ return nil , fmt .Errorf ("Unrecognised COFF file header machine value of 0x%x." , f .FileHeader .Machine )
88
91
}
89
92
90
93
var err error
0 commit comments