debug/pe

pe包

  • import "debug/pe"

  • 概述

  • 索引

概述

Package pe实现对 PE(Microsoft Windows Portable Executable)文件的访问。

索引

  • 常量

  • type COFFSymbol

  • func (sym *COFFSymbol) FullName(st StringTable) (string, error)

  • type DataDirectory

  • type File

  • func NewFile(r io.ReaderAt) (*File, error)

  • func Open(name string) (*File, error)

  • func (f *File) Close() error

  • func (f *File) DWARF() (*dwarf.Data, error)

  • func (f *File) ImportedLibraries() ([]string, error)

  • func (f *File) ImportedSymbols() ([]string, error)

  • func (f *File) Section(name string) *Section

  • type FileHeader

  • type FormatError

  • func (e *FormatError) Error() string

  • type ImportDirectory

  • type OptionalHeader32

  • type OptionalHeader64

  • type Reloc

  • type Section

  • func (s *Section) Data() ([]byte, error)

  • func (s *Section) Open() io.ReadSeeker

  • type SectionHeader

  • type SectionHeader32

  • type StringTable

  • func (st StringTable) String(start uint32) (string, error)

  • type Symbol

包文件

file.go pe.go section.go string.go symbol.go

常量

const ( IMAGE_FILE_MACHINE_UNKNOWN = 0x0 IMAGE_FILE_MACHINE_AM33 = 0x1d3 IMAGE_FILE_MACHINE_AMD64 = 0x8664 IMAGE_FILE_MACHINE_ARM = 0x1c0 IMAGE_FILE_MACHINE_EBC = 0xebc IMAGE_FILE_MACHINE_I386 = 0x14c IMAGE_FILE_MACHINE_IA64 = 0x200 IMAGE_FILE_MACHINE_M32R = 0x9041 IMAGE_FILE_MACHINE_MIPS16 = 0x266 IMAGE_FILE_MACHINE_MIPSFPU = 0x366 IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466 IMAGE_FILE_MACHINE_POWERPC = 0x1f0 IMAGE_FILE_MACHINE_POWERPCFP = 0x1f1 IMAGE_FILE_MACHINE_R4000 = 0x166 IMAGE_FILE_MACHINE_SH3 = 0x1a2 IMAGE_FILE_MACHINE_SH3DSP = 0x1a3 IMAGE_FILE_MACHINE_SH4 = 0x1a6 IMAGE_FILE_MACHINE_SH5 = 0x1a8 IMAGE_FILE_MACHINE_THUMB = 0x1c2 IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 )

const COFFSymbolSize = 18

type COFFSymbol(查看源代码)

COFFSymbol 表示单个 COFF 符号表记录。

type COFFSymbol struct { Name [8]uint8 Value uint32 SectionNumber int16 Type uint16 StorageClass uint8 NumberOfAuxSymbols uint8 }

func (*COFFSymbol) FullName(查看源代码)

func (sym *COFFSymbol) FullName(st StringTable) (string, error)

FullName 找到符号 sym 的真实名称。通常名称存储在 sym.Name 中,但如果长度超过8个字符,它将存储在 COFF 字符串表st中。

type DataDirectory(查看源代码)

type DataDirectory struct { VirtualAddress uint32 Size uint32 }

type File(查看源代码)

文件表示一个开放的 PE 文件。

