-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(deobf): split deobfuscation conditions (#2040)
- Loading branch information
Showing
22 changed files
with
482 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
jadx-core/src/main/java/jadx/api/deobf/IDeobfCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jadx.api.deobf; | ||
|
||
import jadx.api.deobf.impl.CombineDeobfConditions; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.core.dex.nodes.FieldNode; | ||
import jadx.core.dex.nodes.MethodNode; | ||
import jadx.core.dex.nodes.PackageNode; | ||
import jadx.core.dex.nodes.RootNode; | ||
|
||
/** | ||
* Utility interface to simplify merging several rename conditions to build {@link IRenameCondition} | ||
* instance with {@link CombineDeobfConditions#combine(IDeobfCondition...)}. | ||
*/ | ||
public interface IDeobfCondition { | ||
|
||
enum Action { | ||
NO_ACTION, | ||
FORCE_RENAME, | ||
FORBID_RENAME, | ||
} | ||
|
||
void init(RootNode root); | ||
|
||
Action check(PackageNode pkg); | ||
|
||
Action check(ClassNode cls); | ||
|
||
Action check(FieldNode fld); | ||
|
||
Action check(MethodNode mth); | ||
} |
73 changes: 73 additions & 0 deletions
73
jadx-core/src/main/java/jadx/api/deobf/impl/CombineDeobfConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package jadx.api.deobf.impl; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import jadx.api.deobf.IDeobfCondition; | ||
import jadx.api.deobf.IRenameCondition; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.core.dex.nodes.FieldNode; | ||
import jadx.core.dex.nodes.MethodNode; | ||
import jadx.core.dex.nodes.PackageNode; | ||
import jadx.core.dex.nodes.RootNode; | ||
|
||
public class CombineDeobfConditions implements IRenameCondition { | ||
|
||
public static IRenameCondition combine(List<IDeobfCondition> conditions) { | ||
return new CombineDeobfConditions(conditions); | ||
} | ||
|
||
public static IRenameCondition combine(IDeobfCondition... conditions) { | ||
return new CombineDeobfConditions(Arrays.asList(conditions)); | ||
} | ||
|
||
private final List<IDeobfCondition> conditions; | ||
|
||
private CombineDeobfConditions(List<IDeobfCondition> conditions) { | ||
if (conditions == null || conditions.isEmpty()) { | ||
throw new IllegalArgumentException("Conditions list can't be empty"); | ||
} | ||
this.conditions = conditions; | ||
} | ||
|
||
private boolean combineFunc(Function<IDeobfCondition, IDeobfCondition.Action> check) { | ||
for (IDeobfCondition c : conditions) { | ||
switch (check.apply(c)) { | ||
case NO_ACTION: | ||
// ignore | ||
break; | ||
case FORCE_RENAME: | ||
return true; | ||
case FORBID_RENAME: | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void init(RootNode root) { | ||
conditions.forEach(c -> c.init(root)); | ||
} | ||
|
||
@Override | ||
public boolean shouldRename(PackageNode pkg) { | ||
return combineFunc(c -> c.check(pkg)); | ||
} | ||
|
||
@Override | ||
public boolean shouldRename(ClassNode cls) { | ||
return combineFunc(c -> c.check(cls)); | ||
} | ||
|
||
@Override | ||
public boolean shouldRename(FieldNode fld) { | ||
return combineFunc(c -> c.check(fld)); | ||
} | ||
|
||
@Override | ||
public boolean shouldRename(MethodNode mth) { | ||
return combineFunc(c -> c.check(mth)); | ||
} | ||
} |
103 changes: 0 additions & 103 deletions
103
jadx-core/src/main/java/jadx/core/deobf/DeobfCondition.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.