Beispiel #1
1
func (this *HSPerfData) readEntryValueAsString(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
	reader.Seek(StartOfs+int64(entry.DataOffset), os.SEEK_SET)

	DataLen := entry.EntryLength - entry.DataOffset
	n, err := reader.Read(this.globalbuf[:DataLen])
	if err != nil {
		return err
	} else if n != int(DataLen) {
		return errors.New("Could not read entry value.")
	}

	n = bytes.Index(this.globalbuf[:DataLen], []byte{0})
	entry.StringValue = string(this.globalbuf[:n])

	return nil
}
Beispiel #2
1
func ReadEntryValueAsString(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
	reader.Seek(StartOfs+int64(entry.DataOffset), os.SEEK_SET)

	DataLen := entry.EntryLength - entry.DataOffset
	var buf []byte = make([]byte, DataLen)
	n, err := reader.Read(buf)
	if err != nil {
		return err
	} else if n != int(DataLen) {
		return errors.New("Could not read entry value.")
	}

	n = bytes.Index(buf, []byte{0})
	entry.StringValue = string(buf[:n])

	return nil
}
Beispiel #3
1
func ReadEntryName(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
	reader.Seek(StartOfs+int64(entry.NameOffset), os.SEEK_SET)

	NameLen := entry.DataOffset - entry.NameOffset
	var buf []byte = make([]byte, NameLen)
	n, err := reader.Read(buf)
	if err != nil {
		return err
	} else if n != int(NameLen) {
		return errors.New("Could not read entry name.")
	}

	n = bytes.Index(buf, []byte{0})
	entry.EntryName = string(buf[:n])

	return nil
}
Beispiel #4
1
func (this *HSPerfData) readEntryName(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
	reader.Seek(StartOfs+int64(entry.NameOffset), os.SEEK_SET)

	NameLen := entry.DataOffset - entry.NameOffset
	n, err := reader.Read(this.globalbuf[:NameLen])
	if err != nil {
		return err
	} else if n != int(NameLen) {
		return errors.New("Could not read entry name.")
	}

	n = bytes.Index(this.globalbuf[:NameLen], []byte{0})
	for i := 0; i < n; i++ { // Convert '.' to '/'
		if this.globalbuf[i] == '.' {
			this.globalbuf[i] = '/'
		}
	}
	entry.EntryName = string(this.globalbuf[:n])

	return nil
}
Beispiel #5
0
func (this *HSPerfData) readEntryValueAsLong(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
	reader.Seek(StartOfs+int64(entry.DataOffset), os.SEEK_SET)
	reader.Read(this.globalbuf[:8])
	entry.LongValue = int64(this.byteOrder.Uint64(this.globalbuf[:8]))

	return nil
}
Beispiel #6
0
func readTracks(reader *bytes.Reader, encodedDataSize int) ([]Track, error) {
	var tracks []Track

	position := encodedDataSize - reader.Len()

	for position < encodedDataSize {
		var id int32
		binary.Read(reader, binary.LittleEndian, &id)

		channelNameSize, _ := reader.ReadByte()
		channelBytes := make([]byte, channelNameSize)
		_, err := reader.Read(channelBytes)
		if err != nil {
			return []Track{}, errors.New("Could not read Track name with id " + string(id))
		}

		pattern := make([]uint32, 4)
		patternReadErr := binary.Read(reader, binary.LittleEndian, &pattern)
		if patternReadErr != nil {
			return []Track{}, errors.New("Could not read Track step with id " + string(id))
		}

		tracks = append(tracks, Track{
			id,
			string(channelBytes),
			pattern})

		position += int(21) + int(channelNameSize)
	}

	return tracks, nil
}
Beispiel #7
0
func (ra *radiusAttribute) decode(b *bytes.Reader) error {
	raType, err := b.ReadByte()
	if err != nil {
		return err
	}
	ra.raType = radiusAttributeType(raType)
	length, err := b.ReadByte()
	if err != nil {
		return err
	}
	if length < 2 {
		return fmt.Errorf("invalid attribute length: %d", length)
	}
	ra.length = length
	if length == 2 {
		return nil
	}
	ra.value = make([]byte, length-2)
	n, err := b.Read(ra.value)
	if err != nil {
		return err
	}
	if n != int(length)-2 {
		return fmt.Errorf("attribute value short read: %d", n)
	}
	return nil
}
Beispiel #8
0
func (section_header *Section_Header) Verify(datar *bytes.Reader) bool {
	var buf []byte

	datar.Read(buf)
	fmt.Println(section_header.Checksum, len(buf))
	return section_header.Checksum == adler32.Checksum(buf[:72])

}
Beispiel #9
0
Datei: bytes.go Projekt: h8liu/d8
func UnpackBytes(in *bytes.Reader, n uint16) (Bytes, error) {
	ret := make([]byte, n)
	if _, e := in.Read([]byte(ret)); e != nil {
		return nil, e
	}

	return Bytes(ret), nil
}
Beispiel #10
0
func readBytes(f *bytes.Reader, len int) ([]byte, error) {
	b := make([]byte, len)
	_, err := f.Read(b)
	if err != nil {
		return nil, err
	}
	return b, nil
}
Beispiel #11
0
Datei: text.go Projekt: h8liu/d8
func UnpackString(in *bytes.Reader, n uint16) (Text, error) {
	buf := make([]byte, n)
	_, e := in.Read(buf)
	if e != nil {
		return "", e
	}
	return Text(string(buf)), nil
}
Beispiel #12
0
func ReadMac(reader *bytes.Reader) uint64 {
	mac_byte := make([]byte, 6)
	reader.Read(mac_byte)
	mac := []byte{0, 0}
	mac = append(mac, mac_byte...)

	return binary.BigEndian.Uint64(mac)
}
Beispiel #13
0
func (self *Question) unpackFlags(in *bytes.Reader) error {
	buf := make([]byte, 4)
	if _, e := in.Read(buf); e != nil {
		return e
	}

	self.Type = enc.Uint16(buf[0:2])
	self.Class = enc.Uint16(buf[2:4])

	return nil
}
Beispiel #14
0
func ReadString(r *bytes.Reader) string {
	length, _ := binary.ReadUvarint(r)
	if length < 1 {
		return ""
	} else {
		buf := make([]byte, length)
		r.Read(buf)

		return string(buf)
	}
}
Beispiel #15
0
Datei: rr.go Projekt: h8liu/d8
func (self *RR) unpackFlags(in *bytes.Reader) error {
	var buf [8]byte
	if _, e := in.Read(buf[:]); e != nil {
		return e
	}
	self.Type = enc.Uint16(buf[0:2])
	self.Class = enc.Uint16(buf[2:4])
	self.TTL = enc.Uint32(buf[4:8])

	return nil
}
Beispiel #16
0
//Read read
func (t *TTFParser) Read(fd *bytes.Reader, length int) ([]byte, error) {
	buff := make([]byte, length)
	readlength, err := fd.Read(buff)
	if err != nil {
		return nil, err
	}
	if readlength != length {
		return nil, errors.New("file out of length")
	}
	//fmt.Printf("%d,%s\n", readlength, string(buff))
	return buff, nil
}
Beispiel #17
0
Datei: ipv6.go Projekt: h8liu/d8
func UnpackIPv6(in *bytes.Reader, n uint16) (IPv6, error) {
	if n != 16 {
		return nil, fmt.Errorf("IPv6 with %d bytes", n)
	}
	buf := make([]byte, 16)
	_, e := in.Read(buf)
	if e != nil {
		return nil, e
	}

	return IPv6(buf), nil
}
Beispiel #18
0
Datei: ipv4.go Projekt: h8liu/d8
func UnpackIPv4(in *bytes.Reader, n uint16) (IPv4, error) {
	if n != 4 {
		return nil, fmt.Errorf("IPv4 with %d bytes", n)
	}

	buf := make([]byte, 4)
	_, e := in.Read(buf)
	if e != nil {
		return nil, e
	}

	return IPv4(net.IPv4(buf[0], buf[1], buf[2], buf[3])), nil
}
Beispiel #19
0
func (table_entry *EWF_Table_Section_Entry) Parse(buf *bytes.Reader) {
	var b *bytes.Reader

	val := make([]byte, int64(buf.Len()))

	buf.Read(val)
	//parse struct attributes
	table_entry.IsCompressed = val[3] << 1 & 1
	val[3] &= 0x7F //exlude MSB

	b = bytes.NewReader(val)

	parseutil.Parse(b, &table_entry.ChunkDataOffset)
}
Beispiel #20
0
func readHardwareVersion(reader *bytes.Reader) (string, error) {
	versionBytes := make([]byte, 32)
	_, versionReadError := reader.Read(versionBytes)
	if versionReadError != nil {
		return "", versionReadError
	}

	versionString := string(bytes.Trim(versionBytes, "\x00"))
	if versionString == "" {
		return "", errors.New("The file version is incorrect.")
	}

	return versionString, nil
}
Beispiel #21
0
Datei: rdata.go Projekt: h8liu/d8
func Unpack(t, c uint16, in *bytes.Reader, p []byte) (Rdata, error) {
	buf := make([]byte, 2)
	if _, e := in.Read(buf); e != nil {
		return nil, e
	}
	n := enc.Uint16(buf)

	buf = make([]byte, n)
	if _, e := in.Read(buf); e != nil {
		return nil, e
	}

	in = bytes.NewReader(buf)
	ret, e := unpack(t, c, bytes.NewReader(buf), p)
	return ret, e
}
Beispiel #22
0
// Grab a variable-length sequence of bytes from the buffer.
func varLenBytes(buf *bytes.Reader) ([]byte, error) {
	// Read the length of the sequence, as a varint.
	seqLen, err := vint(buf)
	if err != nil {
		return nil, err
	}
	// Read the sequence itself.
	seq := make([]byte, seqLen)
	n, err := buf.Read(seq)
	if err != nil {
		return nil, err
	}
	if n != seqLen {
		return nil, errors.New("Buffer too short to read sequence of requested length.")
	}
	return seq, nil
}
Beispiel #23
0
func (self *Packet) unpackHeader(in *bytes.Reader) error {
	buf := make([]byte, 12)
	if _, e := in.Read(buf); e != nil {
		return e
	}

	self.Id = enc.Uint16(buf[0:2])
	self.Flag = enc.Uint16(buf[2:4])
	if enc.Uint16(buf[4:6]) != 1 {
		return errors.New("not one question")
	}

	self.Answer = make([]*RR, enc.Uint16(buf[6:8]))
	self.Authority = make([]*RR, enc.Uint16(buf[8:10]))
	self.Addition = make([]*RR, enc.Uint16(buf[10:12]))

	return nil
}
Beispiel #24
0
Datei: mx.go Projekt: h8liu/d8
func UnpackMailEx(in *bytes.Reader, n uint16, p []byte) (*MailEx, error) {
	if n <= 2 {
		return nil, fmt.Errorf("mx with %d bytes", n)
	}

	buf := make([]byte, 2)
	_, e := in.Read(buf)
	if e != nil {
		return nil, e
	}

	ret := new(MailEx)
	ret.Priority = enc.Uint16(buf)
	labels, e := unpackLabels(in, n-2, p)
	if e != nil {
		return nil, e
	}
	ret.Domain = labels

	return ret, nil
}
// Decodes an encoded ChangeLog.
func DecodeChangeLog(r *bytes.Reader) *ChangeLog {
	type docAndRev struct {
		docID, revID string
	}

	ch := ChangeLog{
		Since:   readSequence(r),
		Entries: make([]*LogEntry, 0, 500),
	}
	parents := map[docAndRev]*LogEntry{}
	var buf [1]byte
	for {
		n, _ := r.Read(buf[0:1])
		if n == 0 {
			break // eof
		}
		if buf[0] > 7 {
			panic("bad flags")
		}
		entry := &LogEntry{
			Flags:    buf[0],
			Sequence: readSequence(r),
			DocID:    readString(r),
			RevID:    readString(r),
		}

		if parentID := readString(r); parentID != "" {
			if parent := parents[docAndRev{entry.DocID, parentID}]; parent != nil {
				// Clear out the parent rev that was overwritten by this one
				parent.DocID = ""
				parent.RevID = ""
			}
		}
		parents[docAndRev{entry.DocID, entry.RevID}] = entry

		ch.Entries = append(ch.Entries, entry)
	}
	return &ch
}
Beispiel #26
0
func (ewf_table_section *EWF_Table_Section) Parse(buf *bytes.Reader) {

	defer parseutil.TimeTrack(time.Now(), "Parsing")
	val := make([]byte, int64(buf.Len()))

	buf.Read(val)

	ewf_table_section.table_header.Parse(bytes.NewReader(val[0:24]))
	ewf_table_section.table_footer.Parse(bytes.NewReader(val[len(val)-4 : len(val)]))
	val = val[24 : len(val)-4]
	k := 0
	ewf_table_section.Table_entries = make([]EWF_Table_Section_Entry, ewf_table_section.table_header.nofEntries)
	for i := uint32(0); i < ewf_table_section.table_header.nofEntries; i += 1 {

		ewf_table_section.Table_entries[i].Parse(bytes.NewReader(val[0+k : 4+k]))
		//  fmt.Println("EFW in by",i,
		//       ewf_table_section.table_entries[i].IsCompressed,ewf_table_section.table_entries[i].ChunkDataOffset)
		k += 4

	}

}
Beispiel #27
0
func UnpackLabels(buf *bytes.Reader, p []byte) ([]string, error) {
	labels := make([]string, 0, 5)

	for {
		n, e := buf.ReadByte() // label length
		if e != nil {
			return nil, e
		}
		if n == 0 {
			break
		}
		if isRedirect(n) {
			b, e := buf.ReadByte()
			if e != nil {
				return nil, e
			}
			off := offset(n, b)
			if off >= len(p) {
				return nil, errors.New("offset out of range")
			}
			buf = bytes.NewReader(p[off:])
			continue
		}
		if n > 63 {
			return nil, errors.New("label too long")
		}

		labelBuf := make([]byte, n)
		if _, e := buf.Read(labelBuf); e != nil {
			return nil, e
		}

		label := strings.ToLower(string(labelBuf))

		labels = append(labels, label)
	}

	return labels, nil
}
Beispiel #28
0
func NewArrayFromReader(input *bytes.Reader) (value Array, err error) {
	numberOfValueElements, err := binary.ReadUvarint(input)
	if err != nil {
		return
	}

	if numberOfValueElements == 0 {
		// Shortcut
		return Array{}, nil
	} else {
		// Read all lengths
		lengths := make([]uint64, numberOfValueElements)
		for valueNumber := 0; valueNumber < int(numberOfValueElements); valueNumber++ {
			length, err := binary.ReadUvarint(input)
			if err != nil {
				return nil, err
			}
			lengths[valueNumber] = length
		}

		// Now read the actual value
		resultingValueElements := make([][]byte, numberOfValueElements)
		for valueNumber := 0; valueNumber < int(numberOfValueElements); valueNumber++ {
			thisValueLength := lengths[valueNumber]
			valueBuf := make([]byte, thisValueLength)
			numRead, err := input.Read(valueBuf)
			if err != nil {
				return nil, err
			}
			if uint64(numRead) != thisValueLength {
				return nil, errors.New("Could not read all bytes required for this value")
			}

			resultingValueElements[valueNumber] = valueBuf
		}
		return Array(resultingValueElements), nil
	}
}
Beispiel #29
0
func ReadRESP(r *bytes.Reader) (it interface{}, err error) {
	typ := readRune(r)
	switch typ {
	case _RESPARR_:
		l := respUnitLength(r)
		it = readRESPArray(r, l)
	case _RESPBLKSTR_:
		l := respUnitLength(r)
		it = readRESPBulkString(r, l)
	case _RESPINT_:
		it = readRESPInteger(r)
	case _RESPSPSTR_:
		it = readRESPSimpleString(r)
	default:
		remain := make([]byte, 10)
		n, _ := r.Read(remain)
		err = errors.New(fmt.Sprintf("Wrong RESP rune(%q): %q", typ, string(remain[:n])))
		return
	}
	consumeLF(r)

	return
}
Beispiel #30
0
func (store *fileStore) Retrieve(id Id) ([]byte, error) {
	var (
		err  error
		data []byte
	)

	data = make([]byte, 0)

	for {
		var (
			header   blockHeader
			memSlice []byte
			buffer   *bytes.Reader
		)

		if memSlice, err = store.acquireBlock(id); err != nil {
			return nil, err
		}

		buffer = bytes.NewReader(memSlice)

		binary.Read(buffer, binary.BigEndian, &header)

		data = append(data, make([]byte, header.Len)...)
		buffer.Read(data[len(data)-int(header.Len):])

		store.releaseBlock(memSlice)

		if header.Flags&flagLast > 0 {
			break
		} else {
			id = header.NextId
		}
	}

	return data, nil
}