|
| 1 | +package dev.skidfuscator.obf.transform.impl.kappa; |
| 2 | + |
| 3 | +import dev.skidfuscator.obf.init.SkidSession; |
| 4 | +import dev.skidfuscator.obf.transform.impl.ProjectPass; |
| 5 | +import dev.skidfuscator.obf.utils.RandomUtil; |
| 6 | +import org.mapleir.asm.ClassNode; |
| 7 | +import org.mapleir.asm.FieldNode; |
| 8 | +import org.mapleir.asm.MethodNode; |
| 9 | +import org.mapleir.ir.TypeUtils; |
| 10 | +import org.mapleir.ir.cfg.BasicBlock; |
| 11 | +import org.mapleir.ir.cfg.ControlFlowGraph; |
| 12 | +import org.mapleir.ir.code.Expr; |
| 13 | +import org.mapleir.ir.code.Stmt; |
| 14 | +import org.mapleir.ir.code.expr.ConstantExpr; |
| 15 | +import org.mapleir.ir.code.expr.FieldLoadExpr; |
| 16 | +import org.mapleir.ir.code.expr.NewArrayExpr; |
| 17 | +import org.mapleir.ir.code.stmt.ArrayStoreStmt; |
| 18 | +import org.mapleir.ir.code.stmt.FieldStoreStmt; |
| 19 | +import org.mapleir.ir.code.stmt.PopStmt; |
| 20 | +import org.mapleir.ir.locals.Local; |
| 21 | +import org.objectweb.asm.Opcodes; |
| 22 | +import org.objectweb.asm.Type; |
| 23 | + |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Random; |
| 27 | +import java.util.Stack; |
| 28 | + |
| 29 | +/** |
| 30 | + * Do not question this. This is a stupid idea; Stupid ideas are bets. Bets are funny. |
| 31 | + * End of discussion. |
| 32 | + */ |
| 33 | +public class AhegaoPass implements ProjectPass { |
| 34 | + |
| 35 | + @Override |
| 36 | + public void pass(SkidSession session) { |
| 37 | + for (ClassNode classNode : session.getClassSource().iterate()) { |
| 38 | + final org.objectweb.asm.tree.FieldNode fieldNode = new org.objectweb.asm.tree.FieldNode( |
| 39 | + Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, |
| 40 | + "nothing_to_see_here", |
| 41 | + "[Ljava/lang/String;", |
| 42 | + null, |
| 43 | + null |
| 44 | + ); |
| 45 | + final FieldNode mapleNode = new FieldNode(fieldNode, classNode); |
| 46 | + classNode.getFields().add(mapleNode); |
| 47 | + classNode.node.fields.add(fieldNode); |
| 48 | + |
| 49 | + MethodNode clinit = classNode.getMethods().stream() |
| 50 | + .filter(e -> e.getName().equals("<clinit>") && e.getDesc().equals("()V")) |
| 51 | + .findFirst() |
| 52 | + .orElse(null); |
| 53 | + |
| 54 | + if (clinit == null) { |
| 55 | + final org.objectweb.asm.tree.MethodNode asmclinit = new org.objectweb.asm.tree.MethodNode( |
| 56 | + Opcodes.ACC_STATIC, |
| 57 | + "<clinit>", |
| 58 | + "()V", |
| 59 | + null, |
| 60 | + new String[0] |
| 61 | + ); |
| 62 | + |
| 63 | + clinit = new MethodNode(asmclinit, classNode); |
| 64 | + |
| 65 | + classNode.getMethods().add(clinit); |
| 66 | + classNode.node.methods.add(asmclinit); |
| 67 | + } |
| 68 | + |
| 69 | + final String[] array = ahegaos.get(RandomUtil.nextInt(ahegaos.size())); |
| 70 | + |
| 71 | + final NewArrayExpr array_expr = new NewArrayExpr( |
| 72 | + new Expr[] { new ConstantExpr(array.length, Type.INT_TYPE)}, |
| 73 | + Type.getType(String[].class) |
| 74 | + ); |
| 75 | + |
| 76 | + |
| 77 | + final ControlFlowGraph cfg = session.getCxt().getIRCache().getFor(clinit); |
| 78 | + |
| 79 | + final Stack<Stmt> stack = new Stack<>(); |
| 80 | + |
| 81 | + stack.add(new FieldStoreStmt( |
| 82 | + null, |
| 83 | + array_expr, |
| 84 | + mapleNode.getOwner(), |
| 85 | + mapleNode.getName(), |
| 86 | + mapleNode.getDesc(), |
| 87 | + true |
| 88 | + )); |
| 89 | + |
| 90 | + for (int i = 0; i < array.length; i++) { |
| 91 | + stack.add(new ArrayStoreStmt( |
| 92 | + new FieldLoadExpr( |
| 93 | + null, |
| 94 | + mapleNode.getOwner(), |
| 95 | + mapleNode.getName(), |
| 96 | + mapleNode.getDesc(), |
| 97 | + true |
| 98 | + ), |
| 99 | + new ConstantExpr(i, Type.INT_TYPE), |
| 100 | + new ConstantExpr(array[i]), |
| 101 | + TypeUtils.ArrayType.OBJECT |
| 102 | + )); |
| 103 | + } |
| 104 | + |
| 105 | + Stmt stmt = stack.pop(); |
| 106 | + |
| 107 | + if (cfg.getEntries().isEmpty()) { |
| 108 | + cfg.addVertex(new BasicBlock(cfg)); |
| 109 | + } |
| 110 | + |
| 111 | + while (stmt != null) { |
| 112 | + cfg.getEntries().iterator().next().add(0, stmt); |
| 113 | + |
| 114 | + if (stack.isEmpty()) |
| 115 | + break; |
| 116 | + stmt = stack.pop(); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public String getName() { |
| 123 | + return "Ahegao Pass"; |
| 124 | + } |
| 125 | + |
| 126 | + private static final List<String[]> ahegaos = Arrays.asList( |
| 127 | + new String[] { |
| 128 | + "⠄⠄⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄", |
| 129 | + "⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄", |
| 130 | + "⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄", |
| 131 | + "⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄", |
| 132 | + "⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰", |
| 133 | + "⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤", |
| 134 | + "⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗", |
| 135 | + "⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄", |
| 136 | + "⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄", |
| 137 | + "⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄", |
| 138 | + "⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄", |
| 139 | + "⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄", |
| 140 | + "⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄", |
| 141 | + "⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴", |
| 142 | + "⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿" |
| 143 | + }, |
| 144 | + new String[] { |
| 145 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣀⣠⣤⣶⣶⣶⣤⣄⣀⣀⠄⠄⠄⠄⠄", |
| 146 | + "⠄⠄⠄⠄⠄⠄⠄⠄⣀⣤⣤⣶⣿⣿⣿⣿⣿⣿⣿⣟⢿⣿⣿⣿⣶⣤⡀⠄", |
| 147 | + "⠄⠄⠄⠄⠄⠄⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣜⠿⠿⣿⣿⣧⢓", |
| 148 | + "⠄⠄⠄⠄⠄⡠⢛⣿⣿⣿⡟⣿⣿⣽⣋⠻⢻⣿⣿⣿⣿⡻⣧⡠⣭⣭⣿⡧", |
| 149 | + "⠄⠄⠄⠄⠄⢠⣿⡟⣿⢻⠃⣻⣨⣻⠿⡀⣝⡿⣿⣿⣷⣜⣜⢿⣝⡿⡻⢔", |
| 150 | + "⠄⠄⠄⠄⠄⢸⡟⣷⢿⢈⣚⣓⡡⣻⣿⣶⣬⣛⣓⣉⡻⢿⣎⠢⠻⣴⡾⠫", |
| 151 | + "⠄⠄⠄⠄⠄⢸⠃⢹⡼⢸⣿⣿⣿⣦⣹⣿⣿⣿⠿⠿⠿⠷⣎⡼⠆⣿⠵⣫", |
| 152 | + "⠄⠄⠄⠄⠄⠈⠄⠸⡟⡜⣩⡄⠄⣿⣿⣿⣿⣶⢀⢀⣿⣷⣿⣿⡐⡇⡄⣿", |
| 153 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠁⢶⢻⣧⣖⣿⣿⣿⣿⣿⣿⣿⣿⡏⣿⣇⡟⣇⣷⣿", |
| 154 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣆⣤⣽⣿⡿⠿⠿⣿⣿⣦⣴⡇⣿⢨⣾⣿⢹⢸", |
| 155 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⠊⡛⢿⣿⣿⣿⣿⡿⣫⢱⢺⡇⡏⣿⣿⣸⡼", |
| 156 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⡿⠄⣿⣷⣾⡍⣭⣶⣿⣿⡌⣼⣹⢱⠹⣿⣇⣧", |
| 157 | + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⣼⠁⣤⣭⣭⡌⢁⣼⣿⣿⣿⢹⡇⣭⣤⣶⣤⡝⡼", |
| 158 | + "⠄⣀⠤⡀⠄⠄⠄⠄⠄⡏⣈⡻⡿⠃⢀⣾⣿⣿⣿⡿⡼⠁⣿⣿⣿⡿⢷⢸", |
| 159 | + "⢰⣷⡧⡢⠄⠄⠄⠄⠠⢠⡛⠿⠄⠠⠬⠿⣿⠭⠭⢱⣇⣀⣭⡅⠶⣾⣷⣶", |
| 160 | + "⠈⢿⣿⣧⠄⠄⠄⠄⢀⡛⠿⠄⠄⠄⠄⢠⠃⠄⠄⡜⠄⠄⣤⢀⣶⣮⡍⣴", |
| 161 | + "⠄⠈⣿⣿⡀⠄⠄⠄⢩⣝⠃⠄⠄⢀⡄⡎⠄⠄⠄⠇⠄⠄⠅⣴⣶⣶⠄⣶" |
| 162 | + } |
| 163 | + ); |
| 164 | +} |
0 commit comments