示例#1
0
文件: elf_file.go 项目: jvoung/go-ld
func readPhdr32(buf []byte, byte_order binary.ByteOrder) ProgramHeader {
	byte_reader := bytes.NewReader(buf)
	phdr := ProgramHeader{}
	// binary.Read doesn't like elf.ProgType == int, so read that
	// to a local instead.
	var typ uint32
	err1 := binary.Read(byte_reader, byte_order, &typ)
	if err1 != nil {
		panic("Failed to read phdr type" + err1.Error())
	}
	phdr.P_type = elf.ProgType(typ)
	var offset, vaddr, paddr, filesz, memsz, flags, align uint32
	err1 = binary.Read(byte_reader, byte_order, &offset)
	err2 := binary.Read(byte_reader, byte_order, &vaddr)
	err3 := binary.Read(byte_reader, byte_order, &paddr)
	err4 := binary.Read(byte_reader, byte_order, &filesz)
	if err1 != nil || err2 != nil || err3 != nil || err4 != nil {
		panic("Failed to read phdr offset, vaddr, paddr, or filesz")
	}
	err1 = binary.Read(byte_reader, byte_order, &memsz)
	err2 = binary.Read(byte_reader, byte_order, &flags)
	err3 = binary.Read(byte_reader, byte_order, &align)
	if err1 != nil || err2 != nil || err3 != nil {
		panic("Failed to read phdr memsz, flags, or align")
	}
	phdr.P_flags = elf.ProgFlag(flags)
	phdr.P_offset = uint64(offset)
	phdr.P_vaddr = uint64(vaddr)
	phdr.P_paddr = uint64(paddr)
	phdr.P_vaddr = uint64(vaddr)
	phdr.P_filesz = uint64(filesz)
	phdr.P_memsz = uint64(memsz)
	phdr.P_align = uint64(align)
	return phdr
}
示例#2
0
文件: elf_file.go 项目: jvoung/go-ld
func readPhdr64(buf []byte, byte_order binary.ByteOrder) ProgramHeader {
	byte_reader := bytes.NewReader(buf)
	phdr := ProgramHeader{}
	var typ uint32
	err1 := binary.Read(byte_reader, byte_order, &typ)
	err2 := binary.Read(byte_reader, byte_order, &phdr.P_flags)
	err3 := binary.Read(byte_reader, byte_order, &phdr.P_offset)
	err4 := binary.Read(byte_reader, byte_order, &phdr.P_vaddr)
	if err1 != nil || err2 != nil || err3 != nil || err4 != nil {
		panic("Failed to read phdr type, flags, offset, or vaddr")
	}
	phdr.P_type = elf.ProgType(typ)
	err1 = binary.Read(byte_reader, byte_order, &phdr.P_paddr)
	err2 = binary.Read(byte_reader, byte_order, &phdr.P_filesz)
	err3 = binary.Read(byte_reader, byte_order, &phdr.P_memsz)
	err4 = binary.Read(byte_reader, byte_order, &phdr.P_align)
	if err1 != nil || err2 != nil || err3 != nil {
		panic("Failed to read paddr, filesz, memsz, or align")
	}
	return phdr
}