diff options
Diffstat (limited to 'src/org/jetbrains/java/decompiler/struct/attr')
12 files changed, 1002 insertions, 0 deletions
diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructAnnDefaultAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnDefaultAttribute.java new file mode 100644 index 0000000..d171349 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnDefaultAttribute.java @@ -0,0 +1,40 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; + +import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + + +public class StructAnnDefaultAttribute extends StructGeneralAttribute { + + private Exprent defaultValue; + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_ANNOTATION_DEFAULT; + + DataInputStream data = new DataInputStream(new ByteArrayInputStream(info)); + defaultValue = StructAnnotationAttribute.parseAnnotationElement(data, pool); + } + + public Exprent getDefaultValue() { + return defaultValue; + } + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationAttribute.java new file mode 100644 index 0000000..8958299 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationAttribute.java @@ -0,0 +1,187 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.code.CodeConstants; +import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent; +import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent; +import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; +import org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent; +import org.jetbrains.java.decompiler.modules.decompiler.exps.NewExprent; +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant; +import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor; +import org.jetbrains.java.decompiler.struct.gen.VarType; + +public class StructAnnotationAttribute extends StructGeneralAttribute { + + private List<AnnotationExprent> annotations; + + public void initContent(ConstantPool pool) { + + super.initContent(pool); + + annotations = new ArrayList<AnnotationExprent>(); + DataInputStream data = new DataInputStream(new ByteArrayInputStream(info, 2, info.length)); + + int len = (((info[0] & 0xFF)<<8) | (info[1] & 0xFF)); + for(int i=0;i<len;i++) { + annotations.add(parseAnnotation(data, pool)); + } + + } + + public static AnnotationExprent parseAnnotation(DataInputStream data, ConstantPool pool) { + + try { + + String classname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); + VarType cltype = new VarType(classname); + + int len = data.readUnsignedShort(); + + List<String> parnames = new ArrayList<String>(); + List<Exprent> parvalues = new ArrayList<Exprent>(); + + for(int i=0;i<len;i++) { + parnames.add(pool.getPrimitiveConstant(data.readUnsignedShort()).getString()); + parvalues.add(parseAnnotationElement(data, pool)); + } + + return new AnnotationExprent(cltype.value, parnames, parvalues); + + } catch(IOException ex) { + throw new RuntimeException(ex); + } + + } + + public static Exprent parseAnnotationElement(DataInputStream data, ConstantPool pool) { + + try { + int tag = data.readUnsignedByte(); + + switch(tag) { + case 'e': // enum constant + String classname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); + String constname = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); + + FieldDescriptor descr = FieldDescriptor.parseDescriptor(classname); + return new FieldExprent(constname, descr.type.value, true, null, descr); + case 'c': // class + String descriptor = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); + VarType type = FieldDescriptor.parseDescriptor(descriptor).type; + + String value; + switch(type.type) { + case CodeConstants.TYPE_OBJECT: + value = type.value; + break; + case CodeConstants.TYPE_BYTE: + value = byte.class.getName(); + break; + case CodeConstants.TYPE_CHAR: + value = char.class.getName(); + break; + case CodeConstants.TYPE_DOUBLE: + value = double.class.getName(); + break; + case CodeConstants.TYPE_FLOAT: + value = float.class.getName(); + break; + case CodeConstants.TYPE_INT: + value = int.class.getName(); + break; + case CodeConstants.TYPE_LONG: + value = long.class.getName(); + break; + case CodeConstants.TYPE_SHORT: + value = short.class.getName(); + break; + case CodeConstants.TYPE_BOOLEAN: + value = boolean.class.getName(); + break; + case CodeConstants.TYPE_VOID: + value = void.class.getName(); + break; + default: + throw new RuntimeException("invalid class type: " + type.type); + } + return new ConstExprent(VarType.VARTYPE_CLASS, value); + case '[': // array + int len = data.readUnsignedShort(); + List<Exprent> lst = new ArrayList<Exprent>(); + + for(int i=0;i<len;i++) { + lst.add(parseAnnotationElement(data, pool)); + } + + VarType newtype; + if(lst.isEmpty()) { + newtype = new VarType(CodeConstants.TYPE_OBJECT, 1, "java/lang/Object"); + } else { + VarType eltype = lst.get(0).getExprType(); + newtype = new VarType(eltype.type, 1, eltype.value); + } + + NewExprent newexpr = new NewExprent(newtype, new ArrayList<Exprent>()); + newexpr.setDirectArrayInit(true); + newexpr.setLstArrayElements(lst); + return newexpr; + case '@': // annotation + return parseAnnotation(data, pool); + default: + PrimitiveConstant cn = pool.getPrimitiveConstant(data.readUnsignedShort()); + switch(tag) { + case 'B': + return new ConstExprent(VarType.VARTYPE_BYTE, cn.value); + case 'C': + return new ConstExprent(VarType.VARTYPE_CHAR, cn.value); + case 'D': + return new ConstExprent(VarType.VARTYPE_DOUBLE, cn.value); + case 'F': + return new ConstExprent(VarType.VARTYPE_FLOAT, cn.value); + case 'I': + return new ConstExprent(VarType.VARTYPE_INT, cn.value); + case 'J': + return new ConstExprent(VarType.VARTYPE_LONG, cn.value); + case 'S': + return new ConstExprent(VarType.VARTYPE_SHORT, cn.value); + case 'Z': + return new ConstExprent(VarType.VARTYPE_BOOLEAN, cn.value); + case 's': + return new ConstExprent(VarType.VARTYPE_STRING, cn.value); + default: + throw new RuntimeException("invalid element type!"); + } + } + } catch(IOException ex) { + throw new RuntimeException(ex); + } + + } + + + public List<AnnotationExprent> getAnnotations() { + return annotations; + } + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationParameterAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationParameterAttribute.java new file mode 100644 index 0000000..dd28aa7 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationParameterAttribute.java @@ -0,0 +1,57 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent; +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructAnnotationParameterAttribute extends StructGeneralAttribute { + + private List<List<AnnotationExprent>> paramAnnotations; + + public void initContent(ConstantPool pool) { + + super.initContent(pool); + + paramAnnotations = new ArrayList<List<AnnotationExprent>>(); + DataInputStream data = new DataInputStream(new ByteArrayInputStream(info)); + + try { + int len = data.readUnsignedByte(); + for(int i=0;i<len;i++) { + List<AnnotationExprent> lst = new ArrayList<AnnotationExprent>(); + int annsize = data.readUnsignedShort(); + + for(int j=0;j<annsize;j++) { + lst.add(StructAnnotationAttribute.parseAnnotation(data, pool)); + } + paramAnnotations.add(lst); + } + } catch(IOException ex) { + throw new RuntimeException(ex); + } + + } + + public List<List<AnnotationExprent>> getParamAnnotations() { + return paramAnnotations; + } +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationTypeAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationTypeAttribute.java new file mode 100644 index 0000000..9677ddd --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationTypeAttribute.java @@ -0,0 +1,188 @@ +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent; +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructAnnotationTypeAttribute extends StructGeneralAttribute { + + public static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS = 0x00; + public static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD = 0x01; + public static final int ANNOTATION_TARGET_TYPE_EXTENDS_IMPLEMENTS = 0x10; + public static final int ANNOTATION_TARGET_TYPE_GENERIC_CLASS_BOUND = 0x11; + public static final int ANNOTATION_TARGET_TYPE_GENERIC_METHOD_BOUND = 0x12; + public static final int ANNOTATION_TARGET_TYPE_FIELD = 0x13; + public static final int ANNOTATION_TARGET_TYPE_RETURN = 0x14; + public static final int ANNOTATION_TARGET_TYPE_RECEIVER = 0x15; + public static final int ANNOTATION_TARGET_TYPE_FORMAL = 0x16; + public static final int ANNOTATION_TARGET_TYPE_THROWS = 0x17; + public static final int ANNOTATION_TARGET_TYPE_LOCAL_VARIABLE = 0x40; + public static final int ANNOTATION_TARGET_TYPE_RESOURCE_VARIABLE = 0x41; + public static final int ANNOTATION_TARGET_TYPE_EXCEPTION = 0x42; + public static final int ANNOTATION_TARGET_TYPE_INSTANCEOF = 0x43; + public static final int ANNOTATION_TARGET_TYPE_NEW = 0x44; + public static final int ANNOTATION_TARGET_TYPE_DOUBLECOLON_NEW = 0x45; + public static final int ANNOTATION_TARGET_TYPE_DOUBLECOLON_ID = 0x46; + public static final int ANNOTATION_TARGET_TYPE_CAST = 0x47; + public static final int ANNOTATION_TARGET_TYPE_INVOKATION_CONSTRUCTOR = 0x48; + public static final int ANNOTATION_TARGET_TYPE_INVOKATION_METHOD = 0x49; + public static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_NEW = 0x4A; + public static final int ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_ID = 0x4B; + + public static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER = 1; + public static final int ANNOTATION_TARGET_UNION_SUPERTYPE = 2; + public static final int ANNOTATION_TARGET_UNION_TYPE_PARAMETER_BOUND = 3; + public static final int ANNOTATION_TARGET_UNION_EMPTY = 4; + public static final int ANNOTATION_TARGET_UNION_FORMAL_PARAMETER = 5; + public static final int ANNOTATION_TARGET_UNION_THROWS = 6; + public static final int ANNOTATION_TARGET_UNION_LOCALVAR = 7; + public static final int ANNOTATION_TARGET_UNION_CATCH = 8; + public static final int ANNOTATION_TARGET_UNION_OFFSET = 9; + public static final int ANNOTATION_TARGET_UNION_TYPE_ARGUMENT = 10; + + + List<AnnotationLocation> locations = new ArrayList<AnnotationLocation>(); + List<AnnotationExprent> annotations = new ArrayList<AnnotationExprent>(); + + public void initContent(ConstantPool pool) { + + super.initContent(pool); + + DataInputStream data = new DataInputStream(new ByteArrayInputStream(info)); + + try { + + int ann_number = data.readUnsignedByte(); + for(int i = 0; i < ann_number; i++) { + locations.add(parseAnnotationLocation(data)); + annotations.add(StructAnnotationAttribute.parseAnnotation(data, pool)); + } + + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + public AnnotationLocation parseAnnotationLocation(DataInputStream data) throws IOException { + + AnnotationLocation ann_location = new AnnotationLocation(); + + // target type + + ann_location.target_type = data.readUnsignedByte(); + + // target union + + switch(ann_location.target_type) { + case ANNOTATION_TARGET_TYPE_GENERIC_CLASS: + case ANNOTATION_TARGET_TYPE_GENERIC_METHOD: + ann_location.target_union = ANNOTATION_TARGET_UNION_TYPE_PARAMETER; + break; + case ANNOTATION_TARGET_TYPE_EXTENDS_IMPLEMENTS: + ann_location.target_union = ANNOTATION_TARGET_UNION_SUPERTYPE; + break; + case ANNOTATION_TARGET_TYPE_GENERIC_CLASS_BOUND: + case ANNOTATION_TARGET_TYPE_GENERIC_METHOD_BOUND: + ann_location.target_union = ANNOTATION_TARGET_UNION_TYPE_PARAMETER_BOUND; + break; + case ANNOTATION_TARGET_TYPE_FIELD: + case ANNOTATION_TARGET_TYPE_RETURN: + case ANNOTATION_TARGET_TYPE_RECEIVER: + ann_location.target_union = ANNOTATION_TARGET_UNION_EMPTY; + break; + case ANNOTATION_TARGET_TYPE_FORMAL: + ann_location.target_union = ANNOTATION_TARGET_UNION_FORMAL_PARAMETER; + break; + case ANNOTATION_TARGET_TYPE_THROWS: + ann_location.target_union = ANNOTATION_TARGET_UNION_THROWS; + break; + case ANNOTATION_TARGET_TYPE_LOCAL_VARIABLE: + case ANNOTATION_TARGET_TYPE_RESOURCE_VARIABLE: + ann_location.target_union = ANNOTATION_TARGET_UNION_LOCALVAR; + break; + case ANNOTATION_TARGET_TYPE_EXCEPTION: + ann_location.target_union = ANNOTATION_TARGET_UNION_CATCH; + break; + case ANNOTATION_TARGET_TYPE_INSTANCEOF: + case ANNOTATION_TARGET_TYPE_NEW: + case ANNOTATION_TARGET_TYPE_DOUBLECOLON_NEW: + case ANNOTATION_TARGET_TYPE_DOUBLECOLON_ID: + ann_location.target_union = ANNOTATION_TARGET_UNION_OFFSET; + break; + case ANNOTATION_TARGET_TYPE_CAST: + case ANNOTATION_TARGET_TYPE_INVOKATION_CONSTRUCTOR: + case ANNOTATION_TARGET_TYPE_INVOKATION_METHOD: + case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_NEW: + case ANNOTATION_TARGET_TYPE_GENERIC_DOUBLECOLON_ID: + ann_location.target_union = ANNOTATION_TARGET_UNION_TYPE_ARGUMENT; + break; + default: + throw new RuntimeException("Unknown target type in a type annotation!"); + } + + // target union data + + switch(ann_location.target_union) { + case ANNOTATION_TARGET_UNION_TYPE_PARAMETER: + case ANNOTATION_TARGET_UNION_FORMAL_PARAMETER: + ann_location.data = new int[] {data.readUnsignedByte()}; + break; + case ANNOTATION_TARGET_UNION_SUPERTYPE: + case ANNOTATION_TARGET_UNION_THROWS: + case ANNOTATION_TARGET_UNION_CATCH: + case ANNOTATION_TARGET_UNION_OFFSET: + ann_location.data = new int[] {data.readUnsignedShort()}; + break; + case ANNOTATION_TARGET_UNION_TYPE_PARAMETER_BOUND: + ann_location.data = new int[] {data.readUnsignedByte(), data.readUnsignedByte()}; + break; + case ANNOTATION_TARGET_UNION_EMPTY: + break; + case ANNOTATION_TARGET_UNION_LOCALVAR: + int table_length = data.readUnsignedShort(); + + ann_location.data = new int[table_length * 3 + 1]; + ann_location.data[0] = table_length; + + for(int i = 0; i < table_length; ++i) { + ann_location.data[3 * i + 1] = data.readUnsignedShort(); + ann_location.data[3 * i + 2] = data.readUnsignedShort(); + ann_location.data[3 * i + 3] = data.readUnsignedShort(); + } + break; + case ANNOTATION_TARGET_UNION_TYPE_ARGUMENT: + ann_location.data = new int[] {data.readUnsignedShort(), data.readUnsignedByte()}; + } + + // target path + + int path_length = data.readUnsignedByte(); + + ann_location.target_path_kind = new int[path_length]; + ann_location.target_argument_index = new int[path_length]; + + for(int i = 0; i < path_length; ++i) { + ann_location.target_path_kind[i] = data.readUnsignedByte(); + ann_location.target_argument_index[i] = data.readUnsignedByte(); + } + + return ann_location; + } + + private static class AnnotationLocation { + + public int target_type; + public int target_union; + + public int[] data; + + public int[] target_path_kind; + public int[] target_argument_index; + } +} + diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructBootstrapMethodsAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructBootstrapMethodsAttribute.java new file mode 100644 index 0000000..ac51027 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructBootstrapMethodsAttribute.java @@ -0,0 +1,62 @@ +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.struct.consts.LinkConstant; +import org.jetbrains.java.decompiler.struct.consts.PooledConstant; + +public class StructBootstrapMethodsAttribute extends StructGeneralAttribute { + + private List<LinkConstant> method_refs = new ArrayList<LinkConstant>(); + private List<List<PooledConstant>> method_arguments = new ArrayList<List<PooledConstant>>(); + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_BOOTSTRAP_METHODS; + + try { + + DataInputStream data = new DataInputStream(new ByteArrayInputStream(info, 0, info.length)); + + int method_number = data.readUnsignedShort(); + + for(int i = 0; i < method_number; ++i) { + int bootstrap_method_ref = data.readUnsignedShort(); + int num_bootstrap_arguments = data.readUnsignedShort(); + + List<PooledConstant> list_arguments = new ArrayList<PooledConstant>(); + + for(int j = 0; j < num_bootstrap_arguments; ++j) { + int bootstrap_argument_ref = data.readUnsignedShort(); + + list_arguments.add(pool.getConstant(bootstrap_argument_ref)); + } + + method_refs.add(pool.getLinkConstant(bootstrap_method_ref)); + method_arguments.add(list_arguments); + } + + } catch(IOException ex) { + throw new RuntimeException(ex); + } + + } + + public int getMethodsNumber() { + return method_refs.size(); + } + + public LinkConstant getMethodReference(int index) { + return method_refs.get(index); + } + + public List<PooledConstant> getMethodArguments(int index) { + return method_arguments.get(index); + } + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructConstantValueAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructConstantValueAttribute.java new file mode 100644 index 0000000..f186767 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructConstantValueAttribute.java @@ -0,0 +1,34 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructConstantValueAttribute extends StructGeneralAttribute { + + private int index; + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_CONSTANT_VALUE; + index = ((info[0] & 0xFF)<<8) | (info[1] & 0xFF); + } + + public int getIndex() { + return index; + } + + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructEnclosingMethodAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructEnclosingMethodAttribute.java new file mode 100644 index 0000000..61bb886 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructEnclosingMethodAttribute.java @@ -0,0 +1,57 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.struct.consts.LinkConstant; + +public class StructEnclosingMethodAttribute extends StructGeneralAttribute { + + private String classname; + + private String mtname; + + private String methodDescriptor; + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_ENCLOSING_METHOD; + + int clindex = (((info[0] & 0xFF)<<8) | (info[1] & 0xFF)); + int mtindex = (((info[2] & 0xFF)<<8) | (info[3] & 0xFF)); + + classname = pool.getPrimitiveConstant(clindex).getString(); + if(mtindex != 0) { + LinkConstant lk = pool.getLinkConstant(mtindex); + + mtname = lk.elementname; + methodDescriptor = lk.descriptor; + } + } + + public String getClassname() { + return classname; + } + + public String getMethodDescriptor() { + return methodDescriptor; + } + + public String getMethodName() { + return mtname; + } + + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java new file mode 100644 index 0000000..4d6bd4c --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java @@ -0,0 +1,78 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructExceptionsAttribute extends StructGeneralAttribute { + + private List<Integer> throwsExceptions = new ArrayList<Integer>(); + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_EXCEPTIONS; + + int length = 2+(((info[0] & 0xFF)<<8) | (info[1] & 0xFF))*2; + for(int i=2;i<length;i+=2) { + int index = ((info[i] & 0xFF)<<8) | (info[i+1] & 0xFF); + throwsExceptions.add(index); + } + + } + + public void writeToStream(DataOutputStream out) throws IOException { + + out.writeShort(attribute_name_index); + + ByteArrayOutputStream codeout = new ByteArrayOutputStream(); + DataOutputStream dataout = new DataOutputStream(codeout); + + int len = throwsExceptions.size(); + dataout.writeShort(len); + + if(len>0) { + info = new byte[len*2]; + for(int i=0,j=0;i<len;i++,j+=2) { + int index = ((Integer)throwsExceptions.get(i)).intValue(); + info[j] = (byte)(index >> 8); + info[j+1] = (byte)(index & 0xFF); + } + dataout.write(info); + } + + out.writeInt(codeout.size()); + out.write(codeout.toByteArray()); + } + + public String getExcClassname(int index, ConstantPool pool) { + return pool.getPrimitiveConstant(((Integer)throwsExceptions.get(index)).intValue()).getString(); + } + + public List<Integer> getThrowsExceptions() { + return throwsExceptions; + } + + public void setThrowsExceptions(List<Integer> throwsExceptions) { + this.throwsExceptions = throwsExceptions; + } + + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java new file mode 100644 index 0000000..2648b3c --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java @@ -0,0 +1,145 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.io.DataOutputStream; +import java.io.IOException; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +/* + attribute_info { + u2 attribute_name_index; + u4 attribute_length; + u1 info[attribute_length]; + } +*/ + +public class StructGeneralAttribute { + + public static final String ATTRIBUTE_CODE = "Code"; + public static final String ATTRIBUTE_INNER_CLASSES = "InnerClasses"; + public static final String ATTRIBUTE_SIGNATURE = "Signature"; + public static final String ATTRIBUTE_ANNOTATION_DEFAULT = "AnnotationDefault"; + public static final String ATTRIBUTE_EXCEPTIONS = "Exceptions"; + public static final String ATTRIBUTE_ENCLOSING_METHOD = "EnclosingMethod"; + public static final String ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations"; + public static final String ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS = "RuntimeInvisibleAnnotations"; + public static final String ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = "RuntimeVisibleParameterAnnotations"; + public static final String ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = "RuntimeInvisibleParameterAnnotations"; + public static final String ATTRIBUTE_RUNTIME_VISIBLE_TYPE_ANNOTATIONS = "RuntimeVisibleTypeAnnotations"; + public static final String ATTRIBUTE_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = "RuntimeInvisibleTypeAnnotations"; + public static final String ATTRIBUTE_LOCAL_VARIABLE_TABLE = "LocalVariableTable"; + public static final String ATTRIBUTE_CONSTANT_VALUE = "ConstantValue"; + public static final String ATTRIBUTE_BOOTSTRAP_METHODS = "BootstrapMethods"; + public static final String ATTRIBUTE_SYNTHETIC = "Synthetic"; + public static final String ATTRIBUTE_DEPRECATED = "Deprecated"; + + + // ***************************************************************************** + // private fields + // ***************************************************************************** + + protected int attribute_name_index; + + protected byte[] info; + + protected String name; + + // ***************************************************************************** + // public methods + // ***************************************************************************** + + public void writeToStream(DataOutputStream out) throws IOException { + out.writeShort(attribute_name_index); + out.writeInt(info.length); + if(info.length>0) { + out.write(info); + } + } + + public void initContent(ConstantPool pool) { + name = pool.getPrimitiveConstant(attribute_name_index).getString(); + } + + public static StructGeneralAttribute getMatchingAttributeInstance(int nameindex, String attrname) { + + StructGeneralAttribute attr; + + if(ATTRIBUTE_INNER_CLASSES.equals(attrname)) { + attr = new StructInnerClassesAttribute(); + } else if(ATTRIBUTE_CONSTANT_VALUE.equals(attrname)) { + attr = new StructConstantValueAttribute(); + } else if(ATTRIBUTE_SIGNATURE.equals(attrname)) { + attr = new StructGenericSignatureAttribute(); + } else if(ATTRIBUTE_ANNOTATION_DEFAULT.equals(attrname)) { + attr = new StructAnnDefaultAttribute(); + } else if(ATTRIBUTE_EXCEPTIONS.equals(attrname)) { + attr = new StructExceptionsAttribute(); + } else if(ATTRIBUTE_ENCLOSING_METHOD.equals(attrname)) { + attr = new StructEnclosingMethodAttribute(); + } else if(ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS.equals(attrname) || + ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS.equals(attrname)) { + attr = new StructAnnotationAttribute(); + } else if(ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS.equals(attrname) || + ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS.equals(attrname)) { + attr = new StructAnnotationParameterAttribute(); + } else if(ATTRIBUTE_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.equals(attrname) || + ATTRIBUTE_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.equals(attrname)) { + attr = new StructAnnotationTypeAttribute(); + } else if(ATTRIBUTE_LOCAL_VARIABLE_TABLE.equals(attrname)) { + attr = new StructLocalVariableTableAttribute(); + } else if(ATTRIBUTE_BOOTSTRAP_METHODS.equals(attrname)) { + attr = new StructBootstrapMethodsAttribute(); + } else if(ATTRIBUTE_SYNTHETIC.equals(attrname) || ATTRIBUTE_DEPRECATED.equals(attrname)) { + attr = new StructGeneralAttribute(); + } else { + // unsupported attribute + return null; + } + + attr.setAttribute_name_index(nameindex); + return attr; + } + + // ***************************************************************************** + // getter and setter methods + // ***************************************************************************** + + public byte[] getInfo() { + return info; + } + + public void setInfo(byte[] info) { + this.info = info; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAttribute_name_index() { + return attribute_name_index; + } + + public void setAttribute_name_index(int attribute_name_index) { + this.attribute_name_index = attribute_name_index; + } + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructGenericSignatureAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructGenericSignatureAttribute.java new file mode 100644 index 0000000..11206e0 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructGenericSignatureAttribute.java @@ -0,0 +1,34 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructGenericSignatureAttribute extends StructGeneralAttribute { + + private String signature; + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_SIGNATURE; + signature = pool.getPrimitiveConstant(((info[0] & 0xFF)<<8) | (info[1] & 0xFF)).getString(); + } + + public String getSignature() { + return signature; + } + + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructInnerClassesAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructInnerClassesAttribute.java new file mode 100644 index 0000000..794da15 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructInnerClassesAttribute.java @@ -0,0 +1,73 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.util.ArrayList; +import java.util.List; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructInnerClassesAttribute extends StructGeneralAttribute { + + private List<int[]> classentries = new ArrayList<int[]>(); + + private List<String[]> stringentries = new ArrayList<String[]>(); + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_INNER_CLASSES; + + int length = 2+(((info[0] & 0xFF)<<8) | (info[1] & 0xFF))*8; + int i=2; + + while(i<length) { + + int[] arr = new int[4]; + for(int j=0;j<4;j++) { + arr[j] = ((info[i] & 0xFF)<<8) | (info[i+1] & 0xFF); + i+=2; + } + + classentries.add(arr); + } + + for(int[] entry: classentries) { + + String[] arr = new String[3]; + // inner name + arr[0] = pool.getPrimitiveConstant(entry[0]).getString(); + //enclosing class + if(entry[1] != 0) { + arr[1] = pool.getPrimitiveConstant(entry[1]).getString(); + } + // original simple name + if(entry[2]!=0) { + arr[2] = pool.getPrimitiveConstant(entry[2]).getString(); + } + + stringentries.add(arr); + } + + } + + public List<int[]> getClassentries() { + return classentries; + } + + public List<String[]> getStringentries() { + return stringentries; + } + +} diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructLocalVariableTableAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructLocalVariableTableAttribute.java new file mode 100644 index 0000000..119d1ff --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructLocalVariableTableAttribute.java @@ -0,0 +1,47 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.struct.attr; + +import java.util.HashMap; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; + +public class StructLocalVariableTableAttribute extends StructGeneralAttribute { + + private HashMap<Integer, String> mapVarNames = new HashMap<Integer, String>(); + + public void initContent(ConstantPool pool) { + + name = ATTRIBUTE_LOCAL_VARIABLE_TABLE; + + int len = ((info[0] & 0xFF)<<8) | (info[1] & 0xFF); + + int ind = 6; + for(int i=0;i<len;i++, ind+=10) { + int nindex = ((info[ind] & 0xFF)<<8) | (info[ind+1] & 0xFF); + int vindex = ((info[ind+4] & 0xFF)<<8) | (info[ind+5] & 0xFF); + + mapVarNames.put(vindex, pool.getPrimitiveConstant(nindex).getString()); + } + } + + public void addLocalVariableTable(StructLocalVariableTableAttribute attr) { + mapVarNames.putAll(attr.getMapVarNames()); + } + + public HashMap<Integer, String> getMapVarNames() { + return mapVarNames; + } +} |