2
2
3
3
import com .google .common .collect .Streams ;
4
4
import dev .skidfuscator .obf .init .SkidSession ;
5
+ import dev .skidfuscator .obf .skidasm .NoNoSkidMethod ;
6
+ import dev .skidfuscator .obf .skidasm .v2 .SStorage ;
5
7
import dev .skidfuscator .obf .transform .impl .fixer .ExceptionFixerPass ;
6
8
import dev .skidfuscator .obf .transform .impl .fixer .SwitchFixerPass ;
7
9
import dev .skidfuscator .obf .transform .impl .flow .*;
10
+ import dev .skidfuscator .obf .utils .ProgressUtil ;
8
11
import dev .skidfuscator .obf .utils .TimedLogger ;
9
12
import dev .skidfuscator .obf .yggdrasil .caller .CallerType ;
10
13
import dev .skidfuscator .obf .transform .impl .flow .gen3 .SeedFlowPass ;
13
16
import dev .skidfuscator .obf .skidasm .SkidInvocation ;
14
17
import dev .skidfuscator .obf .skidasm .SkidMethod ;
15
18
import dev .skidfuscator .obf .utils .OpcodeUtil ;
19
+ import me .tongfei .progressbar .ProgressBar ;
16
20
import org .apache .log4j .LogManager ;
17
21
import org .mapleir .asm .ClassNode ;
18
22
import org .mapleir .asm .MethodNode ;
25
29
26
30
public class SkidMethodRenderer {
27
31
private final Set <MethodNode > methodNodes = new HashSet <>();
32
+ private final SStorage storage = new SStorage ();
28
33
private final Map <MethodNode , SkidMethod > skidMethodMap = new HashMap <>();
29
34
private final TimedLogger logger = new TimedLogger (LogManager .getLogger (this .getClass ()));
30
35
@@ -36,52 +41,67 @@ public void render(final SkidSession skidSession) {
36
41
.filter (e -> skidSession .getClassSource ().isApplicationClass (e .getName ()))
37
42
.collect (Collectors .toList ());
38
43
39
- for (ClassNode classNode : nodeList ) {
40
- methodNodes .addAll (classNode .getMethods ());
41
- }
44
+ nodeList .parallelStream ().forEach (e -> methodNodes .addAll (e .getMethods ()));
42
45
logger .log ("Finished initial load" );
46
+ storage .cache (skidSession );
43
47
logger .post ("Beginning method load..." );
44
48
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 );
48
53
49
- hierarchy .add (methodNode );
54
+ hierarchy .add (methodNode );
50
55
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 ;
55
63
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 ();
57
71
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
+ }
62
78
}
63
- }
64
79
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 ));
72
87
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 <>());
74
92
}
75
93
76
- method = new SkidMethod (new HashSet <>(hierarchy ), type , new HashSet <>());
77
- }
94
+ skidMethodMap .put (methodNode , method );
95
+ bar .step ();
96
+ });
97
+ }
78
98
79
- skidMethodMap .put (methodNode , method );
80
- });
81
99
82
100
logger .log ("Finished loading " + skidMethodMap .size () + " methods" );
83
101
logger .post ("Beginning method mapping..." );
84
- for (MethodNode method : methodNodes ) {
102
+
103
+ try (ProgressBar bar = ProgressUtil .progress (methodNodes .size ())) {
104
+ methodNodes .parallelStream ().forEach (method -> {
85
105
final ControlFlowGraph cfg = skidSession .getCxt ().getIRCache ().getFor (method );
86
106
cfg .allExprStream ()
87
107
.filter (e -> e instanceof InvocationExpr )
@@ -111,11 +131,17 @@ public void render(final SkidSession skidSession) {
111
131
}
112
132
113
133
});
134
+ bar .step ();
135
+ });
114
136
}
115
137
116
138
logger .log ("Finished mapping " + skidMethodMap .size () + " methods" );
117
139
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 ());
119
145
120
146
/*skidMethods.forEach(e -> {
121
147
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) {
155
181
});
156
182
157
183
// 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 -> {
160
186
for (SkidGraph methodNode : e .getMethodNodes ()) {
161
187
if (methodNode .getNode ().isAbstract ())
162
188
continue ;
@@ -175,20 +201,28 @@ public void render(final SkidSession skidSession) {
175
201
+ "]" );
176
202
}
177
203
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
+
188
222
189
223
190
224
191
- skidMethods .forEach (e -> e .renderPublic (skidSession ));
225
+ skidMethods .parallelStream (). forEach (e -> e .renderPublic (skidSession ));
192
226
logger .log ("[*] Finished Gen3 flow obfuscation" );
193
227
194
228
}
0 commit comments