]> Cypherpunks repositories - gostls13.git/commit
debug/pe: enable parsing of variable length optional header in PE file
authorPrashant Agrawal <prashant.a.vjti@gmail.com>
Sat, 18 May 2019 00:55:20 +0000 (17:55 -0700)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 29 Aug 2019 08:57:06 +0000 (08:57 +0000)
commit3b92f36d15c868e856be71c0fadfc7ff97039b96
tree38e4d4d710a83ce506231707f578f0c96d5e6dbe
parent8e4399ff77e7967543fb9f383511b3f3f8470cda
debug/pe: enable parsing of variable length optional header in PE file

The debug/pe package assumes there are always 16 entries in
DataDirectory in OptionalHeader32/64
ref pe.go:
...
NumberOfRvaAndSizes uint32
DataDirectory [16]DataDirectory
}
...

But that is not always the case, there could be less no of
entries (PE signed linux kernel for example):
$ sudo pev /boot/vmlinuz-4.15.0-47-generic
....
Data-dictionary entries: 6
....

In such case, the parsing gives incorrect results.
This changes aims to fix that by:
1. Determining type of optional header by looking at header
   magic instead of size
2. Parsing optional header in 2 steps:
   a. Fixed part
   b. Variable data directories part

Testing:
1. Fixed existing test cases to reflect the change
2. Added new file (modified linux kernel image)
   which has smaller number of data directories

Fixes #32126

Change-Id: Iee56ecc4369a0e75a4be805e7cb8555c7d81ae2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/177959
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/debug/pe/file.go
src/debug/pe/file_test.go
src/debug/pe/testdata/vmlinuz-4.15.0-47-generic [new file with mode: 0644]