Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if ((m.name.equals(targetMethod3Name) && m.desc
- .equals("(Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;"))) {
- System.out
- .println("********* [ImageBufferDowload] Inside target3 method!");
- //on boucle et on récupère la position et les noeuds qui nous interresse
- AbstractInsnNode currentNode = null;
- //1er bipush
- AbstractInsnNode targetNode = null;
- //2eme bipush
- AbstractInsnNode targetNode2 = null;
- //les apelles des methodes:
- //setAreaOpaque
- AbstractInsnNode AreaOpaque = null;
- int INVOKESPECIALAreaOpaque_index = -1;
- //setAreaTransparent
- AbstractInsnNode AreaTransparent = null;
- //setAreaOpaque
- int INVOKESPECIALAreaTransparent_index = -1;
- AbstractInsnNode AreaOpaque2 = null;
- int INVOKESPECIALAreaOpaque2_index = -1;
- @SuppressWarnings("unchecked")
- Iterator<AbstractInsnNode> iter = m.instructions.iterator();
- int index = -1;
- int passageBIPUSH = 0;
- int passageINVOKESPECIAL = 0;
- // On boucle
- while (iter.hasNext()) {
- index++;
- currentNode = iter.next();
- System.out.println("line " + index + " : "
- + currentNode.getOpcode());
- //pour changer
- //this.imageWidth = 64;
- //this.imageHeight = 32;
- if (currentNode.getOpcode() == BIPUSH) {
- passageBIPUSH++;
- if (passageBIPUSH == 1) {
- System.out.println("1er Bipush");
- targetNode = currentNode;
- bipush_index = index;
- } else if (passageBIPUSH == 2) {
- System.out.println("2eme Bipush");
- targetNode2 = currentNode;
- }
- }
- /*
- pour changer:
- this.setAreaOpaque(0, 0, 32, 16);
- this.setAreaTransparent(32, 0, 64, 32);
- this.setAreaOpaque(0, 16, 64, 32);
- */
- if (currentNode.getOpcode() == INVOKESPECIAL) {
- passageINVOKESPECIAL++;
- if (passageINVOKESPECIAL == 1) {
- System.out.println("1er INVOKESPECIAL");
- AreaOpaque = currentNode;
- INVOKESPECIALAreaOpaque_index = index;
- } else if (passageINVOKESPECIAL == 2) {
- System.out.println("2ème INVOKESPECIAL");
- AreaTransparent = currentNode;
- INVOKESPECIALAreaTransparent_index = index;
- } else if (passageINVOKESPECIAL == 3) {
- System.out.println("3ème INVOKESPECIAL");
- AreaOpaque2 = currentNode;
- INVOKESPECIALAreaOpaque2_index = index;
- }
- }
- }
- /* on change
- this.setAreaOpaque(0, 16, 64, 32); en this.setAreaOpaque(0, this.imageHeight / 2, this.imageWidth, this.imageHeight);
- */
- // on créer les variables contenant les opcodes à supprimer
- AbstractInsnNode remNode11 = m.instructions
- .get(INVOKESPECIALAreaOpaque2_index - 1);
- AbstractInsnNode remNode12 = m.instructions
- .get(INVOKESPECIALAreaOpaque2_index - 2);
- AbstractInsnNode remNode13 = m.instructions
- .get(INVOKESPECIALAreaOpaque2_index - 3);
- // on les supprime
- m.instructions.remove(remNode11);
- m.instructions.remove(remNode12);
- m.instructions.remove(remNode13);
- //on créer les opcodes
- InsnList toInjectAreaOpaque2 = new InsnList();
- toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- toInjectAreaOpaque2.add(new InsnNode(ICONST_2));
- toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque2.add(new InsnNode(IDIV));
- toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageWidth", "I"));
- toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- // on les insère
- m.instructions.insertBefore(AreaOpaque2, toInjectAreaOpaque2);
- /* on change
- this.setAreaTransparent(32, 0, 64, 32);en this.setAreaTransparent(this.imageHeight, 0, this.imageWidth, this.imageHeight);
- */
- // on créer les variables contenant les opcodes à supprimer
- AbstractInsnNode remNode7 = m.instructions
- .get(INVOKESPECIALAreaTransparent_index - 1);
- AbstractInsnNode remNode8 = m.instructions
- .get(INVOKESPECIALAreaTransparent_index - 2);
- AbstractInsnNode remNode9 = m.instructions
- .get(INVOKESPECIALAreaTransparent_index - 3);
- AbstractInsnNode remNode10 = m.instructions
- .get(INVOKESPECIALAreaTransparent_index - 4);
- // on les supprime
- m.instructions.remove(remNode7);
- m.instructions.remove(remNode8);
- m.instructions.remove(remNode9);
- m.instructions.remove(remNode10);
- //on créer les opcodes
- InsnList toInjectAreaTransparent = new InsnList();
- toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- toInjectAreaTransparent.add(new InsnNode(ICONST_0));
- toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageWidth", "I"));
- toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- // on les insère
- m.instructions.insertBefore(AreaTransparent, toInjectAreaTransparent);
- /* on change
- this.setAreaOpaque(0, 0, 32, 16); en this.setAreaOpaque(0, 0, this.imageHeight, this.imageHeight/2);
- */
- // on créer les variables contenant les opcodes à supprimer
- AbstractInsnNode remNode5 = m.instructions
- .get(INVOKESPECIALAreaOpaque_index - 1);
- AbstractInsnNode remNode6 = m.instructions
- .get(INVOKESPECIALAreaOpaque_index - 2);
- // on les supprime
- m.instructions.remove(remNode5);
- m.instructions.remove(remNode6);
- //on créer les opcodes
- InsnList toInjectAreaOpaque = new InsnList();
- toInjectAreaOpaque.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- toInjectAreaOpaque.add(new VarInsnNode(ALOAD, 0));
- toInjectAreaOpaque.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
- toInjectAreaOpaque.add(new InsnNode(ICONST_2));
- toInjectAreaOpaque.add(new InsnNode(IDIV));
- // on les insère
- m.instructions.insertBefore(AreaOpaque, toInjectAreaOpaque);
- /* ajout de la condition:
- if(this.imageHeight != this.imageWidth/2)
- return null;
- */
- //on créer les opcodes
- InsnList toInjectCondition = new InsnList();
- toInjectCondition.add(new VarInsnNode(ALOAD, 0));
- toInjectCondition.add(new FieldInsnNode(GETFIELD,
- "net/minecraft/client/renderer/ImageBufferDownload",
- "imageHeight", "I"));
- toInjectCondition.add(new VarInsnNode(ALOAD, 0));
- toInjectCondition.add(new FieldInsnNode(GETFIELD,
- "net/minecraft/client/renderer/ImageBufferDownload",
- "imageWidth", "I"));
- toInjectCondition.add(new InsnNode(ICONST_2));
- toInjectCondition.add(new InsnNode(IDIV));
- LabelNode L1 = new LabelNode();
- toInjectCondition.add(new JumpInsnNode(IF_ICMPEQ, L1));
- toInjectCondition.add(new InsnNode(ACONST_NULL));
- toInjectCondition.add(new InsnNode(ARETURN));
- toInjectCondition.add(L1);
- // on les insère
- m.instructions.insert(m.instructions.get(bipush_index + 6),
- toInjectCondition);
- /* on change
- this.imageHeight = 32; en this.imageHeight = par1BufferedImage.getHeight();
- */
- // on créer les variables contenant les opcodes à supprimer
- AbstractInsnNode remNode3 = m.instructions
- .get(bipush_index + 5);
- AbstractInsnNode remNode4 = m.instructions
- .get(bipush_index + 6);
- // on les supprime
- m.instructions.remove(remNode3);
- m.instructions.remove(remNode4);
- // on créer les opcodes à insérer
- InsnList toInject2 = new InsnList();
- toInject2.add(new VarInsnNode(ALOAD, 0));
- toInject2.add(new VarInsnNode(ALOAD, 1));
- toInject2.add(new MethodInsnNode(INVOKEVIRTUAL,
- "java/awt/image/BufferedImage", "getHeight", "()I"));
- toInject2.add(new FieldInsnNode(PUTFIELD,
- "net/minecraft/client/renderer/ImageBufferDownload",
- "imageHeight", "I"));
- // on les insère
- m.instructions.insert(targetNode2, toInject2);
- /* on change
- this.imageWidth = 64; en this.imageWidth = par1BufferedImage.getWidth();
- */
- // on créer les variables contenant les opcodes à supprimer
- AbstractInsnNode remNode1 = m.instructions.get(bipush_index);
- AbstractInsnNode remNode2 = m.instructions
- .get(bipush_index + 1);
- // on les supprime
- m.instructions.remove(remNode1);
- m.instructions.remove(remNode2);
- // on créer les opcodes à insérer
- InsnList toInject = new InsnList();
- toInject.add(new VarInsnNode(ALOAD, 0));
- toInject.add(new VarInsnNode(ALOAD, 1));
- toInject.add(new MethodInsnNode(INVOKEVIRTUAL,
- "java/awt/image/BufferedImage", "getWidth", "()I"));
- toInject.add(new FieldInsnNode(PUTFIELD,
- "net/minecraft/client/renderer/ImageBufferDownload",
- "imageWidth", "I"));
- // on les insère
- m.instructions.insert(targetNode, toInject);
- System.out
- .println("[ImageBufferDownload] Patching Method3 Complete!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement