From b4aaff683d78ab92b83f3a7257c33b8e27d1affa Mon Sep 17 00:00:00 2001 From: Thog Date: Tue, 7 Mar 2017 21:24:39 +0100 Subject: Drop unix case style and implement hashCode when equals is overrided Also update Guava to version 21 --- .../cuchaz/enigma/bytecode/CheckCastIterator.java | 119 --------------------- .../java/cuchaz/enigma/bytecode/ClassRenamer.java | 7 +- .../cuchaz/enigma/bytecode/InnerClassWriter.java | 1 - 3 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java (limited to 'src/main/java/cuchaz/enigma/bytecode') diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java deleted file mode 100644 index d15dd87..0000000 --- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.bytecode; - -import java.util.Iterator; - -import cuchaz.enigma.bytecode.CheckCastIterator.CheckCast; -import cuchaz.enigma.mapping.ClassEntry; -import cuchaz.enigma.mapping.MethodEntry; -import cuchaz.enigma.mapping.Signature; -import javassist.bytecode.*; - -@Deprecated -// TODO: Find if this class can have any usage. -public class CheckCastIterator implements Iterator { - - public static class CheckCast { - - public String className; - public MethodEntry prevMethodEntry; - - public CheckCast(String className, MethodEntry prevMethodEntry) { - this.className = className; - this.prevMethodEntry = prevMethodEntry; - } - } - - private ConstPool constants; - private CodeAttribute attribute; - private CodeIterator iter; - private CheckCast next; - - public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { - this.constants = codeAttribute.getConstPool(); - this.attribute = codeAttribute; - this.iter = this.attribute.iterator(); - - this.next = getNext(); - } - - @Override - public boolean hasNext() { - return this.next != null; - } - - @Override - public CheckCast next() { - CheckCast out = this.next; - try { - this.next = getNext(); - } catch (BadBytecode ex) { - throw new Error(ex); - } - return out; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - private CheckCast getNext() throws BadBytecode { - int prevPos = 0; - while (this.iter.hasNext()) { - int pos = this.iter.next(); - int opcode = this.iter.byteAt(pos); - switch (opcode) { - case Opcode.CHECKCAST: - - // get the type of this op code (next two bytes are a classinfo index) - MethodEntry prevMethodEntry = getMethodEntry(prevPos); - if (prevMethodEntry != null) { - return new CheckCast(this.constants.getClassInfo(this.iter.s16bitAt(pos + 1)), prevMethodEntry); - } - break; - } - prevPos = pos; - } - return null; - } - - private MethodEntry getMethodEntry(int pos) { - switch (this.iter.byteAt(pos)) { - case Opcode.INVOKEVIRTUAL: - case Opcode.INVOKESTATIC: - case Opcode.INVOKEDYNAMIC: - case Opcode.INVOKESPECIAL: { - int index = this.iter.s16bitAt(pos + 1); - return new MethodEntry( - new ClassEntry(Descriptor.toJvmName(this.constants.getMethodrefClassName(index))), - this.constants.getMethodrefName(index), - new Signature(this.constants.getMethodrefType(index)) - ); - } - - case Opcode.INVOKEINTERFACE: { - int index = this.iter.s16bitAt(pos + 1); - return new MethodEntry( - new ClassEntry(Descriptor.toJvmName(this.constants.getInterfaceMethodrefClassName(index))), - this.constants.getInterfaceMethodrefName(index), - new Signature(this.constants.getInterfaceMethodrefType(index)) - ); - } - } - return null; - } - - public Iterable casts() { - return () -> CheckCastIterator.this; - } -} diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java index d49f13a..d874633 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java @@ -52,10 +52,10 @@ public class ClassRenamer { private static class ReplacerClassMap extends HashMap { - private ClassNameReplacer m_replacer; + private ClassNameReplacer replacer; public ReplacerClassMap(ClassNameReplacer replacer) { - m_replacer = replacer; + this.replacer = replacer; } @Override @@ -67,7 +67,7 @@ public class ClassRenamer { } public String get(String className) { - return m_replacer.replace(className); + return replacer.replace(className); } } @@ -146,7 +146,6 @@ public class ClassRenamer { // rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo) ConstPool constPool = c.getClassFile().getConstPool(); - String className = constPool.getClassName(); constPool.renameClass(map); // rename class attributes diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java index 6e2a29d..eb70c23 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java @@ -15,7 +15,6 @@ import com.google.common.collect.Lists; import java.util.Collection; import java.util.List; -import cuchaz.enigma.Deobfuscator; import cuchaz.enigma.analysis.JarIndex; import cuchaz.enigma.mapping.*; import javassist.ClassPool; -- cgit v1.2.3