import ( "cmd/internal/obj" ) func main() { rawData := []byte{0x90, 0xC3} // NOP, RET code prog := obj.ProgFrom(rawData, 0) // `prog` now contains the decoded instruction }
import ( "cmd/internal/obj" "debug/elf" ) func main() { f, err := elf.Open("test.elf") // handle errors... defer f.Close() section := f.Section(".text") data, err := section.Data() // handle errors... for offset := 0; offset < len(data); { prog := obj.ProgFrom(data, offset) // `prog` now contains the decoded instruction at offset offset += prog.Size } }The above example reads an ELF file, opens the ".text" section, and reads the data into a byte slice. It then iterates over the data, creating a "Prog" structure for each instruction and advancing the offset by the size of the instruction. This allows for easy decoding of object code in binary files.