jawa.classloader module¶
-
class
jawa.classloader.
ClassLoader
(*sources, max_cache: int = 50, klass=<class 'jawa.cf.ClassFile'>, bytecode_transforms: Iterable[Callable] = None)[source]¶ Bases:
object
Emulate the Java ClassPath.
Provides utilities for managing a java classpath as well as loading classes from those paths.
Parameters: - sources – Optional sources to pass into update().
- max_cache (Long) – The maximum number of ClassFile’s to store in the cache. If set to 0, the cache will be unlimited. [default: 50]
- klass (ClassFile or subclass.) – The class to use when constructing ClassFiles.
- bytecode_transforms – Default transforms to apply when disassembling a method.
-
classes
¶ Yield the name of all classes discovered in the path map.
-
dependencies
(path: str) → Set[str][source]¶ Returns a set of all classes referenced by the ClassFile at path without reading the entire ClassFile.
This is an optimization method that does not load a complete ClassFile, nor does it add the results to the ClassLoader cache.
Parameters: path – Fully-qualified path to a ClassFile.
-
load
(path: str) → jawa.cf.ClassFile[source]¶ Load the class at path and return it.
Load will attempt to load the file at path and path + .class before failing.
Parameters: path – Fully-qualified path to a ClassFile.
-
open
(path: str, mode: str = 'r') → IO[source]¶ Open an IO-like object for path.
Note
Mode must be either ‘r’ or ‘w’, as the underlying objects do not understand the full range of modes.
Parameters: - path – The path to open.
- mode – The mode of the file being opened, either ‘r’ or ‘w’.
-
search_constant_pool
(*, path: str, **options)[source]¶ Partially load the class at path, yield all matching constants from the ConstantPool.
This is an optimization method that does not load a complete ClassFile, nor does it add the results to the ClassLoader cache.
Parameters: - path – Fully-qualified path to a ClassFile.
- options – A list of options to pass into ConstantPool.find()
-
update
(*sources, follow_symlinks: bool = False, maximum_depth: int = 20)[source]¶ Add one or more ClassFile sources to the class loader.
If a given source is a directory path, it is traversed up to the maximum set depth and all files under it are added to the class loader lookup table.
If a given source is a .jar or .zip file it will be opened and the file index added to the class loader lookup table.
If a given source is a ClassFile or a subclass, it’s immediately added to the class loader lookup table and the class cache.
Parameters: - sources – One or more ClassFile sources to be added.
- follow_symlinks – True if symlinks should be followed when traversing filesystem directories. [default: False]
- maximum_depth – The maximum sub-directory depth when traversing filesystem directories. If set to None no limit will be enforced. [default: 20]