Package jadx.core.dex.visitors.regions
Class SwitchOverStringVisitor
java.lang.Object
jadx.core.dex.visitors.AbstractVisitor
jadx.core.dex.visitors.regions.SwitchOverStringVisitor
- All Implemented Interfaces:
IDexTreeVisitor,IRegionIterativeVisitor
A switch(string) java code will be compiled to two switches in class code.
Sometimes, android's d8/r8 will make some further modification.
1st switch could be changed to ifs to reduce size of dex.
2nd switch could be flattened and removed if there are many cases using a same block.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classprivate static enum -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanstore str and num/caseBlock in switchData validate: - case key is hashcode of strValue - case block is str.equals compare - str compare thenBlock is num assign (SWITCH_SWITCH and IF_SWITCH)private static @Nullable IntegerextractConstNumber(SwitchOverStringVisitor.SwitchData switchData, @Nullable InsnNode numInsn) private static @Nullable BlockNodeprivate static @Nullable InvokeNodeprivate static booleanisIfStringEqualsInsn(InsnNode ifInsn) private static booleancreate cases according to part2Region (part1Region if is SINGLE_SWITCH).private static booleanreplace with new switch.private booleanrestoreSwitchOverString(MethodNode mth, IRegion part1Region) private static IntegerunwrapIntKey(Object key) voidvisit(MethodNode mth) Visit methodbooleanvisitRegion(MethodNode mth, IRegion region) If return 'true' traversal will be restarted.Methods inherited from class jadx.core.dex.visitors.AbstractVisitor
getName, init, toString, visit
-
Field Details
-
DEFAULT_NUM_VALUE
-
-
Constructor Details
-
SwitchOverStringVisitor
public SwitchOverStringVisitor()
-
-
Method Details
-
visit
Description copied from interface:IDexTreeVisitorVisit method- Specified by:
visitin interfaceIDexTreeVisitor- Overrides:
visitin classAbstractVisitor- Throws:
JadxException
-
visitRegion
Description copied from interface:IRegionIterativeVisitorIf return 'true' traversal will be restarted.- Specified by:
visitRegionin interfaceIRegionIterativeVisitor
-
restoreSwitchOverString
-
collectPart1RegionCases
store str and num/caseBlock in switchData validate: - case key is hashcode of strValue - case block is str.equals compare - str compare thenBlock is num assign (SWITCH_SWITCH and IF_SWITCH) -
prepareMergedSwitchCases
create cases according to part2Region (part1Region if is SINGLE_SWITCH). replace keys with strings. -
replaceWithMergedSwitch
replace with new switch. remove original code -
extractConstNumber
@Nullable private static @Nullable Integer extractConstNumber(SwitchOverStringVisitor.SwitchData switchData, @Nullable @Nullable InsnNode numInsn) -
unwrapIntKey
-
getStrHashcodeInvokeInsn
-
isIfStringEqualsInsn
-
getOnlyOneInsnBlock
-