mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 06:52:14 +00:00
Allow runtime-decompilation of exported classes using fernflower
This commit is contained in:
1 parent
771746185f
commit
7f3f7bf446
5 files changed
+242
-5
No files matched your search
@@ -26,6 +26,7 @@ package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -53,6 +54,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler.ErrorAction;
|
||||
import org.spongepowered.asm.mixin.transformer.debug.IDecompiler;
|
||||
import org.spongepowered.asm.transformers.TreeTransformer;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
@@ -215,6 +217,8 @@ public class MixinTransformer extends TreeTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
static final File DEBUG_OUTPUT = new File(Constants.DEBUG_OUTPUT_PATH);
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
*/
|
||||
@@ -262,6 +266,8 @@ public class MixinTransformer extends TreeTransformer {
|
||||
*/
|
||||
private boolean errorState = false;
|
||||
|
||||
private final IDecompiler decompiler;
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
@@ -277,8 +283,28 @@ public class MixinTransformer extends TreeTransformer {
|
||||
environment.setActiveTransformer(this);
|
||||
|
||||
TreeInfo.setLock(this.lock);
|
||||
|
||||
this.decompiler = this.initDecompiler(new File(MixinTransformer.DEBUG_OUTPUT, "java"));
|
||||
}
|
||||
|
||||
private IDecompiler initDecompiler(File outputPath) {
|
||||
if (!MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
this.logger.info("Attempting to load Fernflower decompiler");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IDecompiler> clazz =
|
||||
(Class<? extends IDecompiler>)Class.forName("org.spongepowered.asm.mixin.transformer.debug.RuntimeDecompiler");
|
||||
Constructor<? extends IDecompiler> ctor = clazz.getDeclaredConstructor(File.class);
|
||||
return ctor.newInstance(outputPath);
|
||||
} catch (Throwable th) {
|
||||
this.logger.info("Fernflower could not be loaded, exported classes will not be decompiled. {}: {}",
|
||||
th.getClass().getSimpleName(), th.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-load all classes targetted by mixins but not yet applied
|
||||
*/
|
||||
@@ -619,17 +645,22 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
// Export transformed class for debugging purposes
|
||||
if (MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT)) {
|
||||
MixinTransformer.dumpClass(transformedName.replace('.', '/'), bytes);
|
||||
File outputFile = MixinTransformer.dumpClass(transformedName.replace('.', '/'), bytes);
|
||||
if (this.decompiler != null) {
|
||||
this.decompiler.decompile(outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private static void dumpClass(String fileName, byte[] bytes) {
|
||||
private static File dumpClass(String fileName, byte[] bytes) {
|
||||
File outputFile = new File(MixinTransformer.DEBUG_OUTPUT, "class/" + fileName + ".class");
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(new File(Constants.DEBUG_OUTPUT_PATH + "/" + fileName + ".class"), bytes);
|
||||
FileUtils.writeByteArrayToFile(outputFile, bytes);
|
||||
} catch (IOException ex) {
|
||||
// don't care
|
||||
}
|
||||
return outputFile;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -36,7 +36,6 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
@@ -61,7 +60,7 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
private final File report;
|
||||
|
||||
public MixinTransformerModuleInterfaceChecker() {
|
||||
File debugOutputFolder = new File(Constants.DEBUG_OUTPUT_PATH);
|
||||
File debugOutputFolder = new File(MixinTransformer.DEBUG_OUTPUT, "audit");
|
||||
debugOutputFolder.mkdirs();
|
||||
this.csv = new File(debugOutputFolder, "mixin_implementation_report.csv");
|
||||
this.report = new File(debugOutputFolder, "mixin_implementation_report.txt");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered.org <http://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.debug;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Interface to allow the actual decompiler to be loaded on-demand
|
||||
*/
|
||||
public interface IDecompiler {
|
||||
|
||||
/**
|
||||
* Decompile a class file
|
||||
*
|
||||
* @param file .class file to decompile
|
||||
*/
|
||||
public abstract void decompile(File file);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user