java.lang.Object | ||
↳ | com.pnfsoftware.jeb.core.AbstractPlugin | |
↳ | com.pnfsoftware.jeb.core.units.code.android.ir.AbstractDCollectionOptimizer |
Base class for dexdec
(DEX decompiler) IR optimizer plugins working on a collection of IR
contexts. Those plugins can access and modify the intermediate representation of a group of
methods being decompiled. They can be used to implement a wide range of optimizations, from
trivial code clean-up to the most complex deobfuscation passes. Internally, dexdec
uses
IR optimizers to perform dead-code removal, variable substitutions, immediate propagation,
restructuring, constant folding, arithmetic operation simplifications, deobfuscations such as
control-flow unflattening, etc.
Optimizers are usually managed by master optimizers
(also called
orchestrators
). Third-party optimizer plugins can be automatically registered when
creating an orchestrator. Refer to createMasterOptimizer
.
Life-cycle information:
- plugins are reused (i.e. the performOnCollection()
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
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
com.pnfsoftware.jeb.core.units.code.android.ir.IDOptimizer
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public List<IDMethodContext> | ctxlist | The list of IR method contexts available to the optimizer. | |||||||||
public IDexDecompilerUnit | decomp | Managing dex decompiler. | |||||||||
public IDexUnit | dex | Underlying dex code. | |||||||||
public IDGlobalContext | g | IR global context. | |||||||||
public static final ILogger | logger | Public logger accessible by the implementing optimizer. | |||||||||
public IJavaOperatorFactory | of | IR/AST operation factory reference (for convenience). | |||||||||
public IJavaTypeFactory | tf | IR/AST type factory reference (for convenience). |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractDCollectionOptimizer()
Create a
standard optimizer. | |||||||||||
AbstractDCollectionOptimizer(DOptimizerType type)
Create an optimizer.
| |||||||||||
AbstractDCollectionOptimizer(DOptimizerType type, String name)
Create an optimizer.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
assignLocalFields(List<IDMethodContext> _ctxlist)
This convenience method can be used to assign the object's attributes from the values of the
provided IR contexts.
| ||||||||||
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.
| ||||||||||
Set<String> |
getTags()
Get the optimizer tags.
| ||||||||||
DOptimizerType |
getType()
Get the optimizer type.
| ||||||||||
boolean |
isCollectionOptimizer()
Determine whether this optimizer performs on a single method or an a collection of methods.
| ||||||||||
boolean |
isEnabled()
Determine whether the optimizer is enabled or not.
| ||||||||||
int |
perform(IDMethodContext ctx)
Run the optimizer on the provided target method.
| ||||||||||
abstract int |
performOnCollection()
An optimizer must implement this method.
| ||||||||||
final int |
performOnCollection(List<IDMethodContext> ctxlist, Map<IDMethodContext, Integer> pmcntmap)
Run the optimizer on the provided collection of methods.
| ||||||||||
void |
resetLocalFields()
Reset this object's attributes.
| ||||||||||
void |
setEnabled(boolean enabled)
Enable or disable this optimizer.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | addTag(String tag) | ||||||||||
void |
checkInterrupted()
Verify if an interruption request was made by the managing decompiler.
| ||||||||||
void | recordMethodOptimization(IDMethodContext ctx, int cnt) | ||||||||||
void | removeTag(String tag) | ||||||||||
void |
setName(String name)
Set the optimizer name.
| ||||||||||
void |
setPriority(double priority)
Set the optimizer priority.
| ||||||||||
void |
setType(DOptimizerType 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.android.ir.IDOptimizer
|
The list of IR method contexts available to the optimizer. A collection is not a class. Those IR contexts may represent methods from multiple classes.
Public logger accessible by the implementing optimizer. Writing to the logger should be
favored over writing directly to stdout
.
This convenience method can be used to assign the object's attributes from the values of the provided IR contexts.
_ctxlist | an IR context |
---|
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 tags. An optimizer may have 0, 1, or more tags. A tag is a non-null, non-empty string.
Get the optimizer type. Types are used by optimizer orchestrators
to determine whether an optimizer should run.
Determine whether this optimizer performs on a single method or an a collection of methods.
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 method.
For this method to be called by an orchestrator
,
isCollectionOptimizer()
must return false
.
ctx | a method context |
---|
An optimizer must implement this method. This method is called by a master optimizer to perform optimizations on the provided target contexts.
Run the optimizer on the provided collection of methods.
For this method to be called by an orchestrator
,
isCollectionOptimizer()
must return true
.
ctxlist | a collection of method contexts |
---|---|
pmcntmap | optional output map that will receive the per-method optimization counts |
Reset this object's attributes. Same as #assignLocalFields(IDMethodContext) assignLocalFields(null).
Enable or disable this optimizer. This flag is checked by a master
optimizer
.
Verify if an interruption request was made by the managing decompiler. This method may be called when potentially length computations are performed in a loop.
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
|
---|