From e27d5967029f4f3da8889dd673ba516dcd9f3ac8 Mon Sep 17 00:00:00 2001 From: gegy1000 Date: Sun, 16 Jun 2019 23:49:25 +0200 Subject: Plugin rework along with API rework: Enigma split from EnigmaProject; plugins now provide services configurable via a profile --- .../java/cuchaz/enigma/analysis/ParsedJar.java | 129 --------------------- 1 file changed, 129 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/analysis/ParsedJar.java (limited to 'src/main/java/cuchaz/enigma/analysis/ParsedJar.java') diff --git a/src/main/java/cuchaz/enigma/analysis/ParsedJar.java b/src/main/java/cuchaz/enigma/analysis/ParsedJar.java deleted file mode 100644 index ddcda3e..0000000 --- a/src/main/java/cuchaz/enigma/analysis/ParsedJar.java +++ /dev/null @@ -1,129 +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.analysis; - -import com.google.common.io.ByteStreams; -import cuchaz.enigma.CompiledSource; -import cuchaz.enigma.bytecode.translators.LocalVariableFixVisitor; -import cuchaz.enigma.translation.representation.entry.ClassEntry; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.ClassNode; - -import javax.annotation.Nullable; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.JarInputStream; - -public class ParsedJar implements CompiledSource { - private final Map classBytes; - private final Map nodeCache = new HashMap<>(); - - public ParsedJar(JarFile jar) throws IOException { - Map uClassBytes = new LinkedHashMap<>(); - try { - // get the jar entries that correspond to classes - Enumeration entries = jar.entries(); - while (entries.hasMoreElements()) { - JarEntry entry = entries.nextElement(); - // is this a class file? - if (entry.getName().endsWith(".class")) { - try (InputStream input = new BufferedInputStream(jar.getInputStream(entry))) { - String path = entry.getName().substring(0, entry.getName().length() - ".class".length()); - uClassBytes.put(path, ByteStreams.toByteArray(input)); - } - } - } - } finally { - jar.close(); - classBytes = Collections.unmodifiableMap(uClassBytes); - } - } - - public ParsedJar(JarInputStream jar) throws IOException { - Map uClassBytes = new LinkedHashMap<>(); - try { - // get the jar entries that correspond to classes - JarEntry entry; - while ((entry = jar.getNextJarEntry()) != null) { - // is this a class file? - if (entry.getName().endsWith(".class")) { - String path = entry.getName().substring(0, entry.getName().length() - ".class".length()); - uClassBytes.put(path, ByteStreams.toByteArray(jar)); - jar.closeEntry(); - } - } - } finally { - jar.close(); - classBytes = Collections.unmodifiableMap(uClassBytes); - } - } - - public void visitReader(Function visitorFunction, int options) { - for (String s : classBytes.keySet()) { - ClassNode nodeCached = nodeCache.get(s); - if (nodeCached != null) { - nodeCached.accept(visitorFunction.apply(s)); - } else { - new ClassReader(classBytes.get(s)).accept(visitorFunction.apply(s), options); - } - } - } - - public void visitNode(Consumer consumer) { - for (String s : classBytes.keySet()) { - consumer.accept(getClassNode(s)); - } - } - - public int getClassCount() { - return classBytes.size(); - } - - @Nullable - @Override - public ClassNode getClassNode(String name) { - return nodeCache.computeIfAbsent(name, (n) -> { - byte[] bytes = classBytes.get(name); - if (bytes == null) { - return null; - } - - ClassReader reader = new ClassReader(bytes); - ClassNode node = new ClassNode(); - - LocalVariableFixVisitor visitor = new LocalVariableFixVisitor(Opcodes.ASM5, node); - reader.accept(visitor, 0); - - return node; - }); - } - - public List getClassEntries() { - List entries = new ArrayList<>(classBytes.size()); - for (String s : classBytes.keySet()) { - entries.add(new ClassEntry(s)); - } - return entries; - } - - public Map getClassDataMap() { - return classBytes; - } -} -- cgit v1.2.3