From 663631f0456fcc245dd835889f86541d75161c53 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 28 Aug 2014 20:52:43 +0400 Subject: java-decompiler: post-import cleanup (classes moved) --- .../java/decompiler/struct/lazy/LazyLoader.java | 186 +++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java (limited to 'src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java') diff --git a/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java b/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java new file mode 100644 index 0000000..94cef9a --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/lazy/LazyLoader.java @@ -0,0 +1,186 @@ +/* + * 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.lazy; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; + +import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider; +import org.jetbrains.java.decompiler.struct.StructMethod; +import org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute; +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.util.DataInputFullStream; + +public class LazyLoader { + + private HashMap mapClassLinks = new HashMap(); + + private IBytecodeProvider provider; + + public LazyLoader(IBytecodeProvider provider) { + this.provider = provider; + } + + public void addClassLink(String classname, Link link) { + mapClassLinks.put(classname, link); + } + + public void removeClassLink(String classname) { + mapClassLinks.remove(classname); + } + + public Link getClassLink(String classname) { + return mapClassLinks.get(classname); + } + + + public ConstantPool loadPool(String classname) { + + try { + + DataInputFullStream in = getClassStream(classname); + if(in == null) { + return null; + } + + in.skip(8); + + return new ConstantPool(in); + + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + public byte[] loadBytecode(StructMethod mt, int code_fulllength) { + + try { + + DataInputFullStream in = getClassStream(mt.getClassStruct().qualifiedName); + if(in == null) { + return null; + } + + byte[] res = null; + + in.skip(8); + + ConstantPool pool = mt.getClassStruct().getPool(); + if(pool == null) { + pool = new ConstantPool(in); + } else { + ConstantPool.skipPool(in); + } + + in.skip(2); + int this_class = in.readUnsignedShort(); + in.skip(2); + + // interfaces + in.skip(in.readUnsignedShort() * 2); + + // fields + int size = in.readUnsignedShort(); + for (int i = 0; i < size; i++) { + in.skip(6); + skipAttributes(in); + } + + // methods + size = in.readUnsignedShort(); + for (int i = 0; i < size; i++) { + in.skip(2); + + int name_index = in.readUnsignedShort(); + int descriptor_index = in.readUnsignedShort(); + + String elem_arr[] = pool.getClassElement(ConstantPool.METHOD, this_class, name_index, descriptor_index); + String name = elem_arr[0]; + + if(mt.getName().equals(name)) { + String descriptor = elem_arr[1]; + if(mt.getDescriptor().equals(descriptor)) { + + int len = in.readUnsignedShort(); + for(int j=0;j