package org.apache.bcel.util; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.Charset; import java.util.BitSet; import org.apache.bcel.Const; import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.LocalVariableTable; import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.Utility; final class CodeHTML { private static boolean wide; private final String className; private final PrintWriter printWriter; private BitSet gotoSet; private final ConstantPool constantPool; private final ConstantHTML constantHtml; CodeHTML(String dir, String className, Method[] methods, ConstantPool constantPool, ConstantHTML constantHtml, Charset charset) throws IOException { this.className = className; this.constantPool = constantPool; this.constantHtml = constantHtml; PrintWriter newPrintWriter = new PrintWriter(dir + className + "_code.html", charset.name()); Throwable var8 = null; try { this.printWriter = newPrintWriter; this.printWriter.print("
"); this.printWriter.println(""); for(int i = 0; i < methods.length; ++i) { this.writeMethod(methods[i], i); } this.printWriter.println(""); } catch (Throwable var17) { var8 = var17; throw var17; } finally { if (newPrintWriter != null) { if (var8 != null) { try { newPrintWriter.close(); } catch (Throwable var16) { var8.addSuppressed(var16); } } else { newPrintWriter.close(); } } } } private String codeToHTML(ByteSequence var1, int var2) throws IOException { // $FF: Couldn't be decompiled } private void findGotos(ByteSequence bytes, Code code) throws IOException { this.gotoSet = new BitSet(bytes.available()); int defaultOffset; int offset; int npairs; if (code != null) { CodeException[] ce = code.getExceptionTable(); CodeException[] var6 = ce; defaultOffset = ce.length; for(offset = 0; offset < defaultOffset; ++offset) { CodeException cex = var6[offset]; this.gotoSet.set(cex.getStartPC()); this.gotoSet.set(cex.getEndPC()); this.gotoSet.set(cex.getHandlerPC()); } Attribute[] attributes = code.getAttributes(); Attribute[] var15 = attributes; offset = attributes.length; for(npairs = 0; npairs < offset; ++npairs) { Attribute attribute = var15[npairs]; if (attribute.getTag() == 5) { ((LocalVariableTable)attribute).forEach((var) -> { int start = var.getStartPC(); this.gotoSet.set(start); this.gotoSet.set(start + var.getLength()); }); break; } } } while(true) { while(bytes.available() > 0) { int opcode = bytes.readUnsignedByte(); int index; switch (opcode) { case 153: case 154: case 155: case 156: case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 198: case 199: index = bytes.getIndex() + bytes.readShort() - 1; this.gotoSet.set(index); break; case 169: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: default: bytes.unreadByte(); this.codeToHTML(bytes, 0); break; case 170: case 171: int remainder = bytes.getIndex() % 4; int noPadBytes = remainder == 0 ? 0 : 4 - remainder; for(npairs = 0; npairs < noPadBytes; ++npairs) { bytes.readByte(); } defaultOffset = bytes.readInt(); int j; if (opcode == 170) { npairs = bytes.readInt(); j = bytes.readInt(); offset = bytes.getIndex() - 12 - noPadBytes - 1; defaultOffset += offset; this.gotoSet.set(defaultOffset); for(int j = 0; j < j - npairs + 1; ++j) { index = offset + bytes.readInt(); this.gotoSet.set(index); } } else { npairs = bytes.readInt(); offset = bytes.getIndex() - 8 - noPadBytes - 1; defaultOffset += offset; this.gotoSet.set(defaultOffset); for(j = 0; j < npairs; ++j) { bytes.readInt(); index = offset + bytes.readInt(); this.gotoSet.set(index); } } break; case 200: case 201: index = bytes.getIndex() + bytes.readInt() - 1; this.gotoSet.set(index); } } return; } } private void writeMethod(Method method, int methodNumber) throws IOException { String signature = method.getSignature(); String[] args = Utility.methodSignatureArgumentTypes(signature, false); String type = Utility.methodSignatureReturnType(signature, false); String name = method.getName(); String htmlName = Class2HTML.toHTML(name); String access = Utility.accessToString(method.getAccessFlags()); access = Utility.replace(access, " ", " "); Attribute[] attributes = method.getAttributes(); this.printWriter.print("" + access + " " + Class2HTML.referenceType(type) + " " + htmlName + "("); for(int i = 0; i < args.length; ++i) { this.printWriter.print(Class2HTML.referenceType(args[i])); if (i < args.length - 1) { this.printWriter.print(", "); } } this.printWriter.println(")
"); Code c = null; byte[] code = null; if (attributes.length > 0) { this.printWriter.print("Byte offset | Instruction | Argument | "); String anchor; String anchor2; String str; for(; stream.available() > 0; this.printWriter.println("
---|---|---|
" + anchor2 + " | " + anchor + str + " | |