Esempio n. 1
0
func (l *SLEB128) Read(br *binary.BinaryReader) error {
	var (
		curr  LEB128
		shift LEB128
		v     uint8
		err   error
	)
	for {
		v, err = br.Uint8()
		if err != nil {
			return err
		}
		br := v&0x80 == 0
		v = v & 0x7f
		curr |= LEB128(v) << shift
		shift += 7
		if br {
			break
		}
	}
	const size = 64
	if (shift < size) && v&0x40 != 0 {
		curr |= -(1 << shift)
	}
	*l = SLEB128(curr)

	return nil
}
Esempio n. 2
0
func (ih *InfoHeader) Read(br *binary.BinaryReader) error {
	err := br.ReadInterface(&ih.Header)
	if err != nil {
		return err
	}
	if ih.is64 {
		ih.DebugAbbrevOffset, err = br.Int64()
	} else {
		var v uint32
		v, err = br.Uint32()
		ih.DebugAbbrevOffset = int64(v)
	}
	if err != nil {
		return err
	}
	ih.AddressSize, err = br.Uint8()
	return err
}
Esempio n. 3
0
func (l *LEB128) Read(br *binary.BinaryReader) error {
	curr := LEB128(0)
	shift := LEB128(0)
	for {
		v, err := br.Uint8()
		if err != nil {
			return err
		}
		br := v&0x80 == 0
		v = v & 0x7f
		curr |= LEB128(v) << shift
		if br {
			break
		}
		shift += 7
	}
	*l = curr
	return nil
}
Esempio n. 4
0
func (ie *InfoEntry) data(form DW_FORM, br binary.BinaryReader) interface{} {
	if form == DW_FORM_ref_addr && ie.header.Version < 3 {
		form = DW_FORM_addr
	}
	switch form {
	case DW_FORM_flag_present:
		return true
	case DW_FORM_exprloc, DW_FORM_block:
		var size LEB128
		br.ReadInterface(&size)
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block1:
		size, _ := br.Uint8()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block2:
		size, _ := br.Uint16()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block4:
		size, _ := br.Uint32()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_addr:
		if ie.header.AddressSize == 8 {
			v, _ := br.Uint64()
			return v
		} else {
			v, _ := br.Uint32()
			return uint64(v)
		}
	case DW_FORM_ref_addr, DW_FORM_strp, DW_FORM_sec_offset:
		if ie.header.is64 {
			v, _ := br.Uint64()
			return v
		} else {
			v, _ := br.Uint32()
			return uint64(v)
		}
	case DW_FORM_ref1, DW_FORM_flag, DW_FORM_data1:
		v, _ := br.Uint8()
		return uint64(v)
	case DW_FORM_ref2, DW_FORM_data2:
		v, _ := br.Uint16()
		return uint64(v)
	case DW_FORM_ref4, DW_FORM_data4:
		v, _ := br.Uint32()
		return uint64(v)
	case DW_FORM_ref8, DW_FORM_data8:
		v, _ := br.Uint64()
		return v
	case DW_FORM_sdata, DW_FORM_udata:
		var r LEB128
		br.ReadInterface(&r)
		return uint64(r)
	case DW_FORM_string:
		buf := make([]byte, 4096)

		for i := range buf {
			if v, err := br.Uint8(); err != nil {
				return err
			} else if v == 0 {
				buf = buf[:i]
				break
			} else {
				buf[i] = byte(v)
			}
		}
		return string(buf)
	}
	panic(fmt.Errorf("Unimplemented format: %s", form))
}
Esempio n. 5
0
func parseModelEntryVSET(entry *ModelEntry) error {
	reader := binary.BinaryReader{Reader: entry.Data, Endianess: binary.LittleEndian}

	var err error

	unk, err := reader.Uint16()
	count, err := reader.Uint16()

	fmt.Printf("Count: %04x\n", count)
	fmt.Printf("Unk: %04x\n", unk)

	for i := uint16(0); i < count && err == nil; i++ {
		var identifier uint16
		identifier, err = reader.Uint16()
		var data []uint8

		if err != nil {
			break
		}

		if identifier&0x8000 != 0 { // Size is f****d up
			var sz, unk uint8
			unk, err = reader.Uint8()

			var size uint16
			if unk == 0x10 {
				size, err = reader.Uint16()
			} else if unk == 0x08 {
				sz, err = reader.Uint8()
				size = uint16(sz)
			} else {
				return errors.New("Unknown size flag")
			}

			fmt.Printf("Oh %02x, %04x\n", unk, size)
			x := 2
			data = make([]uint8, x*int(size+1))
		} else if identifier&0x0900 != 0 { // and 0x0900
			data = make([]uint8, 4)
		} else if identifier&0x0600 == 0x0600 { // and 0x0600
			data = make([]uint8, 2)
		} else if identifier&0xff00 != 0 {
			fmt.Printf("what the f**k is %04x\n", identifier&0xff00)
			//break
		}

		_, err = util.ReadN(entry.Data, data)

		fmt.Printf("\t\t%04x (%08x): %x\n", identifier, len(data), data)
	}

	if _, err = entry.Data.Read(make([]uint8, 1)); err != io.EOF {
		return errors.New("Expected EOF")
	}

	if err == io.EOF {
		return nil
	}

	return err
}
Esempio n. 6
0
func (lh *lineHeader) Read(br *binary.BinaryReader) error {
	start, _ := br.Seek(0, 1)
	err := br.ReadInterface(&lh.Header)
	if err != nil {
		return err
	}
	if lh.is64 {
		lh.header_length, err = br.Int64()
	} else {
		var v uint32
		v, err = br.Uint32()
		lh.header_length = int64(v)
	}
	if err != nil {
		return err
	}
	if lh.minimum_instruction_length, err = br.Uint8(); err != nil {
		return err
	}
	lh.maximum_operations_per_instruction = 1
	// TODO:
	// if lh.maximum_operations_per_instruction, err = br.Uint8(); err != nil {
	// 	return err
	// }
	if err = br.ReadInterface(&lh.default_is_stmt); err != nil {
		return err
	} else if lh.line_base, err = br.Int8(); err != nil {
		return err
	} else if lh.line_range, err = br.Uint8(); err != nil {
		return err
	} else if lh.opcode_base, err = br.Uint8(); err != nil {
		return err
	}
	lh.standard_opcode_lengths = make([]uint8, lh.opcode_base-1)
	if err := br.ReadInterface(&lh.standard_opcode_lengths); err != nil {
		return err
	}
	for {
		var s string
		if err := br.ReadInterface(&s); err != nil {
			return err
		} else if s == "" {
			break
		} else {
			lh.include_directories = append(lh.include_directories, s)
		}
	}

	for {
		var f fileEntry
		pos, _ := br.Seek(0, 1)
		if v, err := br.Uint8(); err != nil {
			return err
		} else if v == '\u0000' {
			break
		} else {
			br.Seek(pos, 0)
		}
		if err := br.ReadInterface(&f); err != nil {
			return err
		} else {
			lh.file_names = append(lh.file_names, f)
		}
	}
	var s state
	s.header = lh
	s.reset()
	pos, _ := br.Seek(0, 1)
	for (pos - 4 - start) < int64(lh.Length) {
		var op DW_LNS
		if err := br.ReadInterface(&op); err != nil {
			return err
		}
		if op == 0 {
			var length LEB128
			if err := br.ReadInterface(&length); err != nil {
				return err
			}

			var op2 DW_LNE
			if err := br.ReadInterface(&op2); err != nil {
				return err
			}
			s.executeLNE(op2, length-1, br)
		} else {
			s.execute(op, br)
		}
		pos, _ = br.Seek(0, 1)
	}

	return nil
}