Skip to content

Commit 813b1e0

Browse files
committed
fix: improve failsafes, fix dep analyzer
1 parent 2d818f0 commit 813b1e0

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

dev.skidfuscator.commons/src/main/java/dev/skidfuscator/config/DefaultSkidConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public boolean isDriver() {
1515
}
1616

1717
public File[] getLibs() {
18-
return this.getStringList("libraries", Collections.emptyList())
18+
return this.getStringList("libraries",
19+
// [failsafe] i fucking made this mistake too
20+
this.getStringList("libs", Collections.emptyList())
21+
)
1922
.stream()
2023
.map(File::new)
2124
.distinct()

dev.skidfuscator.obfuscator.dependanalysis/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
plugins {
2-
id 'java'
2+
id 'java-library'
3+
id 'application'
4+
// shadowJar
5+
id 'com.github.johnrengelman.shadow' version '7.1.2'
36
}
47

58
group = 'dev.skidfuscator.community'
@@ -10,6 +13,10 @@ repositories {
1013
maven { url 'https://jitpack.io' }
1114
}
1215

16+
application {
17+
mainClass = 'dev.skidfuscator.dependanalysis.Main'
18+
}
19+
1320
dependencies {
1421
api project(':modasm')
1522

dev.skidfuscator.obfuscator.dependanalysis/src/main/java/dev/skidfuscator/dependanalysis/DependencyAnalyzer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ private void resolveHierarchy(String className,
8383

8484
// Resolve superclass
8585
if (hierarchy.superName != null && !hierarchy.superName.isEmpty()) {
86+
System.out.println("Resolving superclass of " + className);
8687
Path jarForSuper = hierarchy.isMainJarClass ? mainJar : classToLibraryMap.get(hierarchy.superName);
8788
if (jarForSuper == null && hierarchy.superName != null) {
8889
jarForSuper = classToLibraryMap.get(hierarchy.superName);
8990
}
9091
if (jarForSuper != null) {
9192
String superReason = "needed as superclass of " + className;
93+
System.out.printf("%s -> %s%n", className, hierarchy.superName);
9294
resolveHierarchy(hierarchy.superName, requiredJars, jarForSuper, visited, superReason);
9395
}
9496
}
@@ -129,6 +131,7 @@ private DependencyResult buildResult(Set<Path> requiredJars) {
129131
* Load the class hierarchy of a given class. If cached, use the cache.
130132
*/
131133
private DependencyClassHierarchy loadDependencyClassHierarchy(String className, Path presumedJar) throws IOException {
134+
System.out.println("Loading hierarchy for " + className);
132135
if (cache.containsKey(className)) {
133136
return cache.get(className);
134137
}
@@ -164,8 +167,8 @@ private DependencyClassHierarchy loadDependencyClassHierarchy(String className,
164167

165168
DependencyClassHierarchy hierarchy = new DependencyClassHierarchy(
166169
className,
167-
visitor.superName,
168-
visitor.interfaces,
170+
visitor.superName.replace('.', '/'),
171+
Arrays.stream(visitor.interfaces).map(s -> s.replace('.', '/')).toArray(String[]::new),
169172
fromMainJar,
170173
fromMainJar ? null : jarSource
171174
);
@@ -184,7 +187,7 @@ private void indexLibraries() throws IOException {
184187
while (entries.hasMoreElements()) {
185188
JarEntry entry = entries.nextElement();
186189
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
187-
String className = entry.getName().replace('/', '.').replace(".class", "");
190+
String className = entry.getName().replace(".class", "").replace('.', '/');
188191
classToLibraryMap.put(className, jar);
189192
}
190193
}
@@ -203,7 +206,7 @@ private Set<String> loadClassesFromJar(Path jarPath) throws IOException {
203206
while (entries.hasMoreElements()) {
204207
JarEntry entry = entries.nextElement();
205208
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
206-
String className = entry.getName().replace('/', '.').replace(".class", "");
209+
String className = entry.getName().replace(".class", "").replace('.', '/');
207210
classes.add(className);
208211
}
209212
}

dev.skidfuscator.obfuscator.pureanalysis/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'java'
2+
id 'java-library'
33
}
44

55
group = 'dev.skidfuscator.community'

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ protected void _importJvm() {
528528
}
529529
LOGGER.post("✓ Success");
530530
}
531-
LOGGER.log("Finished importing the JVM!");
531+
LOGGER.log("Finished importing the JVM");
532+
LOGGER.log(String.format("Imported %d jvm classes!", jvmClassSource.size()));
532533
}
533534

534535
protected void _importClasspath() {
@@ -609,7 +610,7 @@ protected void _importClasspath() {
609610
LOGGER.log("✓ Finished importing libs!");
610611
}
611612

612-
if (session.getMappings() == null && config.getLibs().length > 0) {
613+
if (config.getLibs().length > 0) {
613614
final File[] libs = Arrays.stream(config.getLibs())
614615
.filter(e -> e.getAbsolutePath().endsWith(".jar"))
615616
.toArray(File[]::new);
@@ -625,6 +626,9 @@ protected void _importClasspath() {
625626
));
626627
}
627628
LOGGER.log("✓ Finished importing config libs!");
629+
LOGGER.log(String.format("✓ Imported %d config libs!", libs.length));
630+
} else {
631+
LOGGER.warn("! No libraries were imported! If this is normal, ignore this.");
628632
}
629633

630634
/*

0 commit comments

Comments
 (0)