From 5183ad696c708ab5fc65006413019b1ef96aa91b Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 18 Apr 2016 16:42:17 +1000 Subject: [PATCH] debug/pe: add some documentation and TODO No code changes. Just moved ImportDirectory next to ImportedSymbols. And moved useless FormatError to the bottom of file.go. Updates #15345 Change-Id: I91ff243cefd18008b1c5ee9ec4326583deee431b Reviewed-on: https://go-review.googlesource.com/22182 Reviewed-by: David Crawshaw Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- src/debug/pe/file.go | 52 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/debug/pe/file.go b/src/debug/pe/file.go index c68ff1bdce..bfc4cf8a18 100644 --- a/src/debug/pe/file.go +++ b/src/debug/pe/file.go @@ -59,16 +59,6 @@ type Symbol struct { StorageClass uint8 } -type ImportDirectory struct { - OriginalFirstThunk uint32 - TimeDateStamp uint32 - ForwarderChain uint32 - Name uint32 - FirstThunk uint32 - - dll string -} - // Data reads and returns the contents of the PE section. func (s *Section) Data() ([]byte, error) { dat := make([]byte, s.sr.Size()) @@ -82,21 +72,6 @@ func (s *Section) Data() ([]byte, error) { // Open returns a new ReadSeeker reading the PE section. func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) } -type FormatError struct { - off int64 - msg string - val interface{} -} - -func (e *FormatError) Error() string { - msg := e.msg - if e.val != nil { - msg += fmt.Sprintf(" '%v'", e.val) - } - msg += fmt.Sprintf(" in record at byte %#x", e.off) - return msg -} - // Open opens the named file using os.Open and prepares it for use as a PE binary. func Open(name string) (*File, error) { f, err := os.Open(name) @@ -320,6 +295,18 @@ func (f *File) DWARF() (*dwarf.Data, error) { return dwarf.New(abbrev, nil, nil, info, line, nil, ranges, str) } +// TODO(brainman): document ImportDirectory once we decide what to do with it. + +type ImportDirectory struct { + OriginalFirstThunk uint32 + TimeDateStamp uint32 + ForwarderChain uint32 + Name uint32 + FirstThunk uint32 + + dll string +} + // ImportedSymbols returns the names of all symbols // referred to by the binary f that are expected to be // satisfied by other libraries at dynamic load time. @@ -347,6 +334,12 @@ func (f *File) ImportedSymbols() ([]string, error) { } ida = append(ida, dt) } + // TODO(brainman): this needs to be rewritten + // ds.Data() return contets of .idata section. Why store in variable called "names"? + // Why we are retrieving it second time? We already have it in "d", and it is not modified anywhere. + // getString does not extracts a string from symbol string table (as getString doco says). + // Why ds.Data() called again and again in the loop? + // Needs test before rewrite. names, _ := ds.Data() var all []string for _, dt := range ida { @@ -395,3 +388,12 @@ func (f *File) ImportedLibraries() ([]string, error) { // cgo -dynimport don't use this for windows PE, so just return. return nil, nil } + +// FormatError is unused. +// The type is retained for compatibility. +type FormatError struct { +} + +func (e *FormatError) Error() string { + return "unknown error" +} -- 2.48.1