Class Class2HTML

java.lang.Object
org.apache.bcel.util.Class2HTML
All Implemented Interfaces:
Constants

public class Class2HTML extends Object implements Constants
Read class file(s) and convert them into HTML files. Given a JavaClass object "class" that is in package "package" five files will be created in the specified directory.
  1. "package"."class".html as the main file which defines the frames for the following subfiles.
  2. "package"."class"_attributes.html contains all (known) attributes found in the file
  3. "package"."class"_cp.html contains the constant pool
  4. "package"."class"_code.html contains the byte code
  5. "package"."class"_methods.html contains references to all methods and fields of the class
All subfiles reference each other appropriately, for example clicking on a method in the Method's frame will jump to the appropriate method in the Code frame.
  • Field Details

    • classPackage

      private static String classPackage
    • className

      private static String className
    • constantPool

      private static ConstantPool constantPool
    • basicTypes

      private static final Set<String> basicTypes
    • javaClass

      private final JavaClass javaClass
    • dir

      private final String dir
  • Constructor Details

    • Class2HTML

      public Class2HTML(JavaClass javaClass, String dir) throws IOException
      Writes contents of the given JavaClass into HTML files.
      Parameters:
      javaClass - The class to write.
      dir - The directory to put the files in.
      Throws:
      IOException - Thrown when an I/O exception of some sort has occurred.
    • Class2HTML

      private Class2HTML(JavaClass javaClass, String dir, Charset charset) throws IOException
      Throws:
      IOException
  • Method Details

    • checkFileNameSafe

      private static void checkFileNameSafe(String name) throws IOException
      The class name comes from the attacker-controlled this_class constant of the parsed class file and is concatenated into the five output file paths ("dir + className + suffix"). Class file parsing only folds '/' into '.', so Windows separators ('\\'), drive designators (':') and ".." segments survive and would let a crafted class file write its HTML output outside the target directory (CWE-22).
      Parameters:
      name - the class name about to be used as part of a file name.
      Throws:
      IOException - Thrown if the name contains a path separator, a Windows-reserved file name character, a control character, or a ".." sequence.
    • main

      public static void main(String[] argv) throws IOException
      Main program to convert class files to HTML.
      Parameters:
      argv - command line arguments.
      Throws:
      IOException - Thrown if an I/O error occurs.
    • referenceClass

      static String referenceClass(int index)
      Utility method that converts a class reference in the constant pool, that is, an index to a string.
    • referenceType

      static String referenceType(String type)
    • toHTML

      static String toHTML(String str)
    • toHTMLRef

      static String toHTMLRef(String str)
      Escapes a class or type name taken from the constant pool for use as a relative link target inside an HREF attribute value. On top of the text escaping done by toHTML(String), any ':' is replaced so an attacker-chosen name cannot smuggle a URL scheme such as "javascript:" into the generated link.
    • writeMainHTML

      private void writeMainHTML(AttributeHTML attributeHtml, Charset charset) throws FileNotFoundException, UnsupportedEncodingException
      Throws:
      FileNotFoundException
      UnsupportedEncodingException