The Go toolchain stores a build ID in the binary that we can use, as a fallback if binary file specific build IDs can't be obtained. This function reads that build ID from the binary.
(f *os.File, prefixSize int)
| 109 | // fallback if binary file specific build IDs can't be obtained. |
| 110 | // This function reads that build ID from the binary. |
| 111 | func readRawGoBuildID(f *os.File, prefixSize int) ([]byte, error) { |
| 112 | fileStart := make([]byte, prefixSize) |
| 113 | _, err := io.ReadFull(f, fileStart) |
| 114 | if err != nil { |
| 115 | return nil, fmt.Errorf("could not read build id from %s: %v", f.Name(), err) |
| 116 | } |
| 117 | index := bytes.Index(fileStart, []byte("\xff Go build ID: \"")) |
| 118 | if index < 0 || index > len(fileStart)-103 { |
| 119 | return nil, fmt.Errorf("could not find build id in %s", f.Name()) |
| 120 | } |
| 121 | buf := fileStart[index : index+103] |
| 122 | if bytes.HasPrefix(buf, []byte("\xff Go build ID: \"")) && bytes.HasSuffix(buf, []byte("\"\n \xff")) { |
| 123 | return buf[len("\xff Go build ID: \"") : len(buf)-1], nil |
| 124 | } |
| 125 | |
| 126 | return nil, nil |
| 127 | } |
no test coverage detected