github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/debug/pe/section.go (about) 1 // Copyright 2016 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 package pe 6 7 import ( 8 "github.com/shogo82148/std/io" 9 ) 10 11 // SectionHeader32は、実際のPE COFFセクションヘッダーを表します。 12 type SectionHeader32 struct { 13 Name [8]uint8 14 VirtualSize uint32 15 VirtualAddress uint32 16 SizeOfRawData uint32 17 PointerToRawData uint32 18 PointerToRelocations uint32 19 PointerToLineNumbers uint32 20 NumberOfRelocations uint16 21 NumberOfLineNumbers uint16 22 Characteristics uint32 23 } 24 25 // Relocは、PE COFFの再配置を表します。 26 // 各セクションには独自の再配置リストが含まれています。 27 type Reloc struct { 28 VirtualAddress uint32 29 SymbolTableIndex uint32 30 Type uint16 31 } 32 33 // SectionHeaderは、NameフィールドがGoの文字列に置き換えられた [SectionHeader32] と似ています。 34 type SectionHeader struct { 35 Name string 36 VirtualSize uint32 37 VirtualAddress uint32 38 Size uint32 39 Offset uint32 40 PointerToRelocations uint32 41 PointerToLineNumbers uint32 42 NumberOfRelocations uint16 43 NumberOfLineNumbers uint16 44 Characteristics uint32 45 } 46 47 // Sectionは、PE COFFセクションへのアクセスを提供します。 48 type Section struct { 49 SectionHeader 50 Relocs []Reloc 51 52 // Embed ReaderAt for ReadAt method. 53 // Do not embed SectionReader directly 54 // to avoid having Read and Seek. 55 // If a client wants Read and Seek it must use 56 // Open() to avoid fighting over the seek offset 57 // with other clients. 58 io.ReaderAt 59 sr *io.SectionReader 60 } 61 62 // Dataは、PEセクションsの内容を読み取り、返します。 63 // 64 // s.Offsetが0の場合、セクションには内容がなく、 65 // Dataは常に非nilのエラーを返します。 66 func (s *Section) Data() ([]byte, error) 67 68 // Openは、PEセクションsを読み取る新しいReadSeekerを返します。 69 // 70 // s.Offsetが0の場合、セクションには内容がなく、 71 // 返されたリーダーへのすべての呼び出しは非nilのエラーを返します。 72 func (s *Section) Open() io.ReadSeeker 73 74 // セクション特性フラグ。 75 const ( 76 IMAGE_SCN_CNT_CODE = 0x00000020 77 IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040 78 IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080 79 IMAGE_SCN_LNK_COMDAT = 0x00001000 80 IMAGE_SCN_MEM_DISCARDABLE = 0x02000000 81 IMAGE_SCN_MEM_EXECUTE = 0x20000000 82 IMAGE_SCN_MEM_READ = 0x40000000 83 IMAGE_SCN_MEM_WRITE = 0x80000000 84 )