type File struct { FileHeader OptionalHeader interface{} // *OptionalHeader32或 *OptionalHeader64 类型 Sections []*Section Symbols []*Symbol // 删除了辅助符号记录的COFF符号 COFFSymbols []COFFSymbol // 所有COFF符号(包括辅助符号记录) StringTable StringTable // 包含已过滤或未导出的字段 }

func NewFile(查看源代码)

func NewFile(r io.ReaderAt) (*File, error)

NewFile 创建一个新的文件,用于访问底层阅读器中的 PE 二进制文件。

func Open(查看源代码)

func Open(name string) (*File, error)

打开使用 os.Open 打开命名文件,并准备将其用作 PE 二进制文件。

func (*File) Close(查看源代码)

func (f *File) Close() error

关闭文件。如果文件是直接使用 NewFile 而不是 Open 来创建的,则 Close 不起作用。

func (*File) DWARF(查看源代码)

func (f *File) DWARF() (*dwarf.Data, error)

func (*File) ImportedLibraries(查看源代码)

func (f *File) ImportedLibraries() ([]string, error)

ImportedLibraries 返回二进制文件 f 引用的所有库的名称,这些库在动态链接时期预计将与二进制文件链接。

func (*File) ImportedSymbols(查看源代码)

func (f *File) ImportedSymbols() ([]string, error)

ImportedSymbols 返回二进制文件f引用的所有符号的名称,动态加载时期望其他库会满足这些名称。它不会返回弱符号。

func (*File) Section(查看源代码)

func (f *File) Section(name string) *Section

Section 返回给定名称的第一部分,如果不存在这样的部分,则返回 nil。

type FileHeader(查看源代码)

type FileHeader struct { Machine uint16 NumberOfSections uint16 TimeDateStamp uint32 PointerToSymbolTable uint32 NumberOfSymbols uint32 SizeOfOptionalHeader uint16 Characteristics uint16 }

type FormatError(查看源代码)

FormatError 未使用。该类型被保留以便兼容。

type FormatError struct { }

func (*FormatError) Error(查看源代码)

func (e *FormatError) Error() string

type ImportDirectory(查看源代码)

type ImportDirectory struct { OriginalFirstThunk uint32 TimeDateStamp uint32 ForwarderChain uint32 Name uint32 FirstThunk uint32 // 包含已过滤或未导出的字段 }

type OptionalHeader32(查看源代码)

type OptionalHeader32 struct { Magic uint16 MajorLinkerVersion uint8 MinorLinkerVersion uint8 SizeOfCode uint32 SizeOfInitializedData uint32 SizeOfUninitializedData uint32 AddressOfEntryPoint uint32 BaseOfCode uint32 BaseOfData uint32 ImageBase uint32 SectionAlignment uint32 FileAlignment uint32 MajorOperatingSystemVersion uint16 MinorOperatingSystemVersion uint16 MajorImageVersion uint16 MinorImageVersion uint16 MajorSubsystemVersion uint16 MinorSubsystemVersion uint16 Win32VersionValue uint32 SizeOfImage uint32 SizeOfHeaders uint32 CheckSum uint32 Subsystem uint16 DllCharacteristics uint16 SizeOfStackReserve uint32 SizeOfStackCommit uint32 SizeOfHeapReserve uint32 SizeOfHeapCommit uint32 LoaderFlags uint32 NumberOfRvaAndSizes uint32 DataDirectory [16]DataDirectory }

type OptionalHeader64(查看源代码)

type OptionalHeader64 struct { Magic uint16 MajorLinkerVersion uint8 MinorLinkerVersion uint8 SizeOfCode uint32 SizeOfInitializedData uint32 SizeOfUninitializedData uint32 AddressOfEntryPoint uint32 BaseOfCode uint32 ImageBase uint64 SectionAlignment uint32 FileAlignment uint32 MajorOperatingSystemVersion uint16 MinorOperatingSystemVersion uint16 MajorImageVersion uint16 MinorImageVersion uint16 MajorSubsystemVersion uint16 MinorSubsystemVersion uint16 Win32VersionValue uint32 SizeOfImage uint32 SizeOfHeaders uint32 CheckSum uint32 Subsystem uint16 DllCharacteristics uint16 SizeOfStackReserve uint64 SizeOfStackCommit uint64 SizeOfHeapReserve uint64 SizeOfHeapCommit uint64 LoaderFlags uint32 NumberOfRvaAndSizes uint32 DataDirectory [16]DataDirectory }

type Reloc(查看源代码)

Reloc 代表 PE COFF 重新安置。每个部分都包含自己的重定位列表。

type Reloc struct { VirtualAddress uint32 SymbolTableIndex uint32 Type uint16 }

type Section(查看源代码)

部分提供对 PE COFF 部分的访问。

type Section struct { SectionHeader Relocs []Reloc // 为ReadAt方法嵌入ReaderAt。 // 不要直接嵌入SectionReader // 避免阅读Read和寻求Seek。 // 如果客户想要阅读和寻求它必须使用 // Open()以避免争夺搜索偏移量 // 与其他客户。 io.ReaderAt // 包含已过滤或未导出的字段 }

func (*Section) Data(查看源代码)

func (s *Section) Data() ([]byte, error)

数据读取并返回 PE 部分的内容。

func (*Section) Open(查看源代码)

func (s *Section) Open() io.ReadSeeker

Open 返回一个新的 ReadSeeker 读取 PE 部分。

type SectionHeader(查看源代码)

SectionHeader 类似于 SectionHeader32,其中 Name 字段被 Go 字符串替换。

type SectionHeader struct { Name string VirtualSize uint32 VirtualAddress uint32 Size uint32 Offset uint32 PointerToRelocations uint32 PointerToLineNumbers uint32 NumberOfRelocations uint16 NumberOfLineNumbers uint16 Characteristics uint32 }

type SectionHeader32(查看源代码)

SectionHeader32 表示真实的 PE COFF 部分标题。

type SectionHeader32 struct { Name [8]uint8 VirtualSize uint32 VirtualAddress uint32 SizeOfRawData uint32 PointerToRawData uint32 PointerToRelocations uint32 PointerToLineNumbers uint32 NumberOfRelocations uint16 NumberOfLineNumbers uint16 Characteristics uint32 }

type StringTable(查看源代码)

StringTable 是一个 COFF 字符串表。

type StringTable []byte

func (StringTable) String(查看源代码)

func (st StringTable) String(start uint32) (string, error)

字符串从偏移量开始处的 COFF 字符串表st中提取字符串。

type Symbol(查看源代码)

符号与 COFFSymbol 类似,名称字段由 Go 字符串替换。Symbol 也没有 NumberOfAuxSymbols。

type Symbol struct { Name string Value uint32 SectionNumber int16 Type uint16 StorageClass uint8 }