Package de.thetaphi.forbiddenapis
Class AsmUtils
java.lang.Object
de.thetaphi.forbiddenapis.AsmUtils
Some static utilities for analyzing with ASM, also constants.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicBooleanstatic final intMaximum classfile version the bundled ASM can handle.private static final PatternPackage prefixes of documented Java API (extracted from Javadocs of Java 8).private static final Stringprivate static final PatternPattern that matches all module names, which are shipped by default in Java. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbinaryToInternal(String clazz) Converts a binary class name (dotted) to the JVM internal one (slashed).static StringformatClassesAbbreviated(Collection<String> missingClasses) Formats a list of classes, abbreviated, with 2 spaces in front (for logging)static StringgetClassResourceName(String clazz) Converts a binary class name to a ".class" file resource name.static StringgetModuleName(URL jrtUrl) Returns the module name from ajrt:/URL; returns null if no module given or wrong URL type.static Patternglob2Pattern(String... globs) Returns a regex pattern that matches on any of the globs on class names (e.g., "sun.misc.**")static booleanReturns true, if the givenRuntimeExceptionwas caused by ASM's ClassReaderstatic booleanReturns true is a string is a glob patternstatic booleanisPortableRuntimeClass(String className) Returns true, if the given binary class name (dotted) is part of the documented and portable Java APIs.private static booleanisRegexMeta(char c) static booleanisRuntimeModule(String module) Returns true, if the given Java 9 module name is part of the runtime (no custom 3rd party module).private static PatternmakePkgPrefixPattern(String... prefixes) static org.objectweb.asm.ClassReaderreadAndPatchClass(InputStream in, Logger logger) Utility method to load class files of later Java versions by patching them, so ASM can read them.private static byte[]This method is used to read the whole stream into byte array.
-
Field Details
-
REGEX_META_CHARS
- See Also:
-
PORTABLE_RUNTIME_PACKAGE_PATTERN
Package prefixes of documented Java API (extracted from Javadocs of Java 8). -
RUNTIME_MODULES_PATTERN
Pattern that matches all module names, which are shipped by default in Java. (see:http://openjdk.java.net/projects/jigsaw/spec/sotms/): The remaining platform modules will share the 'java.' name prefix and are likely to include, e.g., java.sql for database connectivity, java.xml for XML processing, and java.logging for logging. Modules that are not defined in the Java SE 9 Platform Specification but instead specific to the JDK will, by convention, share the 'jdk.' name prefix. -
LATEST_CLASS_VERSION
public static final int LATEST_CLASS_VERSIONMaximum classfile version the bundled ASM can handle.- See Also:
-
CLASS_DOWNGRADE_LOGGED
-
-
Constructor Details
-
AsmUtils
private AsmUtils()
-
-
Method Details
-
makePkgPrefixPattern
-
isRegexMeta
private static boolean isRegexMeta(char c) -
isPortableRuntimeClass
Returns true, if the given binary class name (dotted) is part of the documented and portable Java APIs. -
isRuntimeModule
Returns true, if the given Java 9 module name is part of the runtime (no custom 3rd party module).- Parameters:
module- the module name ornull, if in unnamed module
-
binaryToInternal
Converts a binary class name (dotted) to the JVM internal one (slashed). Only accepts valid class names, no arrays. -
getClassResourceName
Converts a binary class name to a ".class" file resource name. -
isGlob
Returns true is a string is a glob pattern -
glob2Pattern
Returns a regex pattern that matches on any of the globs on class names (e.g., "sun.misc.**") -
getModuleName
Returns the module name from ajrt:/URL; returns null if no module given or wrong URL type. -
readStream
This method is used to read the whole stream into byte array. This allows patching.- Throws:
IOException
-
readAndPatchClass
public static org.objectweb.asm.ClassReader readAndPatchClass(InputStream in, Logger logger) throws IOException Utility method to load class files of later Java versions by patching them, so ASM can read them.- Throws:
IOException
-
isExceptionInAsmClassReader
Returns true, if the givenRuntimeExceptionwas caused by ASM's ClassReader -
formatClassesAbbreviated
Formats a list of classes, abbreviated, with 2 spaces in front (for logging)
-