diff options
Diffstat (limited to 'src/proguard/classfile/util/DynamicClassReferenceInitializer.java')
-rw-r--r-- | src/proguard/classfile/util/DynamicClassReferenceInitializer.java | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/src/proguard/classfile/util/DynamicClassReferenceInitializer.java b/src/proguard/classfile/util/DynamicClassReferenceInitializer.java index 865e094..413d885 100644 --- a/src/proguard/classfile/util/DynamicClassReferenceInitializer.java +++ b/src/proguard/classfile/util/DynamicClassReferenceInitializer.java @@ -2,7 +2,7 @@ * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * - * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu) + * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -66,21 +66,21 @@ implements InstructionVisitor, new MethodrefConstant(1, 2, null, null), new ClassConstant(3, null), new NameAndTypeConstant(4, 5), - new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_LANG_CLASS), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_CLASS_FOR_NAME), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_CLASS_FOR_NAME), + new Utf8Constant(ClassConstants.NAME_JAVA_LANG_CLASS), + new Utf8Constant(ClassConstants.METHOD_NAME_CLASS_FOR_NAME), + new Utf8Constant(ClassConstants.METHOD_TYPE_CLASS_FOR_NAME), // 6 new MethodrefConstant(1, 7, null, null), new NameAndTypeConstant(8, 9), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_NEW_INSTANCE), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_NEW_INSTANCE), + new Utf8Constant(ClassConstants.METHOD_NAME_NEW_INSTANCE), + new Utf8Constant(ClassConstants.METHOD_TYPE_NEW_INSTANCE), // 10 new MethodrefConstant(1, 11, null, null), new NameAndTypeConstant(12, 13), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_CLASS_GET_COMPONENT_TYPE), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_CLASS_GET_COMPONENT_TYPE), + new Utf8Constant(ClassConstants.METHOD_NAME_CLASS_GET_COMPONENT_TYPE), + new Utf8Constant(ClassConstants.METHOD_TYPE_CLASS_GET_COMPONENT_TYPE), }; // Class.forName("SomeClass"). @@ -103,15 +103,15 @@ implements InstructionVisitor, // { // new MethodrefConstant(A, 1, null, null), // new NameAndTypeConstant(2, 3), -// new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JAVAC), -// new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JAVAC), +// new Utf8Constant(ClassConstants.METHOD_NAME_DOT_CLASS_JAVAC), +// new Utf8Constant(ClassConstants.METHOD_TYPE_DOT_CLASS_JAVAC), // }; private final Constant[] DOT_CLASS_JAVAC_CONSTANTS = new Constant[] { new MethodrefConstant(A, 1, null, null), new NameAndTypeConstant(B, 2), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JAVAC), + new Utf8Constant(ClassConstants.METHOD_TYPE_DOT_CLASS_JAVAC), }; // SomeClass.class = class$("SomeClass") (javac). @@ -126,15 +126,15 @@ implements InstructionVisitor, // { // new MethodrefConstant(A, 1, null, null), // new NameAndTypeConstant(2, 3), -// new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JIKES), -// new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JIKES), +// new Utf8Constant(ClassConstants.METHOD_NAME_DOT_CLASS_JIKES), +// new Utf8Constant(ClassConstants.METHOD_TYPE_DOT_CLASS_JIKES), // }; private final Constant[] DOT_CLASS_JIKES_CONSTANTS = new Constant[] { new MethodrefConstant(A, 1, null, null), new NameAndTypeConstant(B, 2), - new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JIKES), + new Utf8Constant(ClassConstants.METHOD_TYPE_DOT_CLASS_JIKES), }; // SomeClass.class = class("SomeClass", false) (jikes). @@ -240,6 +240,19 @@ implements InstructionVisitor, public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) { + // Try to match the (SomeClass)Class.forName(someName).newInstance() + // construct. Apply this matcher first, so the next matcher can still + // reset it after the first instruction. + instruction.accept(clazz, method, codeAttribute, offset, + classForNameCastMatcher); + + // Did we find a match? + if (classForNameCastMatcher.isMatching()) + { + // Print out a note about the construct. + clazz.constantPoolEntryAccept(classForNameCastMatcher.matchedConstantIndex(X), this); + } + // Try to match the Class.forName("SomeClass") construct. instruction.accept(clazz, method, codeAttribute, offset, constantClassForNameMatcher); @@ -254,18 +267,6 @@ implements InstructionVisitor, classForNameCastMatcher.reset(); } - // Try to match the (SomeClass)Class.forName(someName).newInstance() - // construct. - instruction.accept(clazz, method, codeAttribute, offset, - classForNameCastMatcher); - - // Did we find a match? - if (classForNameCastMatcher.isMatching()) - { - // Print out a note about the construct. - clazz.constantPoolEntryAccept(classForNameCastMatcher.matchedConstantIndex(X), this); - } - // Try to match the javac .class construct. instruction.accept(clazz, method, codeAttribute, offset, dotClassJavacMatcher); @@ -336,15 +337,15 @@ implements InstructionVisitor, String methodType = methodrefConstant.getType(clazz); // Do the method's class and type match? - if (methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JAVAC) || - methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JIKES)) + if (methodType.equals(ClassConstants.METHOD_TYPE_DOT_CLASS_JAVAC) || + methodType.equals(ClassConstants.METHOD_TYPE_DOT_CLASS_JIKES)) { String methodName = methodrefConstant.getName(clazz); // Does the method's name match one of the special names? isClassForNameInvocation = - methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JAVAC) || - methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JIKES); + methodName.equals(ClassConstants.METHOD_NAME_DOT_CLASS_JAVAC) || + methodName.equals(ClassConstants.METHOD_NAME_DOT_CLASS_JIKES); if (isClassForNameInvocation) { |