Advertisement
Guest User

Untitled

a guest
Jul 8th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. else if ((m.name.equals(targetMethod3Name) && m.desc
  2. .equals("(Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;"))) {
  3. System.out
  4. .println("********* [ImageBufferDowload] Inside target3 method!");
  5. //on boucle et on récupère la position et les noeuds qui nous interresse
  6.  
  7. AbstractInsnNode currentNode = null;
  8. //1er bipush
  9. AbstractInsnNode targetNode = null;
  10. //2eme bipush
  11. AbstractInsnNode targetNode2 = null;
  12.  
  13. //les apelles des methodes:
  14. //setAreaOpaque
  15. AbstractInsnNode AreaOpaque = null;
  16. int INVOKESPECIALAreaOpaque_index = -1;
  17. //setAreaTransparent
  18. AbstractInsnNode AreaTransparent = null;
  19. //setAreaOpaque
  20. int INVOKESPECIALAreaTransparent_index = -1;
  21. AbstractInsnNode AreaOpaque2 = null;
  22. int INVOKESPECIALAreaOpaque2_index = -1;
  23.  
  24. @SuppressWarnings("unchecked")
  25. Iterator<AbstractInsnNode> iter = m.instructions.iterator();
  26.  
  27. int index = -1;
  28.  
  29. int passageBIPUSH = 0;
  30. int passageINVOKESPECIAL = 0;
  31. // On boucle
  32. while (iter.hasNext()) {
  33. index++;
  34. currentNode = iter.next();
  35. System.out.println("line " + index + " : "
  36. + currentNode.getOpcode());
  37. //pour changer
  38. //this.imageWidth = 64;
  39. //this.imageHeight = 32;
  40. if (currentNode.getOpcode() == BIPUSH) {
  41. passageBIPUSH++;
  42. if (passageBIPUSH == 1) {
  43. System.out.println("1er Bipush");
  44. targetNode = currentNode;
  45. bipush_index = index;
  46. } else if (passageBIPUSH == 2) {
  47. System.out.println("2eme Bipush");
  48. targetNode2 = currentNode;
  49. }
  50. }
  51.  
  52. /*
  53. pour changer:
  54. this.setAreaOpaque(0, 0, 32, 16);
  55. this.setAreaTransparent(32, 0, 64, 32);
  56. this.setAreaOpaque(0, 16, 64, 32);
  57. */
  58. if (currentNode.getOpcode() == INVOKESPECIAL) {
  59. passageINVOKESPECIAL++;
  60. if (passageINVOKESPECIAL == 1) {
  61. System.out.println("1er INVOKESPECIAL");
  62. AreaOpaque = currentNode;
  63. INVOKESPECIALAreaOpaque_index = index;
  64. } else if (passageINVOKESPECIAL == 2) {
  65. System.out.println("2ème INVOKESPECIAL");
  66. AreaTransparent = currentNode;
  67. INVOKESPECIALAreaTransparent_index = index;
  68. } else if (passageINVOKESPECIAL == 3) {
  69. System.out.println("3ème INVOKESPECIAL");
  70. AreaOpaque2 = currentNode;
  71. INVOKESPECIALAreaOpaque2_index = index;
  72.  
  73. }
  74. }
  75. }
  76.  
  77.  
  78. /* on change
  79. this.setAreaOpaque(0, 16, 64, 32); en this.setAreaOpaque(0, this.imageHeight / 2, this.imageWidth, this.imageHeight);
  80. */
  81.  
  82. // on créer les variables contenant les opcodes à supprimer
  83. AbstractInsnNode remNode11 = m.instructions
  84. .get(INVOKESPECIALAreaOpaque2_index - 1);
  85. AbstractInsnNode remNode12 = m.instructions
  86. .get(INVOKESPECIALAreaOpaque2_index - 2);
  87. AbstractInsnNode remNode13 = m.instructions
  88. .get(INVOKESPECIALAreaOpaque2_index - 3);
  89.  
  90. // on les supprime
  91. m.instructions.remove(remNode11);
  92. m.instructions.remove(remNode12);
  93. m.instructions.remove(remNode13);
  94.  
  95. //on créer les opcodes
  96. InsnList toInjectAreaOpaque2 = new InsnList();
  97. toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
  98. toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  99. toInjectAreaOpaque2.add(new InsnNode(ICONST_2));
  100. toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
  101. toInjectAreaOpaque2.add(new InsnNode(IDIV));
  102. toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
  103. toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageWidth", "I"));
  104. toInjectAreaOpaque2.add(new VarInsnNode(ALOAD, 0));
  105. toInjectAreaOpaque2.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  106.  
  107.  
  108.  
  109. // on les insère
  110. m.instructions.insertBefore(AreaOpaque2, toInjectAreaOpaque2);
  111.  
  112.  
  113.  
  114. /* on change
  115. this.setAreaTransparent(32, 0, 64, 32);en this.setAreaTransparent(this.imageHeight, 0, this.imageWidth, this.imageHeight);
  116. */
  117.  
  118. // on créer les variables contenant les opcodes à supprimer
  119. AbstractInsnNode remNode7 = m.instructions
  120. .get(INVOKESPECIALAreaTransparent_index - 1);
  121. AbstractInsnNode remNode8 = m.instructions
  122. .get(INVOKESPECIALAreaTransparent_index - 2);
  123. AbstractInsnNode remNode9 = m.instructions
  124. .get(INVOKESPECIALAreaTransparent_index - 3);
  125. AbstractInsnNode remNode10 = m.instructions
  126. .get(INVOKESPECIALAreaTransparent_index - 4);
  127.  
  128. // on les supprime
  129. m.instructions.remove(remNode7);
  130. m.instructions.remove(remNode8);
  131. m.instructions.remove(remNode9);
  132. m.instructions.remove(remNode10);
  133.  
  134.  
  135. //on créer les opcodes
  136. InsnList toInjectAreaTransparent = new InsnList();
  137. toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
  138. toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
  139. toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  140. toInjectAreaTransparent.add(new InsnNode(ICONST_0));
  141. toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
  142. toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageWidth", "I"));
  143. toInjectAreaTransparent.add(new VarInsnNode(ALOAD, 0));
  144. toInjectAreaTransparent.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  145.  
  146.  
  147. // on les insère
  148. m.instructions.insertBefore(AreaTransparent, toInjectAreaTransparent);
  149.  
  150.  
  151.  
  152. /* on change
  153. this.setAreaOpaque(0, 0, 32, 16); en this.setAreaOpaque(0, 0, this.imageHeight, this.imageHeight/2);
  154. */
  155.  
  156. // on créer les variables contenant les opcodes à supprimer
  157. AbstractInsnNode remNode5 = m.instructions
  158. .get(INVOKESPECIALAreaOpaque_index - 1);
  159. AbstractInsnNode remNode6 = m.instructions
  160. .get(INVOKESPECIALAreaOpaque_index - 2);
  161.  
  162. // on les supprime
  163. m.instructions.remove(remNode5);
  164. m.instructions.remove(remNode6);
  165.  
  166. //on créer les opcodes
  167. InsnList toInjectAreaOpaque = new InsnList();
  168. toInjectAreaOpaque.add(new VarInsnNode(ALOAD, 0));
  169. toInjectAreaOpaque.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  170. toInjectAreaOpaque.add(new VarInsnNode(ALOAD, 0));
  171. toInjectAreaOpaque.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/renderer/ImageBufferDownload", "imageHeight", "I"));
  172. toInjectAreaOpaque.add(new InsnNode(ICONST_2));
  173. toInjectAreaOpaque.add(new InsnNode(IDIV));
  174.  
  175. // on les insère
  176. m.instructions.insertBefore(AreaOpaque, toInjectAreaOpaque);
  177.  
  178.  
  179.  
  180. /* ajout de la condition:
  181. if(this.imageHeight != this.imageWidth/2)
  182. return null;
  183. */
  184.  
  185. //on créer les opcodes
  186. InsnList toInjectCondition = new InsnList();
  187. toInjectCondition.add(new VarInsnNode(ALOAD, 0));
  188. toInjectCondition.add(new FieldInsnNode(GETFIELD,
  189. "net/minecraft/client/renderer/ImageBufferDownload",
  190. "imageHeight", "I"));
  191. toInjectCondition.add(new VarInsnNode(ALOAD, 0));
  192. toInjectCondition.add(new FieldInsnNode(GETFIELD,
  193. "net/minecraft/client/renderer/ImageBufferDownload",
  194. "imageWidth", "I"));
  195. toInjectCondition.add(new InsnNode(ICONST_2));
  196. toInjectCondition.add(new InsnNode(IDIV));
  197. LabelNode L1 = new LabelNode();
  198. toInjectCondition.add(new JumpInsnNode(IF_ICMPEQ, L1));
  199. toInjectCondition.add(new InsnNode(ACONST_NULL));
  200. toInjectCondition.add(new InsnNode(ARETURN));
  201. toInjectCondition.add(L1);
  202.  
  203. // on les insère
  204. m.instructions.insert(m.instructions.get(bipush_index + 6),
  205. toInjectCondition);
  206.  
  207.  
  208.  
  209. /* on change
  210. this.imageHeight = 32; en this.imageHeight = par1BufferedImage.getHeight();
  211. */
  212.  
  213. // on créer les variables contenant les opcodes à supprimer
  214. AbstractInsnNode remNode3 = m.instructions
  215. .get(bipush_index + 5);
  216. AbstractInsnNode remNode4 = m.instructions
  217. .get(bipush_index + 6);
  218.  
  219. // on les supprime
  220. m.instructions.remove(remNode3);
  221. m.instructions.remove(remNode4);
  222.  
  223. // on créer les opcodes à insérer
  224. InsnList toInject2 = new InsnList();
  225. toInject2.add(new VarInsnNode(ALOAD, 0));
  226. toInject2.add(new VarInsnNode(ALOAD, 1));
  227. toInject2.add(new MethodInsnNode(INVOKEVIRTUAL,
  228. "java/awt/image/BufferedImage", "getHeight", "()I"));
  229. toInject2.add(new FieldInsnNode(PUTFIELD,
  230. "net/minecraft/client/renderer/ImageBufferDownload",
  231. "imageHeight", "I"));
  232.  
  233. // on les insère
  234. m.instructions.insert(targetNode2, toInject2);
  235.  
  236.  
  237.  
  238. /* on change
  239. this.imageWidth = 64; en this.imageWidth = par1BufferedImage.getWidth();
  240. */
  241.  
  242. // on créer les variables contenant les opcodes à supprimer
  243. AbstractInsnNode remNode1 = m.instructions.get(bipush_index);
  244. AbstractInsnNode remNode2 = m.instructions
  245. .get(bipush_index + 1);
  246.  
  247. // on les supprime
  248. m.instructions.remove(remNode1);
  249. m.instructions.remove(remNode2);
  250.  
  251. // on créer les opcodes à insérer
  252. InsnList toInject = new InsnList();
  253. toInject.add(new VarInsnNode(ALOAD, 0));
  254. toInject.add(new VarInsnNode(ALOAD, 1));
  255. toInject.add(new MethodInsnNode(INVOKEVIRTUAL,
  256. "java/awt/image/BufferedImage", "getWidth", "()I"));
  257. toInject.add(new FieldInsnNode(PUTFIELD,
  258. "net/minecraft/client/renderer/ImageBufferDownload",
  259. "imageWidth", "I"));
  260.  
  261. // on les insère
  262. m.instructions.insert(targetNode, toInject);
  263. System.out
  264. .println("[ImageBufferDownload] Patching Method3 Complete!");
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement