From fc95a96e7363ec2adb9fc13724d190b5865e73f3 Mon Sep 17 00:00:00 2001 From: Vincent Rasquier Date: Thu, 14 Dec 2017 17:33:22 +0100 Subject: [PATCH] Add Type class --- asm/classreader.go | 4 ++-- asm/type.go | 34 ++++++++++++++++++++++++++++++++++ asm/typed/type.go | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 asm/type.go create mode 100644 asm/typed/type.go diff --git a/asm/classreader.go b/asm/classreader.go index f128d5a..f3e0550 100644 --- a/asm/classreader.go +++ b/asm/classreader.go @@ -1607,11 +1607,11 @@ func (c ClassReader) readConst(constantPoolEntryIndex int, charBuffer []rune) (i case byte(symbol.CONSTANT_DOUBLE_TAG): return float64(c.readLong(cpInfoOffset)), nil case byte(symbol.CONSTANT_CLASS_TAG): - return 0, nil //Type.getObjectType(c.readUTF8(cpInfoOffset, charBuffer)) + return getObjectType(c.readUTF8(cpInfoOffset, charBuffer)), nil case byte(symbol.CONSTANT_STRING_TAG): return c.readUTF8(cpInfoOffset, charBuffer), nil case byte(symbol.CONSTANT_METHOD_TYPE_TAG): - return 0, nil //Type.getMethodType(c.readUTF8(cpInfoOffset, charBuffer)) + return getMethodType(c.readUTF8(cpInfoOffset, charBuffer)), nil case byte(symbol.CONSTANT_METHOD_HANDLE_TAG): referenceKind := c.readByte(cpInfoOffset) referenceCpInfoOffset := c.cpInfoOffsets[c.readUnsignedShort(cpInfoOffset+1)] diff --git a/asm/type.go b/asm/type.go new file mode 100644 index 0000000..d9cd925 --- /dev/null +++ b/asm/type.go @@ -0,0 +1,34 @@ +package asm + +import "github.com/leaklessgfy/asm/asm/typed" + +type Type struct { + sort int + valueBuffer []rune + valueOffset int + valueLength int +} + +func getObjectType(internalName string) *Type { + valueBuffer := []rune(internalName) + typ := typed.INTERNAL + if valueBuffer[0] == '[' { + typ = typed.ARRAY + } + return &Type{ + sort: typ, + valueBuffer: valueBuffer, + valueOffset: 0, + valueLength: len(valueBuffer), + } +} + +func getMethodType(methodDescriptor string) *Type { + valueBuffer := []rune(methodDescriptor) + return &Type{ + typed.METHOD, + valueBuffer, + 0, + len(valueBuffer), + } +} diff --git a/asm/typed/type.go b/asm/typed/type.go new file mode 100644 index 0000000..ac6e7d8 --- /dev/null +++ b/asm/typed/type.go @@ -0,0 +1,20 @@ +package typed + +const ( + VOID = 0 + BOOLEAN = 1 + CHAR = 2 + BYTE = 3 + SHORT = 4 + INT = 5 + FLOAT = 6 + LONG = 7 + DOUBLE = 8 + ARRAY = 9 + OBJECT = 10 + METHOD = 11 + INTERNAL = 12 +) + +var PRIMITIVE_DESCRIPTORS = []rune{'V', 'Z', 'C', 'B', 'S', 'I', 'F', 'J', 'D'} + \ No newline at end of file