Skip to content

Commit 456f240

Browse files
committed
feat: add support for json mapping pull + bugfix
1 parent 1fb9e5b commit 456f240

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class Skidfuscator {
101101

102102
private final SkidfuscatorSession session;
103103

104+
protected Set<CommonDependency> installedDependencies = new HashSet<>();
104105
protected SkidApplicationClassSource classSource;
105106
private LibraryClassSource jvmClassSource;
106107
protected JarContents jarContents;
@@ -714,8 +715,16 @@ private void _verify() {
714715
} catch (Exception ex) {
715716
final List<String> missingClasses = classSource.getClassTree().getMissingClasses();
716717

717-
LOGGER.warn("Attempting to auto-resolve missing classes...");
718-
final Set<CommonDependency> commonDependencies = Arrays.stream(CommonDependency.values()).filter(f -> f.getMatcher().test(missingClasses)).collect(Collectors.toSet());
718+
LOGGER.warn(
719+
"Attempting to auto-resolve missing classes..."
720+
+ "\n"
721+
+ "List of missing classes:\n"
722+
+ missingClasses.stream().map(f -> " --> " + f + "\n").collect(Collectors.joining())
723+
);
724+
final Set<CommonDependency> commonDependencies = Arrays.stream(CommonDependency.values())
725+
.filter(f -> f.getMatcher().test(missingClasses))
726+
.filter(f -> !installedDependencies.contains(f))
727+
.collect(Collectors.toSet());
719728

720729
if (commonDependencies.isEmpty()) {
721730
LOGGER.warn("\n" +
@@ -751,6 +760,7 @@ private void _verify() {
751760
"Resolved %d common dependencies... retrying verification...\n",
752761
commonDependencies.size()
753762
));
763+
installedDependencies.addAll(commonDependencies);
754764
_verify();
755765
return;
756766
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/dependency/DependencyDownloader.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ public void download(final CommonDependency dependency) {
2929
return;
3030
}
3131

32-
Path zipFilePath = mappingsDir.resolve(dependency.name().toLowerCase() + "/download.zip");
33-
Files.createDirectories(zipFilePath.getParent());
32+
Path resolvedMappingPath = mappingsDir.resolve(dependency.name().toLowerCase() + "/download.mappings");
33+
Files.createDirectories(resolvedMappingPath.getParent());
3434

3535
// Download the zip file
3636
Skidfuscator.LOGGER.style(String.format("Downloading dependency %s from %s\n", dependency.name(), url));
3737
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
38-
FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath.toFile())) {
38+
FileOutputStream fileOutputStream = new FileOutputStream(resolvedMappingPath.toFile())) {
3939
byte[] dataBuffer = new byte[1024];
4040
int bytesRead;
4141
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
4242
fileOutputStream.write(dataBuffer, 0, bytesRead);
4343
}
4444
}
4545

46-
if (!Files.exists(zipFilePath)) {
47-
throw new IOException("Failed to download the file: " + zipFilePath);
46+
if (!Files.exists(resolvedMappingPath)) {
47+
throw new IOException("Failed to download the file: " + resolvedMappingPath);
4848
}
4949

50-
Skidfuscator.LOGGER.style(String.format("Downloaded dependency %s to %s\n", dependency.name(), zipFilePath));
50+
Skidfuscator.LOGGER.style(String.format("Downloaded dependency %s to %s\n", dependency.name(), resolvedMappingPath));
5151

5252
if (url.endsWith(".jar")) {
5353
throw new IllegalArgumentException("Invalid dependency type");
5454
} else if (url.endsWith(".zip")) {
55-
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFilePath))) {
55+
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(resolvedMappingPath))) {
5656
ZipEntry entry;
5757
while ((entry = zipInputStream.getNextEntry()) != null) {
5858
Path filePath = mappingsDir.resolve(entry.getName());
@@ -71,10 +71,15 @@ public void download(final CommonDependency dependency) {
7171
zipInputStream.closeEntry();
7272
}
7373
}
74-
Files.delete(zipFilePath);
7574
Skidfuscator.LOGGER.style(String.format("Extracted dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
76-
} else {
75+
} else if (url.endsWith(".json")) {
76+
// Copy the file to the mappings directory
77+
Files.copy(resolvedMappingPath, mappingsDir.resolve(dependency.name().toLowerCase() + ".json"));
78+
Skidfuscator.LOGGER.style(String.format("Extracted JSON particular dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
79+
}
80+
else {
7781
Skidfuscator.LOGGER.style(String.format("Unsupported file type for %s\n", url));
7882
}
83+
Files.delete(resolvedMappingPath);
7984
}
8085
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,6 @@ private void setupInvoke() {
337337
.filter(e -> e instanceof Invokable)
338338
.map(e -> (Invocation) e)
339339
.forEach(invocation -> {
340-
341-
if (invocation.getName().equals("handle")) {
342-
System.out.println("Invoking " + invocation.getOwner() + "#"
343-
+ invocation.getName() + invocation.getDesc());
344-
}
345-
346340
final ClassMethodHash target;
347341

348342
if (invocation instanceof DynamicInvocationExpr) {

0 commit comments

Comments
 (0)