java.lang.Object | ||
↳ | com.pnfsoftware.jeb.core.AbstractPlugin | |
↳ | com.pnfsoftware.jeb.core.units.code.java.AbstractJOptimizer |
Known Direct Subclasses |
Base class for dexdec
(DEX decompiler) AST optimizer plugins. Those plugins can access
and modify the AST of a class or method being decompiled. They can be used to implement simple
code clean-up and beautification/styling.
Optimizers are usually managed by master optimizers
(also called
orchestrators
). Third-party optimizer plugins can be automatically registered when
creating an orchestrator.
Life-cycle information:
- plugins are reused (i.e. the perform()
method is called multiple times)
- thread-safety:
-- Python script plugins must be thread-safe: a plugin instance may be executed by multiple
threads concurrently
-- Java plugins (including Java script plugins) are not required to be thread-safe: a plugin
instance will not be executed by multiple threads concurrently
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public IJavaClass | c | Target AST class to be optimized. | |||||||||
public IJavaConstantFactory | cf | AST constant factory (for convenience - referenced in jctx ). |
|||||||||
public IDexDecompilerUnit | decomp | Managing dex decompiler. | |||||||||
public IDexUnit | dex | Underlying dex code. | |||||||||
public DeferredRequestsCollector | drcollector | Collector for deferred requests. | |||||||||
public IJavaGlobalContext | jctx | Java AST global context. | |||||||||
public static final ILogger | logger | Public logger accessible by the implementing optimizer. | |||||||||
public IJavaMethod | m | Target AST method to be optimized. | |||||||||
public IJavaOperatorFactory | of | AST operation factory (for convenience - referenced in jctx ). |
|||||||||
public IJavaTypeFactory | tf | AST type factory (for convenience - referenced in jctx ). |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractJOptimizer()
Create a standard optimizer.
| |||||||||||
AbstractJOptimizer(JOptimizerType type)
Create an optimizer.
| |||||||||||
AbstractJOptimizer(JOptimizerType type, String name)
Create an optimizer.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String |
getName()
Retrieve the plugin name.
| ||||||||||
EditablePluginInformation |
getPluginInformation()
Retrieve basic information about the plugin, such as name, version, author, and organization.
| ||||||||||
double |
getPriority()
Get the optimizer priority.
| ||||||||||
JOptimizerType |
getType()
Get the optimizer type.
| ||||||||||
boolean |
isEnabled()
Determine whether the optimizer is enabled or not.
| ||||||||||
final int |
perform(IJavaDecompilableElement elt)
Run the optimizer on the provided target element (method or class).
| ||||||||||
abstract int |
perform()
An optimizer must implement this method.
| ||||||||||
void |
setEnabled(boolean enabled)
Enable or disable this optimizer.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
setName(String name)
Set the optimizer name.
| ||||||||||
void |
setPriority(double priority)
Set the optimizer priority.
| ||||||||||
void |
setType(JOptimizerType type)
Set the optimizer type.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.pnfsoftware.jeb.core.AbstractPlugin
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
com.pnfsoftware.jeb.core.IPlugin
| |||||||||||
From interface
com.pnfsoftware.jeb.core.units.code.java.IJOptimizer
|
Collector for deferred requests. May be null. When non-null, optimizers may file requests to decompile other classes, methods, or fields. It is useful for optimizers needing to examine AST code located in other classes or methods to operate.
How to use in your optimizer:
// do some work // ... // need access to the AST of some other class (CX) to continue the work IJavaClass ast_CX = jctx.getClassFactory().get(csig_CX); if(ast_CX == null || !ast_CX.isBuilt()) { // the AST of CX is not available at this time // if we can, request a decompilation if(drcollector != null) { drcollector.request(csig_MX); } return 0; // done for now } // in a future call to this optimizer, the above check may pass, allowing further processing // ... // ...
Java AST global context. This context holds AST element factory methods as well as references to important factories, such as the constant, type, and operator factories.
Public logger accessible by the implementing optimizer. Writing to the logger should be
favored over writing directly to stdout
.
Create a standard optimizer.
Retrieve the plugin name. Should be consistent with the value returned by
getPluginInformation().getName()
.
Retrieve basic information about the plugin, such as name, version, author, and organization.
Get the optimizer priority. A higher value means a higher priority. Priorities are used by
optimizer orchestrators
to determine in which order optimizers
should be executed.
Get the optimizer type. Types are used by optimizer orchestrators
to determine whether an optimizer should run.
Determine whether the optimizer is enabled or not. This method is used by
optimizer orchestrators
to determine whether an optimizer can be
scheduled for execution.
Run the optimizer on the provided target element (method or class).
elt | an AST element, such as an IJavaMethod or IJavaClass |
---|
An optimizer must implement this method. This method is called by a master optimizer to
perform
the optimization on the selected target.
Note that the optimizer is responsible for returning a legal method context, e.g.: the method
IR instructions must be consistent with the CFG; the CFG must adhere to certain rules (see
#cleanGraph() cleanGraph); if the data flow analysis is no longer valid, it should be
invalidated (see resetDFA
); etc.
Enable or disable this optimizer. This flag is checked by a master
optimizer
.
Set the optimizer name. To be used by the constructor.
name | if null, a name will be auto-generated |
---|
Set the optimizer priority. To be used by the constructor.
priority | the new priority (high means higher priority). When optimizers are managed and run by an orchestrator, the optimizers with a higher priority are run before those having a lower priority. The default priority is 0. |
---|
Set the optimizer type. To be used by the constructor.
type | if null, a standard optimizer is assumed
|
---|