22
33import com .google .common .collect .Streams ;
44import dev .skidfuscator .obf .init .SkidSession ;
5+ import dev .skidfuscator .obf .skidasm .NoNoSkidMethod ;
6+ import dev .skidfuscator .obf .skidasm .v2 .SStorage ;
57import dev .skidfuscator .obf .transform .impl .fixer .ExceptionFixerPass ;
68import dev .skidfuscator .obf .transform .impl .fixer .SwitchFixerPass ;
79import dev .skidfuscator .obf .transform .impl .flow .*;
10+ import dev .skidfuscator .obf .utils .ProgressUtil ;
811import dev .skidfuscator .obf .utils .TimedLogger ;
912import dev .skidfuscator .obf .yggdrasil .caller .CallerType ;
1013import dev .skidfuscator .obf .transform .impl .flow .gen3 .SeedFlowPass ;
1316import dev .skidfuscator .obf .skidasm .SkidInvocation ;
1417import dev .skidfuscator .obf .skidasm .SkidMethod ;
1518import dev .skidfuscator .obf .utils .OpcodeUtil ;
19+ import me .tongfei .progressbar .ProgressBar ;
1620import org .apache .log4j .LogManager ;
1721import org .mapleir .asm .ClassNode ;
1822import org .mapleir .asm .MethodNode ;
2529
2630public class SkidMethodRenderer {
2731 private final Set <MethodNode > methodNodes = new HashSet <>();
32+ private final SStorage storage = new SStorage ();
2833 private final Map <MethodNode , SkidMethod > skidMethodMap = new HashMap <>();
2934 private final TimedLogger logger = new TimedLogger (LogManager .getLogger (this .getClass ()));
3035
@@ -36,52 +41,67 @@ public void render(final SkidSession skidSession) {
3641 .filter (e -> skidSession .getClassSource ().isApplicationClass (e .getName ()))
3742 .collect (Collectors .toList ());
3843
39- for (ClassNode classNode : nodeList ) {
40- methodNodes .addAll (classNode .getMethods ());
41- }
44+ nodeList .parallelStream ().forEach (e -> methodNodes .addAll (e .getMethods ()));
4245 logger .log ("Finished initial load" );
46+ storage .cache (skidSession );
4347 logger .post ("Beginning method load..." );
4448
45- methodNodes .stream ().parallel ().forEach (methodNode -> {
46- final Set <MethodNode > hierarchy = skidSession .getCxt ().getInvocationResolver ()
47- .getHierarchyMethodChain (methodNode .owner , methodNode .getName (), methodNode .getDesc (), true );
49+ try (ProgressBar bar = ProgressUtil .progress (methodNodes .size ())){
50+ methodNodes .stream ().parallel ().forEach (methodNode -> {
51+ final Set <MethodNode > hierarchy = skidSession .getCxt ().getInvocationResolver ()
52+ .getHierarchyMethodChain (methodNode .owner , methodNode .getName (), methodNode .getDesc (), true );
4853
49- hierarchy .add (methodNode );
54+ hierarchy .add (methodNode );
5055
51- if (hierarchy .isEmpty ()) {
52- System .out .println ("/!\\ Method " + methodNode .getDisplayName () + " is empty!" );
53- return ;
54- }
56+ if (hierarchy .isEmpty ()) {
57+ System .out .println ("/!\\ Method " + methodNode .getDisplayName () + " is empty!" );
58+ bar .step ();
59+ return ;
60+ }
61+
62+ SkidMethod method = null ;
5563
56- SkidMethod method = null ;
64+ for (MethodNode node : hierarchy ) {
65+ if (skidMethodMap .containsKey (node )) {
66+ method = skidMethodMap .get (node );
67+ break ;
68+ }
69+ if (node .node .instructions .size () > 6000 ) {
70+ bar .step ();
5771
58- for (MethodNode node : hierarchy ) {
59- if (skidMethodMap .containsKey (node )) {
60- method = skidMethodMap .get (node );
61- break ;
72+ for (MethodNode methodNode1 : hierarchy ) {
73+ skidMethodMap .put (methodNode1 , new NoNoSkidMethod ());
74+ }
75+
76+ return ;
77+ }
6278 }
63- }
6479
65- if (method == null ) {
66- final boolean contains = methodNodes .containsAll (hierarchy );
67- final CallerType type ;
68- if (!contains || OpcodeUtil .isSynthetic (methodNode )) {
69- type = CallerType .LIBRARY ;
70- } else {
71- final boolean entry = methodNode .getName ().equals ("<init>" ) || hierarchy .stream ().anyMatch (e -> skidSession .getEntryPoints ().contains (e ));
80+ if (method == null ) {
81+ final boolean contains = methodNodes .containsAll (hierarchy );
82+ final CallerType type ;
83+ if (!contains || OpcodeUtil .isSynthetic (methodNode )) {
84+ type = CallerType .LIBRARY ;
85+ } else {
86+ final boolean entry = methodNode .getName ().equals ("<init>" ) || hierarchy .stream ().anyMatch (e -> skidSession .getEntryPoints ().contains (e ));
7287
73- type = entry ? CallerType .ENTRY : CallerType .APPLICATION ;
88+ type = entry ? CallerType .ENTRY : CallerType .APPLICATION ;
89+ }
90+
91+ method = new SkidMethod (new HashSet <>(hierarchy ), type , new HashSet <>());
7492 }
7593
76- method = new SkidMethod (new HashSet <>(hierarchy ), type , new HashSet <>());
77- }
94+ skidMethodMap .put (methodNode , method );
95+ bar .step ();
96+ });
97+ }
7898
79- skidMethodMap .put (methodNode , method );
80- });
8199
82100 logger .log ("Finished loading " + skidMethodMap .size () + " methods" );
83101 logger .post ("Beginning method mapping..." );
84- for (MethodNode method : methodNodes ) {
102+
103+ try (ProgressBar bar = ProgressUtil .progress (methodNodes .size ())) {
104+ methodNodes .parallelStream ().forEach (method -> {
85105 final ControlFlowGraph cfg = skidSession .getCxt ().getIRCache ().getFor (method );
86106 cfg .allExprStream ()
87107 .filter (e -> e instanceof InvocationExpr )
@@ -111,11 +131,17 @@ public void render(final SkidSession skidSession) {
111131 }
112132
113133 });
134+ bar .step ();
135+ });
114136 }
115137
116138 logger .log ("Finished mapping " + skidMethodMap .size () + " methods" );
117139 logger .post ("[*] Gen3 bootstrapping... Beginning seeding..." );
118- final List <SkidMethod > skidMethods = skidMethodMap .values ().stream ().distinct ().collect (Collectors .toList ());
140+ final List <SkidMethod > skidMethods = skidMethodMap .values ()
141+ .stream ()
142+ .filter (e -> !(e instanceof NoNoSkidMethod ))
143+ .distinct ()
144+ .collect (Collectors .toList ());
119145
120146 /*skidMethods.forEach(e -> {
121147 System.out.println("(Repository) Added group of size " + e.getMethodNodes().size() + " of name " + e.getModal().getName());
@@ -155,8 +181,8 @@ public void render(final SkidSession skidSession) {
155181 });
156182
157183 // Fix retarded exceptions
158- skidMethods .forEach (e -> e .renderPrivate (skidSession ));
159- skidMethods .forEach (e -> {
184+ skidMethods .parallelStream (). forEach (e -> e .renderPrivate (skidSession ));
185+ skidMethods .parallelStream (). forEach (e -> {
160186 for (SkidGraph methodNode : e .getMethodNodes ()) {
161187 if (methodNode .getNode ().isAbstract ())
162188 continue ;
@@ -175,20 +201,28 @@ public void render(final SkidSession skidSession) {
175201 + "]" );
176202 }
177203
178- skidMethods .forEach (e -> {
179- for (SkidGraph methodNode : e .getMethodNodes ()) {
180- if (methodNode .getNode ().isAbstract ())
181- continue ;
182- final ControlFlowGraph cfg = skidSession .getCxt ().getIRCache ().get (methodNode .getNode ());
183- if (cfg == null )
184- continue ;
185- methodNode .postlinearize (cfg );
186- }
187- });
204+ logger .log ("[*] Linearizing GEN3..." );
205+
206+ try (ProgressBar progressBar = ProgressUtil .progress (skidMethods .size ())){
207+ skidMethods .parallelStream ().forEach (e -> {
208+ e .getMethodNodes ().stream ().parallel ().forEach (methodNode -> {
209+ if (methodNode .getNode ().isAbstract ())
210+ return ;
211+ final ControlFlowGraph cfg = skidSession .getCxt ().getIRCache ().get (methodNode .getNode ());
212+ if (cfg == null )
213+ return ;
214+ methodNode .postlinearize (cfg );
215+ });
216+
217+ progressBar .step ();
218+ });
219+
220+ }
221+
188222
189223
190224
191- skidMethods .forEach (e -> e .renderPublic (skidSession ));
225+ skidMethods .parallelStream (). forEach (e -> e .renderPublic (skidSession ));
192226 logger .log ("[*] Finished Gen3 flow obfuscation" );
193227
194228 }
0 commit comments