Returns the byte content of a custom section with name, or nil.
(b []byte, name string)
| 13 | |
| 14 | // Returns the byte content of a custom section with name, or nil. |
| 15 | func wasmCustomSection(b []byte, name string) []byte { |
| 16 | const customSectionId = 0 |
| 17 | if len(b) < 8 { |
| 18 | return nil |
| 19 | } |
| 20 | b = b[8:] // skip magic+version |
| 21 | for len(b) > 2 { |
| 22 | id := b[0] |
| 23 | b = b[1:] |
| 24 | length, n := binary.Uvarint(b) |
| 25 | b = b[n:] |
| 26 | |
| 27 | if id == customSectionId { |
| 28 | nameLen, n := binary.Uvarint(b) |
| 29 | b = b[n:] |
| 30 | m := string(b[:nameLen]) |
| 31 | if m == name { |
| 32 | return b[nameLen : length-uint64(n)] |
| 33 | } |
| 34 | b = b[length-uint64(n):] |
| 35 | } else { |
| 36 | b = b[length:] |
| 37 | } |
| 38 | } |
| 39 | return nil |
| 40 | } |
| 41 | |
| 42 | // The functions in this file inspect the contents of a well-formed wasm-binary. |
| 43 | // They are very weak parsers: they should be called on a valid module, or may |
no outgoing calls
no test coverage detected