github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/debug/pe/file.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  パッケージpeは、PE(Microsoft Windows Portable Executable)ファイルへのアクセスを実装します。
     7  
     8  # セキュリティ
     9  
    10  このパッケージは、敵対的な入力に対して強化されるように設計されていませんし、
    11  https://go.dev/security/policy の範囲外です。特に、オブジェクトファイルを解析する際には基本的な
    12  検証のみが行われます。そのため、信頼できない入力を解析する際には注意が必要です。なぜなら、
    13  形式が不正なファイルを解析すると、大量のリソースを消費したり、パニックを引き起こす可能性があるからです。
    14  */
    15  package pe
    16  
    17  import (
    18  	"github.com/shogo82148/std/debug/dwarf"
    19  	"github.com/shogo82148/std/io"
    20  )
    21  
    22  // Fileは、開かれたPEファイルを表します。
    23  type File struct {
    24  	FileHeader
    25  	OptionalHeader any
    26  	Sections       []*Section
    27  	Symbols        []*Symbol
    28  	COFFSymbols    []COFFSymbol
    29  	StringTable    StringTable
    30  
    31  	closer io.Closer
    32  }
    33  
    34  // Openは、[os.Open] を使用して指定されたファイルを開き、それをPEバイナリとして使用するための準備をします。
    35  func Open(name string) (*File, error)
    36  
    37  // Closeは、[File] を閉じます。
    38  // [File] が [Open] ではなく [NewFile] を直接使用して作成された場合、
    39  // Closeは何も影響を与えません。
    40  func (f *File) Close() error
    41  
    42  // NewFileは、基礎となるリーダーでPEバイナリにアクセスするための新しいFileを作成します。
    43  func NewFile(r io.ReaderAt) (*File, error)
    44  
    45  // Sectionは、指定された名前の最初のセクションを返します。そのような
    46  // セクションが存在しない場合はnilを返します。
    47  func (f *File) Section(name string) *Section
    48  
    49  func (f *File) DWARF() (*dwarf.Data, error)
    50  
    51  type ImportDirectory struct {
    52  	OriginalFirstThunk uint32
    53  	TimeDateStamp      uint32
    54  	ForwarderChain     uint32
    55  	Name               uint32
    56  	FirstThunk         uint32
    57  
    58  	dll string
    59  }
    60  
    61  // ImportedSymbolsは、動的ロード時に他のライブラリによって満たされることが期待されている、
    62  // バイナリfが参照しているすべてのシンボルの名前を返します。
    63  // それは弱いシンボルを返しません。
    64  func (f *File) ImportedSymbols() ([]string, error)
    65  
    66  // ImportedLibrariesは、動的リンク時にバイナリとリンクされることが期待されている、
    67  // バイナリfが参照しているすべてのライブラリの名前を返します。
    68  func (f *File) ImportedLibraries() ([]string, error)
    69  
    70  // FormatErrorは使用されていません。
    71  // この型は互換性のために保持されています。
    72  type FormatError struct {
    73  }
    74  
    75  func (e *FormatError) Error() string