Skip to content

Commit a1f3420

Browse files
committed
fix(obf): fixed exclusions properly
1 parent 40dd99b commit a1f3420

6 files changed

Lines changed: 64 additions & 11 deletions

File tree

dev.skidfuscator.client.standalone/src/main/java/dev/skidfuscator/obfuscator/command/ObfuscateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public Integer call() {
127127
" │ " + topMemory + " │",
128128
" └───────────────────────────────────────────┘",
129129
"",
130-
" Author: Ghast Version: 2.0.5 Today: "
130+
" Author: Ghast Version: 2.0.6 Today: "
131131
+ DateFormat.getDateTimeInstance().format(new Date(Instant.now().toEpochMilli())),
132132
""
133133
};

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/Skidfuscator.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ public void run() {
186186
.build();
187187
LOGGER.log("Finished resolving predicate analysis!");
188188

189+
_importExempt();
189190
_importClasspath();
190191
_importJvm();
191-
_importExempt();
192192

193193
if (!session.isFuckIt()) {
194194
_verify();
@@ -292,6 +292,7 @@ public void run() {
292292
LOGGER.log("Finished dumping classes...");
293293
EventBus.end();
294294

295+
_cleanup();
295296
_dump();
296297

297298
SkidProgressBar.RENDER_THREAD.shutdown();
@@ -362,6 +363,7 @@ protected void _importExempt() {
362363
progressBar.tick();
363364
}
364365
}
366+
LOGGER.log("Imported: \n " + exemptAnalysis.toString());
365367
} catch (IOException ex) {
366368
/*
367369
* If there's any error, it can pose significant issues with
@@ -522,7 +524,7 @@ protected void _loadTransformer() {
522524

523525
public List<Transformer> getTransformers() {
524526
return Arrays.asList(
525-
/*new StringTransformer(this),
527+
new StringTransformer(this),
526528
//new NegationTransformer(this),
527529
//new FlatteningFlowTransformer(this),
528530
new NumberTransformer(this),
@@ -531,7 +533,7 @@ public List<Transformer> getTransformers() {
531533
new BasicConditionTransformer(this),
532534
new BasicExceptionTransformer(this),
533535
new BasicRangeTransformer(this),
534-
new AhegaoTransformer(this)*/
536+
new AhegaoTransformer(this)
535537
//new SimpleOutlinerTransformer()
536538
//
537539
);
@@ -561,6 +563,13 @@ private void _verify() {
561563
LOGGER.log("Finished verification!");
562564
}
563565

566+
protected void _cleanup() {
567+
this.hierarchy = null;
568+
this.irFactory = null;
569+
this.predicateAnalysis = null;
570+
System.gc();
571+
}
572+
564573
protected void _dump() {
565574
LOGGER.post("Dumping jar...");
566575
try {

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/exempt/ExclusionHelper.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,23 @@ public boolean test(ClassNode var) {
7878
.match("private", var.isPrivate())
7979
.check();
8080

81+
assert initialMatch : "Failed initial match: " + parsed + " got:" + var;
82+
assert !var.getName().contains(".") : "Got weird name: " + var.getName();
8183

82-
return initialMatch
84+
final boolean ret = initialMatch
8385
&& (regex.matcher(var.getName()).find() || parsed.equals(var.getName()));
86+
87+
if (var.getName().equals("jda")) {
88+
System.out.println("JDA! " + var.getName() + " --> " + ret);
89+
}
90+
91+
assert var.getName().contains("jda") == ret : "name: " + var.getName() + " parser: " + parsed;
92+
return ret;
93+
}
94+
95+
@Override
96+
public String toString() {
97+
return regex.pattern();
8498
}
8599
});
86100

@@ -109,11 +123,11 @@ public boolean test(MethodNode var) {
109123
return false;
110124
}
111125

112-
if (descRegex != null && !descRegex.matcher(var.getDesc()).matches()) {
126+
if (descRegex != null && !descRegex.matcher(var.getDesc()).lookingAt()) {
113127
return false;
114128
}
115129

116-
return regexMethod.matcher(var.getName()).find() || parsed.equals(var.getName());
130+
return regexMethod.matcher(var.getName()).lookingAt() || parsed.equals(var.getName());
117131
//&& regexClazz.matcher(var.owner.getDisplayName()).matches();
118132
}
119133

@@ -144,8 +158,8 @@ public boolean test(FieldNode var) {
144158
.check();
145159

146160
return initialMatch
147-
&& regexField.matcher(var.getDisplayName()).matches()
148-
&& regexClazz.matcher(var.owner.getDisplayName()).matches();
161+
&& regexField.matcher(var.getDisplayName()).lookingAt()
162+
&& regexClazz.matcher(var.owner.getDisplayName()).lookingAt();
149163
}
150164
});
151165
break;

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/hierarchy/SkidHierarchy.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public void accept(ClassNode node) {
8383
}
8484
}
8585

86-
node.getMethods().stream().sorted(new Comparator<MethodNode>() {
86+
node.getMethods()
87+
.stream()
88+
.filter(e -> !skidfuscator.getExemptAnalysis().isExempt(e))
89+
.sorted(new Comparator<MethodNode>() {
8790
@Override
8891
public int compare(MethodNode o1, MethodNode o2) {
8992
final Parameter parameter1 = new Parameter(o1.getDesc());
@@ -187,14 +190,16 @@ public void cache() {
187190
this.annotations = new HashMap<>();
188191

189192
try (ProgressWrapper progressBar = ProgressUtil.progress(skidfuscator.getClassSource().size())){
190-
nodes = skidfuscator.getClassSource()
193+
nodes = skidfuscator
194+
.getClassSource()
191195
.getClassTree()
192196
.vertices()
193197
.stream()
194198
.filter(e -> {
195199
progressBar.tick();
196200
return skidfuscator.getClassSource().isApplicationClass(e.getName());
197201
})
202+
.filter(e -> !skidfuscator.getExemptAnalysis().isExempt(e))
198203
.collect(Collectors.toList());
199204
}
200205

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.skidfuscator.test.exclusion;
2+
3+
import dev.skidfuscator.obfuscator.exempt.ExemptAnalysis;
4+
import dev.skidfuscator.obfuscator.exempt.SimpleExemptAnalysis;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class StringExclusionTest {
10+
private ExemptAnalysis analysis;
11+
12+
@BeforeEach
13+
public void init() {
14+
this.analysis = new SimpleExemptAnalysis();
15+
}
16+
17+
@Test
18+
public void testJda() {
19+
final String jdaExempt = "^jda\\/";
20+
final String[] jdaClasses = {};
21+
}
22+
23+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ distributionPath=wrapper/dists
33
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
gradle.publish.key=MWBasmHJWf7vbXU6rKeT07cRfXIshv5C
7+
gradle.publish.secret=1nhGe7kmqKJfxmo1PZjjpCSo2ALAYF2X

0 commit comments

Comments
 (0)