Skip to content

Commit

Permalink
Fixed ancient bug when two different classes with same FQN got return…
Browse files Browse the repository at this point in the history
…ed same bytecode

Now the origin classlaoder is always considered
  • Loading branch information
judovana committed Nov 22, 2023
1 parent 9071005 commit e6d2a73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jrd.backend.data.cli.workers;

import org.jrd.backend.core.ClassInfo;
import org.jrd.backend.core.VmDecompilerStatus;
import org.jrd.backend.data.VmInfo;
import org.jrd.backend.data.VmManager;
Expand All @@ -16,7 +17,6 @@
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Decompile {

Expand Down Expand Up @@ -54,13 +54,14 @@ public VmInfo decompile() throws Exception {

for (int i = 3; i < filteredArgs.size(); i++) {
String clazzRegex = filteredArgs.get(i);
List<String> classes = Lib.obtainFilteredClasses(
vmInfo, vmManager, Arrays.asList(Pattern.compile(clazzRegex)), false, Optional.empty(), Optional.ofNullable(classloader)
).stream().map(a -> a.getName()).collect(Collectors.toList());
List<ClassInfo> classes = Lib.obtainFilteredClasses(
vmInfo, vmManager, Arrays.asList(Pattern.compile(clazzRegex)), true, Optional.empty(), Optional.ofNullable(classloader)
);

for (String clazz : classes) {
for (ClassInfo clazz : classes) {
classCount++;
VmDecompilerStatus result = Lib.obtainClass(vmInfo, clazz, vmManager, Optional.ofNullable(classloader));
VmDecompilerStatus result =
Lib.obtainClass(vmInfo, clazz.getName(), vmManager, Optional.ofNullable(clazz.getClassLoader()));
byte[] bytes = Base64.getDecoder().decode(result.getLoadedClassBytes());

if (new File(plugin).exists() && plugin.toLowerCase().endsWith(".json")) {
Expand All @@ -71,10 +72,11 @@ public VmInfo decompile() throws Exception {

if (pwo.getDecompiler() != null) {
String decompilationResult = pluginManager.decompile(
pwo.getDecompiler(), clazz, bytes, pwo.getOptions(), vmInfo, vmManager, Optional.ofNullable(classloader)
pwo.getDecompiler(), clazz.getName(), bytes, pwo.getOptions(), vmInfo, vmManager,
Optional.ofNullable(clazz.getClassLoader())
);

if (!new Shared(isHex, saving).outOrSave(clazz, ".java", decompilationResult)) {
if (!new Shared(isHex, saving).outOrSave(clazz.getName(), ".java", decompilationResult)) {
failCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jrd.backend.data.cli.workers;

import org.jrd.backend.communication.RuntimeCompilerConnector;
import org.jrd.backend.core.ClassInfo;
import org.jrd.backend.core.VmDecompilerStatus;
import org.jrd.backend.data.DependenciesReader;
import org.jrd.backend.data.VmInfo;
Expand Down Expand Up @@ -67,13 +68,14 @@ public VmInfo printBytes(String operation) throws Exception {

for (int i = 2; i < filteredArgs.size(); i++) {
String clazzRegex = filteredArgs.get(i);
List<String> classes = Lib.obtainFilteredClasses(
vmInfo, vmManager, Arrays.asList(Pattern.compile(clazzRegex)), false, Optional.empty(), Optional.ofNullable(classloader)
).stream().map(a -> a.getName()).collect(Collectors.toList());
List<ClassInfo> classes = Lib.obtainFilteredClasses(
vmInfo, vmManager, Arrays.asList(Pattern.compile(clazzRegex)), true, Optional.empty(), Optional.ofNullable(classloader)
);

for (String clazz : classes) {
for (ClassInfo clazz : classes) {
classCount++;
VmDecompilerStatus result = Lib.obtainClass(vmInfo, clazz, vmManager, Optional.ofNullable(classloader));
VmDecompilerStatus result =
Lib.obtainClass(vmInfo, clazz.getName(), vmManager, Optional.ofNullable(clazz.getClassLoader()));
byte[] bytes;
if (operation.equals(BYTES)) {
bytes = Base64.getDecoder().decode(result.getLoadedClassBytes());
Expand All @@ -94,13 +96,13 @@ public RuntimeCompilerConnector.JrdClassesProvider getClassesProvider() {
return args.getClassesProvider();
}
}, new LoadingDialogProvider() {
}).resolve(clazz, result.getLoadedClassBytes());
}).resolve(clazz.getName(), result.getLoadedClassBytes());
bytes = deps.stream().collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8);
} else {
bytes = result.getLoadedClassBytes().getBytes(StandardCharsets.UTF_8);
}

if (!new Shared(isHex, saving).outOrSave(clazz, ".class", bytes, operation.equals(BYTES))) {
if (!new Shared(isHex, saving).outOrSave(clazz.getName(), ".class", bytes, operation.equals(BYTES))) {
failCount++;
}
}
Expand Down

0 comments on commit e6d2a73

Please sign in to comment.