diff options
Diffstat (limited to 'libgo/go/debug/pe/file.go')
-rw-r--r-- | libgo/go/debug/pe/file.go | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/libgo/go/debug/pe/file.go b/libgo/go/debug/pe/file.go index 6a14e50..d86d916 100644 --- a/libgo/go/debug/pe/file.go +++ b/libgo/go/debug/pe/file.go @@ -35,7 +35,6 @@ type SectionHeader struct { Characteristics uint32 } - type Section struct { SectionHeader @@ -69,7 +68,6 @@ func (s *Section) Data() ([]byte, os.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 @@ -112,7 +110,7 @@ func (f *File) Close() os.Error { return err } -// NewFile creates a new File for acecssing a PE binary in an underlying reader. +// NewFile creates a new File for accessing a PE binary in an underlying reader. func NewFile(r io.ReaderAt) (*File, os.Error) { f := new(File) sr := io.NewSectionReader(r, 0, 1<<63-1) @@ -245,6 +243,7 @@ func (f *File) DWARF() (*dwarf.Data, os.Error) { // satisfied by other libraries at dynamic load time. // It does not return weak symbols. func (f *File) ImportedSymbols() ([]string, os.Error) { + pe64 := f.Machine == IMAGE_FILE_MACHINE_AMD64 ds := f.Section(".idata") if ds == nil { // not dynamic, so no libraries @@ -274,17 +273,31 @@ func (f *File) ImportedSymbols() ([]string, os.Error) { // seek to OriginalFirstThunk d = d[dt.OriginalFirstThunk-ds.VirtualAddress:] for len(d) > 0 { - va := binary.LittleEndian.Uint32(d[0:4]) - d = d[4:] - if va == 0 { - break - } - if va&0x80000000 > 0 { // is Ordinal - // TODO add dynimport ordinal support. - //ord := va&0x0000FFFF - } else { - fn, _ := getString(names, int(va-ds.VirtualAddress+2)) - all = append(all, fn+":"+dt.dll) + if pe64 { // 64bit + va := binary.LittleEndian.Uint64(d[0:8]) + d = d[8:] + if va == 0 { + break + } + if va&0x8000000000000000 > 0 { // is Ordinal + // TODO add dynimport ordinal support. + } else { + fn, _ := getString(names, int(uint32(va)-ds.VirtualAddress+2)) + all = append(all, fn+":"+dt.dll) + } + } else { // 32bit + va := binary.LittleEndian.Uint32(d[0:4]) + d = d[4:] + if va == 0 { + break + } + if va&0x80000000 > 0 { // is Ordinal + // TODO add dynimport ordinal support. + //ord := va&0x0000FFFF + } else { + fn, _ := getString(names, int(va-ds.VirtualAddress+2)) + all = append(all, fn+":"+dt.dll) + } } } } |