Guest User

Untitled

a guest
Oct 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package local.pf.updater.util.instructions;
  2.  
  3. import org.objectweb.asm.Opcodes;
  4. import org.objectweb.asm.tree.AbstractInsnNode;
  5. import org.objectweb.asm.tree.FieldInsnNode;
  6. import org.objectweb.asm.tree.IntInsnNode;
  7.  
  8. public abstract class InsnCondition<T extends AbstractInsnNode> implements
  9. Opcodes {
  10.  
  11. public int opcode;
  12.  
  13. public abstract boolean check(T insn);
  14.  
  15. public InsnCondition(int opcode) {
  16. this.opcode = opcode;
  17. }
  18.  
  19. public static InsnCondition<AbstractInsnNode> makeFieldInsn(int opcode,
  20. final String desc) {
  21. return new InsnCondition<AbstractInsnNode>(opcode) {
  22. @Override
  23. public boolean check(AbstractInsnNode ain) {
  24. if (ain instanceof FieldInsnNode) {
  25. return ((FieldInsnNode) ain).desc.equals(desc);
  26. }
  27. return false;
  28. }
  29. };
  30. }
  31.  
  32. public static InsnCondition<AbstractInsnNode> makeIntInsn(int opcode,
  33. final int operand) {
  34. return new InsnCondition<AbstractInsnNode>(opcode) {
  35. @Override
  36. public boolean check(AbstractInsnNode insn) {
  37. if(insn instanceof IntInsnNode){
  38. return ((IntInsnNode) insn).operand == operand;
  39. }
  40. return false;
  41. }
  42. };
  43.  
  44. }
  45.  
  46. public static InsnCondition<AbstractInsnNode> getCond(final int op){
  47. return new InsnCondition<AbstractInsnNode>(op){
  48. @Override
  49. public boolean check(AbstractInsnNode insn) {
  50. return insn.getOpcode() == op;
  51. }
  52. };
  53. }
  54.  
  55. public static InsnCondition<AbstractInsnNode> makeRegexCond(int opcode, final String regex){
  56. return new InsnCondition<AbstractInsnNode>(opcode) {
  57. @Override
  58. public boolean check(AbstractInsnNode insn) {
  59. if(insn instanceof FieldInsnNode){
  60. return ((FieldInsnNode) insn).desc.matches(regex);
  61. }
  62. return false;
  63. }
  64. };
  65. }
  66.  
  67. public static InsnCondition<AbstractInsnNode> GETFIELD_L = makeRegexCond(GETFIELD, "L.*;");
  68. public static InsnCondition<AbstractInsnNode> GETFIELD_LA = makeRegexCond(GETFIELD, "\\[L.*;");
  69. public static InsnCondition<AbstractInsnNode> GETFIELD_LAA = makeRegexCond(GETFIELD, "\\[\\[L.*;");
  70. public static InsnCondition<AbstractInsnNode> GETFIELD_LAAA = makeRegexCond(GETFIELD, "\\[\\[\\[L.*;");
  71.  
  72. public static InsnCondition<AbstractInsnNode> PUTFIELD_L = makeRegexCond(PUTFIELD, "L.*;");
  73. public static InsnCondition<AbstractInsnNode> PUTFIELD_LA = makeRegexCond(PUTFIELD, "\\[L.*;");
  74. public static InsnCondition<AbstractInsnNode> PUTFIELD_LAA = makeRegexCond(PUTFIELD, "\\[\\[L.*;");
  75. public static InsnCondition<AbstractInsnNode> PUTFIELD_LAAA = makeRegexCond(PUTFIELD, "\\[\\[\\[L.*;");
  76. }
Add Comment
Please, Sign In to add comment