-
Notifications
You must be signed in to change notification settings - Fork 2
/
dos_header.go
46 lines (40 loc) · 1.2 KB
/
dos_header.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pe
import (
"encoding/binary"
"errors"
"io"
)
type DOSHeader struct {
Magic uint16
BytesOnLastPageOfFile uint16
PagesInFile uint16
Relocations uint16
SizeOfHeader uint16
MinExtraParagraphsNeeded uint16
MaxExtraParagraphsNeeded uint16
InitialSS uint16
InitialSP uint16
Checksum uint16
InitialIP uint16
InitialCS uint16
AddressOfRelocationTable uint16
OverlayNumber uint16
ReservedWords1 [4]uint16
OEMIdentifier uint16
OEMInformation uint16
ReservedWords2 [10]uint16
AddressOfNewEXEHeader uint32
}
func (f *File) readDOSHeader() error {
r := io.NewSectionReader(f.f, 0, int64(DOSHeaderSize))
if err := binary.Read(r, binary.LittleEndian, &f.DOSHeader); err != nil {
return err
}
if f.DOSHeader.Magic != ImageDOSSignature && f.DOSHeader.Magic != ImageDOSZMSignature {
return errors.New("invalid PE file signature")
}
if f.DOSHeader.AddressOfNewEXEHeader < 4 || f.DOSHeader.AddressOfNewEXEHeader > f.size {
return errors.New("invalid e_lfanew value. Probably not a PE file")
}
return nil
}