Commit 5183ad69 authored by Alex Brainman's avatar Alex Brainman

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/22182Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent bfe0cbdc
......@@ -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"
}
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