Skip to content

Commit

Permalink
fix: improve failsafes, fix dep analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Dec 13, 2024
1 parent 2d818f0 commit 813b1e0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public boolean isDriver() {
}

public File[] getLibs() {
return this.getStringList("libraries", Collections.emptyList())
return this.getStringList("libraries",
// [failsafe] i fucking made this mistake too
this.getStringList("libs", Collections.emptyList())
)
.stream()
.map(File::new)
.distinct()
Expand Down
9 changes: 8 additions & 1 deletion dev.skidfuscator.obfuscator.dependanalysis/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
plugins {
id 'java'
id 'java-library'
id 'application'
// shadowJar
id 'com.github.johnrengelman.shadow' version '7.1.2'
}

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

application {
mainClass = 'dev.skidfuscator.dependanalysis.Main'
}

dependencies {
api project(':modasm')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ private void resolveHierarchy(String className,

// Resolve superclass
if (hierarchy.superName != null && !hierarchy.superName.isEmpty()) {
System.out.println("Resolving superclass of " + className);
Path jarForSuper = hierarchy.isMainJarClass ? mainJar : classToLibraryMap.get(hierarchy.superName);
if (jarForSuper == null && hierarchy.superName != null) {
jarForSuper = classToLibraryMap.get(hierarchy.superName);
}
if (jarForSuper != null) {
String superReason = "needed as superclass of " + className;
System.out.printf("%s -> %s%n", className, hierarchy.superName);
resolveHierarchy(hierarchy.superName, requiredJars, jarForSuper, visited, superReason);
}
}
Expand Down Expand Up @@ -129,6 +131,7 @@ private DependencyResult buildResult(Set<Path> requiredJars) {
* Load the class hierarchy of a given class. If cached, use the cache.
*/
private DependencyClassHierarchy loadDependencyClassHierarchy(String className, Path presumedJar) throws IOException {
System.out.println("Loading hierarchy for " + className);
if (cache.containsKey(className)) {
return cache.get(className);
}
Expand Down Expand Up @@ -164,8 +167,8 @@ private DependencyClassHierarchy loadDependencyClassHierarchy(String className,

DependencyClassHierarchy hierarchy = new DependencyClassHierarchy(
className,
visitor.superName,
visitor.interfaces,
visitor.superName.replace('.', '/'),
Arrays.stream(visitor.interfaces).map(s -> s.replace('.', '/')).toArray(String[]::new),
fromMainJar,
fromMainJar ? null : jarSource
);
Expand All @@ -184,7 +187,7 @@ private void indexLibraries() throws IOException {
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String className = entry.getName().replace('/', '.').replace(".class", "");
String className = entry.getName().replace(".class", "").replace('.', '/');
classToLibraryMap.put(className, jar);
}
}
Expand All @@ -203,7 +206,7 @@ private Set<String> loadClassesFromJar(Path jarPath) throws IOException {
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String className = entry.getName().replace('/', '.').replace(".class", "");
String className = entry.getName().replace(".class", "").replace('.', '/');
classes.add(className);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev.skidfuscator.obfuscator.pureanalysis/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'java'
id 'java-library'
}

group = 'dev.skidfuscator.community'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ protected void _importJvm() {
}
LOGGER.post("✓ Success");
}
LOGGER.log("Finished importing the JVM!");
LOGGER.log("Finished importing the JVM");
LOGGER.log(String.format("Imported %d jvm classes!", jvmClassSource.size()));
}

protected void _importClasspath() {
Expand Down Expand Up @@ -609,7 +610,7 @@ protected void _importClasspath() {
LOGGER.log("✓ Finished importing libs!");
}

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

/*
Expand Down

0 comments on commit 813b1e0

Please sign in to comment.