generated from kappa-maintainer/1.12.2-FG6-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60ffe64
commit f277a12
Showing
10 changed files
with
178 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/cleanroommc/transformer/ClassSnifferTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.cleanroommc.transformer; | ||
|
||
import com.cleanroommc.Fugue; | ||
import javassist.CannotCompileException; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.expr.ExprEditor; | ||
import javassist.expr.MethodCall; | ||
import top.outlands.foundation.IExplicitTransformer; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
public class ClassSnifferTransformer implements IExplicitTransformer { | ||
@Override | ||
public byte[] transform(byte[] bytes) { | ||
try { | ||
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes)); | ||
cc.instrument(new ExprEditor(){ | ||
@Override | ||
public void edit(MethodCall call) throws CannotCompileException { | ||
if (call.getClassName().equals("org.apache.logging.log4j.Logger") && call.getMethodName().equals("warn")) { | ||
call.replace("{}"); | ||
} | ||
} | ||
}); | ||
bytes = cc.toBytecode(); | ||
} catch (Throwable t) { | ||
Fugue.LOGGER.error(t); | ||
} | ||
return bytes; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/cleanroommc/transformer/universal/FinalStripperTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.cleanroommc.transformer.universal; | ||
|
||
import com.cleanroommc.Fugue; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import top.outlands.foundation.IExplicitTransformer; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
public class FinalStripperTransformer implements IExplicitTransformer { | ||
private final Map<String, String> targets; | ||
public FinalStripperTransformer(Map<String, String> targets) { | ||
this.targets = targets; | ||
} | ||
@Override | ||
public byte[] transform(byte[] bytes) { | ||
try { | ||
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes)); | ||
String[] fields = targets.get(cc.getName()).split("\\|"); | ||
Arrays.stream(cc.getFields()).filter(ctField -> | ||
Arrays.stream(fields).anyMatch(f -> | ||
ctField.getName().equals(f) | ||
) | ||
).forEach(ctField2 -> | ||
{ | ||
ctField2.setModifiers(ctField2.getModifiers() & ~Modifier.FINAL); | ||
Fugue.LOGGER.debug("Stripping final modifier of {} from {}", ctField2.getName(), ctField2.getDeclaringClass().getName()); | ||
}); | ||
bytes = cc.toBytecode(); | ||
} catch (Throwable t) { | ||
Fugue.LOGGER.error(t); | ||
} | ||
return bytes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.