Commit e9f0fc88 authored by Robin Eklind's avatar Robin Eklind Committed by Alex Brainman

debug/pe: support PE files which contain no symbol table (if NumberOfSymbols is…

debug/pe: support PE files which contain no symbol table (if NumberOfSymbols is equal to 0 in the IMAGE_FILE_HEADER structure).

No longer assume that e_lfanew (in the IMAGE_DOS_HEADER strcuture) is always one byte. It is now regarded as a 4 byte uint32.

Fixes #4177.

R=golang-dev, alex.brainman, dave, minux.ma
CC=golang-dev
https://golang.org/cl/6587048
parent 6f7b66db
......@@ -131,12 +131,13 @@ func NewFile(r io.ReaderAt) (*File, error) {
}
var base int64
if dosheader[0] == 'M' && dosheader[1] == 'Z' {
signoff := int64(binary.LittleEndian.Uint32(dosheader[0x3c:]))
var sign [4]byte
r.ReadAt(sign[0:], int64(dosheader[0x3c]))
r.ReadAt(sign[:], signoff)
if !(sign[0] == 'P' && sign[1] == 'E' && sign[2] == 0 && sign[3] == 0) {
return nil, errors.New("Invalid PE File Format.")
}
base = int64(dosheader[0x3c]) + 4
base = signoff + 4
} else {
base = int64(0)
}
......@@ -148,13 +149,15 @@ func NewFile(r io.ReaderAt) (*File, error) {
return nil, errors.New("Invalid PE File Format.")
}
var ss []byte
if f.FileHeader.NumberOfSymbols > 0 {
// Get COFF string table, which is located at the end of the COFF symbol table.
sr.Seek(int64(f.FileHeader.PointerToSymbolTable+COFFSymbolSize*f.FileHeader.NumberOfSymbols), os.SEEK_SET)
var l uint32
if err := binary.Read(sr, binary.LittleEndian, &l); err != nil {
return nil, err
}
ss := make([]byte, l)
ss = make([]byte, l)
if _, err := r.ReadAt(ss, int64(f.FileHeader.PointerToSymbolTable+COFFSymbolSize*f.FileHeader.NumberOfSymbols)); err != nil {
return nil, err
}
......@@ -188,6 +191,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
}
f.Symbols = append(f.Symbols, s)
}
}
// Process sections.
sr.Seek(base, os.SEEK_SET)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment