Exemplo n.º 1
0
func (a *attribute_info) String(c *ConstantPool) (ret string) {
	ret = c.Lut(a.Attribute_name_index).String()
	switch n := c.Lut(a.Attribute_name_index).String(); n {
	case "Signature", "SourceFile":
		ret += "="
		br := binary.BinaryReader{bytes.NewReader(a.Info), binary.BigEndian}
		if i16, err := br.Uint16(); err != nil {
			ret += err.Error()
		} else {
			ret += c.Lut(u2(i16)).String()
		}
	case "Code":
		ret += " ("
		var cl Code_attribute
		br := binary.BinaryReader{bytes.NewReader(a.Info), binary.BigEndian}
		if err := br.ReadInterface(&cl); err != nil {
			ret += err.Error()
		} else {
			for _, a2 := range cl.Attributes {
				ret += fmt.Sprintf(" %s", c.Lut(a2.Attribute_name_index))
			}
		}
		ret += " )"
	}
	return ret
}
Exemplo n.º 2
0
func testparse(c *Class, members []member_info, method bool, t *testing.T) {
	for i := range members {
		var p descriptors.DESCRIPTORS
		desc := c.Constant_pool.Lut(members[i].Descriptor_index).String()
		if !p.Parse(desc) || p.RootNode().Range.End() != len(desc) {
			t.Errorf("Failed to parse descriptor: %s\n%s\n%s", p.Error(), desc, p.RootNode())
		}
		var p2 signatures.SIGNATURES
		for _, attr := range members[i].Attributes {
			if c.Constant_pool.Lut(attr.Attribute_name_index).String() == "Signature" {
				br := binary.BinaryReader{bytes.NewReader(attr.Info), binary.BigEndian}
				if i16, err := br.Uint16(); err != nil {
					t.Error(err)
				} else {
					sign := c.Constant_pool.Lut(u2(i16)).String()
					p2.SetData(sign)
					var ret bool
					if method {
						ret = p2.MethodTypeSignature()
					} else {
						ret = p2.FieldTypeSignature()
					}
					p2.RootNode().UpdateRange()
					if !ret || p2.RootNode().Range.End() != len(sign) {
						t.Errorf("Failed to parse signature: %s\n%s\n%s", p2.Error(), desc, p2.RootNode())
					}
				}
			}
		}
	}
}
Exemplo n.º 3
0
func (m *MetadataUtil) ReadIndex(br *binary.BinaryReader, size uint) (uint32, error) {
	if size != 2 {
		return br.Uint32()
	} else if v, e := br.Uint16(); e != nil {
		return 0, e
	} else {
		return uint32(v), nil
	}
}
Exemplo n.º 4
0
func (ih *Header) Read(br *binary.BinaryReader) error {
	if v, err := br.Uint32(); err != nil {
		return err
	} else if v != 0xffffffff {
		ih.Length = uint64(v)
	} else if v, err := br.Uint64(); err != nil {
		return err
	} else {
		ih.is64 = true
		ih.Length = v
	}
	var err error
	ih.Version, err = br.Uint16()
	return err
}
Exemplo n.º 5
0
func (a *attribute_info) String(c *ConstantPool) (ret string) {
	ret = c.Lut(a.Attribute_name_index).String()
	switch n := c.Lut(a.Attribute_name_index).String(); n {
	case "Signature", "SourceFile":
		ret += "="
		br := binary.BinaryReader{Reader: bytes.NewReader(a.Info), Endianess: binary.BigEndian}
		if i16, err := br.Uint16(); err != nil {
			ret += err.Error()
		} else {
			ret += c.Lut(u2(i16)).String()
		}
	case "Code":
		ret += " ( "
		var cl Code_attribute
		br := binary.BinaryReader{Reader: bytes.NewReader(a.Info), Endianess: binary.BigEndian}
		if err := br.ReadInterface(&cl); err != nil {
			ret += err.Error()
		} else {
			ret += strings.Join(sortStrings(cl.Attributes, c), " ")
		}
		ret += " )"
	}
	return ret
}
Exemplo n.º 6
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))
}
Exemplo n.º 7
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
}