Skip to content

Commit

Permalink
Fix leak and misc stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoPangxie732 committed Aug 21, 2024
1 parent 1d2217e commit 562573b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ public static Stream<Path> iterateFiles(@NotNull Path path) {
DirectoryStream<Path> ds = Files.newDirectoryStream(path);
return StreamSupport.stream(ds.spliterator(), true)
.mapMulti((Path p, Consumer<Path> cons) -> {
if (Files.isDirectory(p)) iterateFiles(p).forEach(cons);
else cons.accept(p);
if (Files.isDirectory(p)) try (var s = iterateFiles(p)) {
s.sequential().forEach(cons);
} else cons.accept(p);
}).onClose(LambdaUtil.unwrap(ds::close));
} catch (IOException e) {
LOGGER.fatal("Error iterating files", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
import java.util.zip.InflaterInputStream;

public class IOUtil {
private static final Class<?> ZIP_FILESYSTEM;
private static final Class<?> ZIP_PATH;
private static final Class<?> ENTRY_INPUT_STREAM;

static {
try {
ZIP_FILESYSTEM = Class.forName("jdk.nio.zipfs.ZipFileSystem");
ZIP_PATH = Class.forName("jdk.nio.zipfs.ZipPath");
ENTRY_INPUT_STREAM = Class.forName("jdk.nio.zipfs.ZipFileSystem$EntryInputStream");
} catch (ClassNotFoundException e) {
throw Utils.wrapInRuntime(e);
}
}

public static byte[] readAllBytes(@NotNull Path file) throws IOException {
if (ZIP_FILESYSTEM != file.getFileSystem().getClass()) throw new IllegalArgumentException(); // Ensure the filesystem is zipfs
if (ZIP_PATH != file.getClass()) throw new IllegalArgumentException(); // Ensure this is zipfs path
try (InputStream is = Files.newInputStream(file)) {
byte[] bytes = new byte[is.available()];
if (is instanceof InflaterInputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ public NamespacedMapping(String[] namespaces, String[] names, int nameStart, Com
if (namespaces.length != (names.length - Objects.checkIndex(nameStart, names.length)))
throw new IllegalArgumentException();
for (int i = 0; i < namespaces.length; i++) {
var n = i + nameStart;
this.names.put(Objects.requireNonNull(namespaces[i]), n >= names.length ? names[names.length - 1] : names[i + nameStart]);
// var n = i + nameStart;// FIXME: Maybe useless?
// this.names.put(Objects.requireNonNull(namespaces[i]), n >= names.length ? names[names.length - 1] : names[n]);
this.names.put(Objects.requireNonNull(namespaces[i]), names[i + nameStart]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.jetbrains.annotations.NotNull;

/**
* Lightweight remapper for descriptors in place of the general heavyweight remappers.
* Lightweight remapper for descriptors in place of the general heavyweight {@link cn.maxpixel.mcdecompiler.mapping.remapper.MappingRemapper}s.
*/
public class DescriptorRemapper {// TODO
private final Object2ObjectOpenHashMap<String, ? extends ClassMapping<? extends Mapping>> mappingByUnm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.jetbrains.annotations.Nullable;

public final class MappingUtil {
private MappingUtil() {
throw new AssertionError("No instances");
}

public static <T extends Mapping> void checkOwner(Owned<T> owned, ClassMapping<T> owner) {
if (owned.owner != owner) throw new IllegalArgumentException("Owner mismatch");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ public Remapper(MethodVisitor methodVisitor) {

@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
// We only remap name here. Other things are remapped by ASM's ClassRemapper
String newName = name;
// Only remap name here. Other things are remapped by ASM's ClassRemapper
if (bootstrapMethodHandle.getOwner().equals("java/lang/invoke/LambdaMetafactory")) {
Type interfaceMethodType = (Type) bootstrapMethodArguments[0];
newName = mappingRemapper.mapMethodName(Type.getReturnType(descriptor).getInternalName(), name, interfaceMethodType.getDescriptor());
name = mappingRemapper.mapMethodName(Type.getReturnType(descriptor).getInternalName(), name, interfaceMethodType.getDescriptor());
}
super.visitInvokeDynamicInsn(newName, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void visitInnerClass(String name, String outerName, String innerName, int

@Override
public MethodVisitor visitMethod(int access, String name, @Subst("(Ljava/lang/String;I)V") String descriptor, String signature, String[] exceptions) {
if(toProcess != null && "<init>".equals(name) && descriptor.startsWith(toProcess)) {
if (toProcess != null && "<init>".equals(name) && descriptor.startsWith(toProcess)) {
return new MethodVisitor(Deobfuscator.ASM_VERSION, super.visitMethod(access, name, descriptor, signature, exceptions)) {
private final int params = DescriptorUtil.getArgumentCount(descriptor);
private boolean processVisible;
Expand Down

0 comments on commit 562573b

Please sign in to comment.