// Copyright 2016 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package peimport ()// cstring converts ASCII byte sequence b to string.// It stops once it finds 0 or reaches end of b.func cstring( []byte) string { := bytes.IndexByte(, 0)if == -1 { = len() }returnstring([:])}// StringTable is a COFF string table.typeStringTable []bytefunc readStringTable( *FileHeader, io.ReadSeeker) (StringTable, error) {// COFF string table is located right after COFF symbol table.if .PointerToSymbolTable <= 0 {returnnil, nil } := .PointerToSymbolTable + COFFSymbolSize*.NumberOfSymbols , := .Seek(int64(), io.SeekStart)if != nil {returnnil, fmt.Errorf("fail to seek to string table: %v", ) }varuint32 = binary.Read(, binary.LittleEndian, &)if != nil {returnnil, fmt.Errorf("fail to read string table length: %v", ) }// string table length includes itselfif <= 4 {returnnil, nil } -= 4 , := saferio.ReadData(, uint64())if != nil {returnnil, fmt.Errorf("fail to read string table: %v", ) }returnStringTable(), nil}// TODO(brainman): decide if start parameter should be int instead of uint32// String extracts string from COFF string table st at offset start.func ( StringTable) ( uint32) (string, error) {// start includes 4 bytes of string table lengthif < 4 {return"", fmt.Errorf("offset %d is before the start of string table", ) } -= 4ifint() > len() {return"", fmt.Errorf("offset %d is beyond the end of string table", ) }returncstring([:]), nil}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.