|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 FalsePattern |
| 3 | + * All Rights Reserved |
| 4 | + * |
| 5 | + * The above copyright notice, this permission notice and the word "SNEED" |
| 6 | + * shall be included in all copies or substantial portions of the Software. |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | + |
| 22 | +package com.falsepattern.lib.internal.asm; |
| 23 | + |
| 24 | +import com.falsepattern.lib.asm.IClassNodeTransformer; |
| 25 | +import lombok.val; |
| 26 | +import org.objectweb.asm.tree.ClassNode; |
| 27 | +import org.objectweb.asm.tree.LdcInsnNode; |
| 28 | + |
| 29 | +public class ITypeDiscovererTransformer implements IClassNodeTransformer { |
| 30 | + @Override |
| 31 | + public String getName() { |
| 32 | + return "ITypeDiscovererTransformer"; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) { |
| 37 | + return "cpw.mods.fml.common.discovery.ITypeDiscoverer".equals(transformedName); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void transform(ClassNode cn, String transformedName, boolean obfuscated) { |
| 42 | + for (val method: cn.methods) { |
| 43 | + if (!method.name.equals("<clinit>")) { |
| 44 | + continue; |
| 45 | + } |
| 46 | + val instructions = method.instructions; |
| 47 | + for (int i = 0; i < instructions.size(); i++) { |
| 48 | + val insn = instructions.get(i); |
| 49 | + if (insn instanceof LdcInsnNode) { |
| 50 | + val ldc = (LdcInsnNode) insn; |
| 51 | + if (ldc.cst.equals("[^\\s\\$]+(\\$[^\\s]+)?\\.class$")) { |
| 52 | + ldc.cst = "(?!module-info)[^\\s\\$]+(\\$[^\\s]+)?\\.class$"; |
| 53 | + return; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments