Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package local.pf.updater.util.instructions;
- import org.objectweb.asm.Opcodes;
- import org.objectweb.asm.tree.AbstractInsnNode;
- import org.objectweb.asm.tree.FieldInsnNode;
- import org.objectweb.asm.tree.IntInsnNode;
- public abstract class InsnCondition<T extends AbstractInsnNode> implements
- Opcodes {
- public int opcode;
- public abstract boolean check(T insn);
- public InsnCondition(int opcode) {
- this.opcode = opcode;
- }
- public static InsnCondition<AbstractInsnNode> makeFieldInsn(int opcode,
- final String desc) {
- return new InsnCondition<AbstractInsnNode>(opcode) {
- @Override
- public boolean check(AbstractInsnNode ain) {
- if (ain instanceof FieldInsnNode) {
- return ((FieldInsnNode) ain).desc.equals(desc);
- }
- return false;
- }
- };
- }
- public static InsnCondition<AbstractInsnNode> makeIntInsn(int opcode,
- final int operand) {
- return new InsnCondition<AbstractInsnNode>(opcode) {
- @Override
- public boolean check(AbstractInsnNode insn) {
- if(insn instanceof IntInsnNode){
- return ((IntInsnNode) insn).operand == operand;
- }
- return false;
- }
- };
- }
- public static InsnCondition<AbstractInsnNode> getCond(final int op){
- return new InsnCondition<AbstractInsnNode>(op){
- @Override
- public boolean check(AbstractInsnNode insn) {
- return insn.getOpcode() == op;
- }
- };
- }
- public static InsnCondition<AbstractInsnNode> makeRegexCond(int opcode, final String regex){
- return new InsnCondition<AbstractInsnNode>(opcode) {
- @Override
- public boolean check(AbstractInsnNode insn) {
- if(insn instanceof FieldInsnNode){
- return ((FieldInsnNode) insn).desc.matches(regex);
- }
- return false;
- }
- };
- }
- public static InsnCondition<AbstractInsnNode> GETFIELD_L = makeRegexCond(GETFIELD, "L.*;");
- public static InsnCondition<AbstractInsnNode> GETFIELD_LA = makeRegexCond(GETFIELD, "\\[L.*;");
- public static InsnCondition<AbstractInsnNode> GETFIELD_LAA = makeRegexCond(GETFIELD, "\\[\\[L.*;");
- public static InsnCondition<AbstractInsnNode> GETFIELD_LAAA = makeRegexCond(GETFIELD, "\\[\\[\\[L.*;");
- public static InsnCondition<AbstractInsnNode> PUTFIELD_L = makeRegexCond(PUTFIELD, "L.*;");
- public static InsnCondition<AbstractInsnNode> PUTFIELD_LA = makeRegexCond(PUTFIELD, "\\[L.*;");
- public static InsnCondition<AbstractInsnNode> PUTFIELD_LAA = makeRegexCond(PUTFIELD, "\\[\\[L.*;");
- public static InsnCondition<AbstractInsnNode> PUTFIELD_LAAA = makeRegexCond(PUTFIELD, "\\[\\[\\[L.*;");
- }
Add Comment
Please, Sign In to add comment