Class AbstractDCollectionOptimizer
- All Implemented Interfaces:
IPlugin,IDOptimizer
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
Note: Starting from JEB 5.28, collection optimizers are not enabled by default. You must set the
option .parsers.dcmp_dex.EnableCollectionOptimizers to true to instruct the
decompiler to execute them.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of IR method contexts available to the optimizer.Managing dex decompiler.Underlying dex code.IR global context.static final ILoggerPublic logger accessible by the implementing optimizer.IR/AST operation factory reference (for convenience).IR/AST type factory reference (for convenience).Fields inherited from interface com.pnfsoftware.jeb.core.units.code.android.ir.IDOptimizer
DEOBFUSCATOR, INLINER, REORDERER, SLOW -
Constructor Summary
ConstructorsConstructorDescriptionCreate astandardoptimizer.Create an optimizer.AbstractDCollectionOptimizer(DOptimizerType type, String name) Create an optimizer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdd an optimizer tag.voidassignLocalFields(List<IDMethodContext> _ctxlist) This convenience method can be used to assign the object's attributes from the values of the provided IR contexts.protected voidVerify if an interruption request was made by the managing decompiler.Generate a per-class map of method contexts.final StringgetName()Retrieve the plugin name.Retrieve basic information about the plugin, such as name, version, author, and organization.final doubleGet the optimizer priority.getTags()Get the optimizer tags.final DOptimizerTypegetType()Get the optimizer type.final booleanDetermine whether this optimizer performs on a single method or an a collection of methods.final booleanDetermine whether the optimizer is enabled or not.intperform(IDMethodContext ctx) Run the optimizer on the provided target method.abstract intAn optimizer must implement this method.final intperformOnCollection(List<IDMethodContext> ctxlist, Map<IDMethodContext, Integer> pmcntmap) Run the optimizer on the provided collection of methods.protected voidrecordMethodOptimization(IDMethodContext ctx, int cnt) Record optimization counts for a method context.protected voidRemove an optimizer tag.voidReset this object's attributes.voidsetEnabled(boolean enabled) Enable or disable this optimizer.protected voidSet the optimizer name.protected voidsetPriority(double priority) Set the optimizer priority.protected voidsetType(DOptimizerType 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. -
tf
IR/AST type factory reference (for convenience). -
of
IR/AST operation factory reference (for convenience). -
g
IR global context. -
dex
Underlying dex code. -
decomp
Managing dex decompiler. -
ctxlist
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.
-
-
Constructor Details
-
AbstractDCollectionOptimizer
public AbstractDCollectionOptimizer()Create astandardoptimizer. -
AbstractDCollectionOptimizer
Create an optimizer.- Parameters:
type- optimizer type, or null to useDOptimizerType.NORMAL
-
AbstractDCollectionOptimizer
Create an optimizer.- Parameters:
type- optimizer type, or null to useDOptimizerType.NORMALname- optional optimizer name
-
-
Method Details
-
checkInterrupted
protected void checkInterrupted()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. -
getPluginInformation
Description copied from interface:IPluginRetrieve basic information about the plugin, such as name, version, author, and organization.- Specified by:
getPluginInformationin 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:IDOptimizerRetrieve the plugin name. Should be consistent with the value returned bygetPluginInformation().getName().- Specified by:
getNamein interfaceIDOptimizer- Returns:
- optimizer name
-
isCollectionOptimizer
public final boolean isCollectionOptimizer()Description copied from interface:IDOptimizerDetermine whether this optimizer performs on a single method or an a collection of methods.- Specified by:
isCollectionOptimizerin interfaceIDOptimizer- Returns:
- true for collection optimizers, false for single-method optimizers
-
setType
Set the optimizer type. To be used by the constructor.- Parameters:
type- if null, astandardoptimizer is assumed
-
getType
Description copied from interface:IDOptimizerGet the optimizer type. Types are used byoptimizer orchestratorsto determine whether an optimizer should run.- Specified by:
getTypein interfaceIDOptimizer- Returns:
- optimizer type
-
addTag
Add an optimizer tag.- Parameters:
tag- tag to add
-
removeTag
Remove an optimizer tag.- Parameters:
tag- tag to remove
-
getTags
Description copied from interface:IDOptimizerGet the optimizer tags. An optimizer may have 0, 1, or more tags. A tag is a non-null, non-empty string.- Specified by:
getTagsin interfaceIDOptimizer- Returns:
- a collection of tags; may be empty (tags are optional), but never null
-
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 final double getPriority()Description copied from interface:IDOptimizerGet the optimizer priority. A higher value means a higher priority. Priorities are used byoptimizer orchestratorsto determine in which order optimizers should be executed.- Specified by:
getPriorityin interfaceIDOptimizer- Returns:
- the default priority
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable this optimizer. This flag is checked by amaster optimizer.- Parameters:
enabled- true to enable this optimizer
-
isEnabled
public final boolean isEnabled()Description copied from interface:IDOptimizerDetermine whether the optimizer is enabled or not. This method is used byoptimizer orchestratorsto determine whether an optimizer can be scheduled for execution.- Specified by:
isEnabledin interfaceIDOptimizer- Returns:
- true if this optimizer is enabled
-
performOnCollection
public final int performOnCollection(List<IDMethodContext> ctxlist, Map<IDMethodContext, Integer> pmcntmap) Description copied from interface:IDOptimizerRun the optimizer on the provided collection of methods.For this method to be called by an
orchestrator,IDOptimizer.isCollectionOptimizer()must returntrue.- Specified by:
performOnCollectionin interfaceIDOptimizer- Parameters:
ctxlist- a collection of method contextspmcntmap- optional output map that will receive the per-method optimization counts- Returns:
- number of optimizations performed
-
perform
Description copied from interface:IDOptimizerRun the optimizer on the provided target method.For this method to be called by an
orchestrator,IDOptimizer.isCollectionOptimizer()must returnfalse.- Specified by:
performin interfaceIDOptimizer- Parameters:
ctx- a method context- Returns:
- number of optimizations performed
-
recordMethodOptimization
Record optimization counts for a method context.- Parameters:
ctx- method contextcnt- number of optimizations performed
-
performOnCollection
public abstract int performOnCollection()An optimizer must implement this method. This method is called by a master optimizer to perform optimizations on the provided target contexts.- Returns:
- total count of optimizations; it is also recommended to register per-method
optimizations with
recordMethodOptimization(IDMethodContext, int)
-
assignLocalFields
This convenience method can be used to assign the object's attributes from the values of the provided IR contexts.- Parameters:
_ctxlist- an IR context
-
resetLocalFields
public void resetLocalFields()Reset this object's attributes. Same asassignLocalFields(null). -
generatePerClassContextsMap
Generate a per-class map of method contexts.- Returns:
- a map with key= class signature C, value= list of IR contexts for methods belonging to the class C
-