Class AbstractMasterOptimizer<T extends IOptimizerTarget>
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.decompiler.opt.AbstractMasterOptimizer<T>
- All Implemented Interfaces:
IMasterOptimizer<T>
- Direct Known Subclasses:
CMasterOptimizer
,EMasterOptimizer
public abstract class AbstractMasterOptimizer<T extends IOptimizerTarget>
extends Object
implements IMasterOptimizer<T>
Standard implementation of a generic master optimizer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
disabled (0) by default; client code must explicitly set to non-zero to allow the execution of decryptors.protected boolean
false by default; client code must explicitly set to true to allow the execution of deobfuscators.protected boolean
false by default; client code must explicitly set to true to allow the execution of unsafe optimizers.protected int
maximum run count for the group [1..N] (<0 means no limit)protected List<IMasterOptimizerInstrumenter<T>>
instrumentersprotected SortedMap<Integer,
List<OptimizerEntry<T>>> groups of optimizers; groups 0 and -1 are entry and exit groups, respectivelyprotected List<OptimizerEntry<T>>
list of all optimizersprotected T
default targetFields inherited from interface com.pnfsoftware.jeb.core.units.code.asm.decompiler.opt.IMasterOptimizer
DEFAULT_GROUP
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractMasterOptimizer
(T t, int grp1NMaxRunCount) Create a master optimizer. -
Method Summary
Modifier and TypeMethodDescriptionint
getMode()
Retrieve the current operating mode for this MO.int
getOptimizationCount
(boolean deobfuscationOnly) getOptimizer
(Class<? extends IOptimizer<T>> clazz) getOptimizerObject
(Class<? extends IOptimizer<T>> clazz) Get a copy of the list of optimizer entries registered with this MO.getRegisteredOptimizers
(int groupId) Get a copy of the lists of optimizer entries registered with this MO and belonging to the provided optimizer group.Get the target onto which the optimizations will be performed.protected abstract String
getTargetAddress
(T target) int
boolean
boolean
protected boolean
onOptimizerException
(T target, IOptimizer<T> opt, Exception ex) This method is called when an optimizer hard-failed and generated an exception.int
perform()
Perform an optimization pass.int
performMultiple
(List<OptimizerEntry<T>> list) Run the list of optimizers, in sequence.int
Perform a single optimization, using the provided optimizer (which must have been previously registered).protected int
protected int
performV2
(boolean rerunFromStartAfterOpt) protected void
postAllOptimizationsCallback
(T target) This method might be overridden, but the parent should be called first.protected void
postOptimizationCallback
(T target, OptimizerEntry<T> e, int cnt, long executionTimeMs) This method might be overridden, but the parent should be called first.protected void
preAllOptimizationsCallback
(T target) This method might be overridden, but the parent should be called first.protected void
preOptimizationCallback
(T target, OptimizerEntry<T> e) This method might be overridden, but the parent should be called first.void
registerInstrumenter
(IMasterOptimizerInstrumenter<T> instrumenter) Register an instrumenter.registerOptimizer
(int group, IOptimizer<T> opt) Register an optimizer, using the optimizer's provided default priority.registerOptimizer
(IOptimizer<T> opt) Register an optimizer to themain group
, using the optimizer's provided default priority.void
setDecryptorSupport
(int value) void
setEnableDeobfuscators
(boolean enabled) void
setEnableUnsafeOptimizers
(boolean enabled) setMode
(OptimizerMode mode) void
setPolicyForOptimizerTag
(String tag, boolean allowed) Set the running policy associated to a tag or group of tags.void
Set the optimizer's target.void
boolean
unregisterInstrumenter
(IMasterOptimizerInstrumenter<T> instrumenter) Unregister an instrumenterboolean
Remove an optimizer.
-
Field Details
-
t
default target -
optGrpMap
groups of optimizers; groups 0 and -1 are entry and exit groups, respectively -
optList
list of all optimizers -
grp1NMaxRunCount
protected int grp1NMaxRunCountmaximum run count for the group [1..N] (<0 means no limit) -
instrumenters
instrumenters -
enableUnsafeOptimizers
protected boolean enableUnsafeOptimizersfalse by default; client code must explicitly set to true to allow the execution of unsafe optimizers. -
enableDeobfuscators
protected boolean enableDeobfuscatorsfalse by default; client code must explicitly set to true to allow the execution of deobfuscators. -
decryptorSupport
protected int decryptorSupportdisabled (0) by default; client code must explicitly set to non-zero to allow the execution of decryptors.
-
-
Constructor Details
-
AbstractMasterOptimizer
Create a master optimizer.- Parameters:
t
- the default target, may be nullgrp1NMaxRunCount
- maximum run count for the group [1..N]
-
-
Method Details
-
getTarget
Description copied from interface:IMasterOptimizer
Get the target onto which the optimizations will be performed.- Specified by:
getTarget
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
setTarget
Description copied from interface:IMasterOptimizer
Set the optimizer's target.- Specified by:
setTarget
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
setMode
- Specified by:
setMode
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
- the previous mode
-
getMode
Description copied from interface:IMasterOptimizer
Retrieve the current operating mode for this MO.- Specified by:
getMode
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
- the current operating mode
-
setEnableUnsafeOptimizers
public void setEnableUnsafeOptimizers(boolean enabled) -
isEnableUnsafeOptimizers
public boolean isEnableUnsafeOptimizers() -
setEnableDeobfuscators
public void setEnableDeobfuscators(boolean enabled) -
isEnableDeobfuscators
public boolean isEnableDeobfuscators() -
setDecryptorSupport
public void setDecryptorSupport(int value) -
getDecryptorSupport
public int getDecryptorSupport() -
setPolicyForOptimizerTag
Description copied from interface:IMasterOptimizer
Set the running policy associated to a tag or group of tags. Policy checks when deciding whether an optimizer should be run works as follow: 1) the tag must be allowed, 2) if passed, the tag must not be blocked. By default, all tags are allowed, none are blocked. To reset to that default policy: first invoke this method with("*", true)
, then invoke it with(null, false)
.- Specified by:
setPolicyForOptimizerTag
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Parameters:
tag
- tag name; the special name"*"
means all tags; the special name""
(empty string) or null string means no tagallowed
- true to allow the master optimizer to run the optimizer with the specified tag; false to block it
-
registerOptimizer
Description copied from interface:IMasterOptimizer
Register an optimizer to themain group
, using the optimizer's provided default priority. Refer toIOptimizer#getDefaultPriority()
.- Specified by:
registerOptimizer
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
registerOptimizer
Description copied from interface:IMasterOptimizer
Register an optimizer, using the optimizer's provided default priority. Refer toIOptimizer#getDefaultPriority()
.- Specified by:
registerOptimizer
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
unregisterOptimizer
Description copied from interface:IMasterOptimizer
Remove an optimizer.- Specified by:
unregisterOptimizer
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
unregisterAllOptimizers
public void unregisterAllOptimizers() -
getRegisteredOptimizers
Description copied from interface:IMasterOptimizer
Get a copy of the list of optimizer entries registered with this MO.- Specified by:
getRegisteredOptimizers
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
getRegisteredOptimizers
Description copied from interface:IMasterOptimizer
Get a copy of the lists of optimizer entries registered with this MO and belonging to the provided optimizer group.- Specified by:
getRegisteredOptimizers
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
getOptimizer
- Specified by:
getOptimizer
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
getTotalOptimizationCount
public int getTotalOptimizationCount()- Specified by:
getTotalOptimizationCount
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
getOptimizationCount
public int getOptimizationCount(boolean deobfuscationOnly) - Specified by:
getOptimizationCount
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
-
getOptimizerObject
- Specified by:
getOptimizerObject
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
perform
public int perform()Description copied from interface:IMasterOptimizer
Perform an optimization pass. All the optimizers will be run according to this master's schedule. They may be run multiple times.- Specified by:
perform
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
- the total number of optimizations performed
-
performV1
protected int performV1() -
performV2
protected int performV2(boolean rerunFromStartAfterOpt) -
performMultiple
Description copied from interface:IMasterOptimizer
Run the list of optimizers, in sequence. Each optimizer is run once.- Specified by:
performMultiple
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Parameters:
list
- a list of optimizers- Returns:
- the total number of optimizations performed
-
performSingle
Description copied from interface:IMasterOptimizer
Perform a single optimization, using the provided optimizer (which must have been previously registered).- Specified by:
performSingle
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Parameters:
e
- an optimizer- Returns:
- the total number of optimizations performed
-
preAllOptimizationsCallback
This method might be overridden, but the parent should be called first. -
preOptimizationCallback
This method might be overridden, but the parent should be called first. Note that this method might have a big impact on decompilation performance, so override carefully. -
postAllOptimizationsCallback
This method might be overridden, but the parent should be called first. -
postOptimizationCallback
protected void postOptimizationCallback(T target, OptimizerEntry<T> e, int cnt, long executionTimeMs) This method might be overridden, but the parent should be called first. Note that this method might have a big impact on decompilation performance, so override carefully. -
registerInstrumenter
Description copied from interface:IMasterOptimizer
Register an instrumenter. Instrumenters will be called following their registration order.- Specified by:
registerInstrumenter
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
unregisterInstrumenter
Description copied from interface:IMasterOptimizer
Unregister an instrumenter- Specified by:
unregisterInstrumenter
in interfaceIMasterOptimizer<T extends IOptimizerTarget>
- Returns:
- true if the instrumenter was removed, false otherwise
-
onOptimizerException
This method is called when an optimizer hard-failed and generated an exception.- Parameters:
target
- the target that being optimizedopt
- the failing optimizerex
- the generated exception- Returns:
- if true, the exception will be neutered and the master optimizer will resume the optimizing process; else, the exception will be thrown
-
retrievePerformanceCounters
-
getTargetAddress
-