Class AbstractJOptimizer
- All Implemented Interfaces:
IPlugin
,IJOptimizer
- Direct Known Subclasses:
AbstractJBlockOptimizer
,AbstractJElementOptimizer
,AbstractJStatementOptimizer
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionTarget AST class to be optimized.AST constant factory (for convenience - referenced injctx
).Managing dex decompiler.Underlying dex code.Collector for deferred requests.Java AST global context.static final ILogger
Public logger accessible by the implementing optimizer.Target AST method to be optimized.AST operation factory (for convenience - referenced injctx
).AST type factory (for convenience - referenced injctx
). -
Constructor Summary
ConstructorsConstructorDescriptionCreate a standard optimizer.Create an optimizer.AbstractJOptimizer
(JOptimizerType type, String name) Create an optimizer. -
Method Summary
Modifier and TypeMethodDescriptiongetName()
Retrieve the plugin name.Retrieve basic information about the plugin, such as name, version, author, and organization.double
Get the optimizer priority.getType()
Get the optimizer type.boolean
Determine whether the optimizer is enabled or not.abstract int
perform()
An optimizer must implement this method.final int
Run the optimizer on the provided target element (method or class).void
setEnabled
(boolean enabled) Enable or disable this optimizer.protected void
Set the optimizer name.protected void
setPriority
(double priority) Set the optimizer priority.protected void
setType
(JOptimizerType type) Set the optimizer type.Methods inherited from class com.pnfsoftware.jeb.core.AbstractPlugin
dispose, getData, setData
-
Field Details
-
logger
Public logger accessible by the implementing optimizer. Writing to the logger should be favored over writing directly tostdout
. -
c
Target AST class to be optimized. May be null, in which casem
is not. -
m
Target AST method to be optimized. May be null, in which casec
is not. -
jctx
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. -
tf
AST type factory (for convenience - referenced injctx
). -
of
AST operation factory (for convenience - referenced injctx
). -
cf
AST constant factory (for convenience - referenced injctx
). -
dex
Underlying dex code. May be null. -
decomp
Managing dex decompiler. May be null. -
drcollector
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 // ... // ...
-
-
Constructor Details
-
AbstractJOptimizer
public AbstractJOptimizer()Create a standard optimizer. -
AbstractJOptimizer
Create an optimizer.- Parameters:
type
-
-
AbstractJOptimizer
Create an optimizer.- Parameters:
type
-name
-
-
-
Method Details
-
getPluginInformation
Description copied from interface:IPlugin
Retrieve basic information about the plugin, such as name, version, author, and organization.- Specified by:
getPluginInformation
in interfaceIPlugin
- Returns:
- the plugin information
-
setName
Set the optimizer name. To be used by the constructor.- Parameters:
name
- if null, a name will be auto-generated
-
getName
Description copied from interface:IJOptimizer
Retrieve the plugin name. Should be consistent with the value returned bygetPluginInformation().getName()
.- Specified by:
getName
in interfaceIJOptimizer
- Returns:
-
setType
Set the optimizer type. To be used by the constructor.- Parameters:
type
- if null, astandard
optimizer is assumed
-
getType
Description copied from interface:IJOptimizer
Get the optimizer type. Types are used byoptimizer orchestrators
to determine whether an optimizer should run.- Specified by:
getType
in interfaceIJOptimizer
- Returns:
-
setPriority
protected void setPriority(double priority) Set the optimizer priority. To be used by the constructor.- Parameters:
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.
-
getPriority
public double getPriority()Description copied from interface:IJOptimizer
Get the optimizer priority. A higher value means a higher priority. Priorities are used byoptimizer orchestrators
to determine in which order optimizers should be executed.- Specified by:
getPriority
in interfaceIJOptimizer
- Returns:
- the default priority
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable this optimizer. This flag is checked by amaster optimizer
.- Parameters:
enabled
-
-
isEnabled
public boolean isEnabled()Description copied from interface:IJOptimizer
Determine whether the optimizer is enabled or not. This method is used byoptimizer orchestrators
to determine whether an optimizer can be scheduled for execution.- Specified by:
isEnabled
in interfaceIJOptimizer
- Returns:
- true if this optimizer is enabled
-
perform
Description copied from interface:IJOptimizer
Run the optimizer on the provided target element (method or class).- Specified by:
perform
in interfaceIJOptimizer
- Parameters:
elt
- an AST element, such as anIJavaMethod
orIJavaClass
- Returns:
- number of optimizations performed
-
perform
public abstract int perform()An optimizer must implement this method. This method is called by a master optimizer toperform
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
); if the data flow analysis is no longer valid, it should be invalidated (seeresetDFA
); etc.- Returns:
- the number of optimizations performed, 0 if none
-