From c70c96b5d91e03e33795ee75bb5d3f34b0b397a8 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 25 Jun 2017 23:48:35 +0200 Subject: [PATCH] preverification for methods --- .../systemTray/util/SystemTrayFixes.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/dorkbox/systemTray/util/SystemTrayFixes.java b/src/dorkbox/systemTray/util/SystemTrayFixes.java index b2889d9..c8838d3 100644 --- a/src/dorkbox/systemTray/util/SystemTrayFixes.java +++ b/src/dorkbox/systemTray/util/SystemTrayFixes.java @@ -27,6 +27,7 @@ import dorkbox.util.OS; import javassist.ClassPool; import javassist.CtBehavior; import javassist.CtClass; +import javassist.CtConstructor; import javassist.CtField; import javassist.CtMethod; import javassist.CtNewMethod; @@ -144,12 +145,14 @@ class SystemTrayFixes { trayClass.getConstructors()[0].setModifiers(trayClass.getConstructors()[0].getModifiers() & javassist.Modifier.PUBLIC); - CtBehavior methodInfos[] = new CtBehavior[]{ - trayClass.getDeclaredMethod("getTrayIconSize") - }; + CtMethod method = trayClass.getDeclaredMethod("getTrayIconSize"); + CtBehavior methodInfos[] = new CtBehavior[]{ method }; fixTraySize(methodInfos, trayIconSize); + // perform pre-verification for the modified method + method.getMethodInfo().rebuildStackMapForME(trayClass.getClassPool()); + trayBytes = trayClass.toBytecode(); } @@ -219,6 +222,10 @@ class SystemTrayFixes { "}" + "}"); + // perform pre-verification for the modified method + ctMethodCreate.getMethodInfo().rebuildStackMapForME(trayIconClass.getClassPool()); + ctMethodUpdate.getMethodInfo().rebuildStackMapForME(trayIconClass.getClassPool()); + trayIconBytes = trayIconClass.toBytecode(); } @@ -397,6 +404,9 @@ class SystemTrayFixes { "}" + "}"); + // perform pre-verification for the modified method + ctMethodGet.getMethodInfo().rebuildStackMapForME(trayClass.getClassPool()); + mouseEventBytes = trayClass.toBytecode(); // whoosh, past the classloader and directly into memory. @@ -490,14 +500,21 @@ class SystemTrayFixes { // Since, looking at the source code, there is NO other case where the number 24 is used (except for size), we just // bytecode replace 24 with our specified size. - CtBehavior methodInfos[] = new CtBehavior[]{ - trayIconClass.getDeclaredConstructors()[0], // only 1 constructor - trayIconClass.getDeclaredMethod("getBounds"), - trayPeerClass.getDeclaredMethod("getTrayIconSize") + CtConstructor constructor = trayIconClass.getDeclaredConstructors()[0]; // only 1 constructor + CtMethod method1 = trayIconClass.getDeclaredMethod("getBounds"); + CtMethod method2 = trayPeerClass.getDeclaredMethod("getTrayIconSize"); + + CtBehavior methodInfos[] = new CtBehavior[]{constructor, + method1, method2 }; fixTraySize(methodInfos, trayIconSize); + // perform pre-verification for the modified method + constructor.getMethodInfo().rebuildStackMapForME(trayIconClass.getClassPool()); + method1.getMethodInfo().rebuildStackMapForME(trayIconClass.getClassPool()); + method2.getMethodInfo().rebuildStackMapForME(trayPeerClass.getClassPool()); + trayIconBytes = trayIconClass.toBytecode(); trayPeerBytes = trayPeerClass.toBytecode(); @@ -525,6 +542,9 @@ class SystemTrayFixes { "super.setVisible(b);" + " }", eFrameClass); eFrameClass.addMethod(methodVisible); + + methodVisible.getMethodInfo().rebuildStackMapForME(eFrameClass.getClassPool()); + eFrameBytes = eFrameClass.toBytecode(); } @@ -544,7 +564,8 @@ class SystemTrayFixes { private static void fixTraySize(final CtBehavior[] behaviors, final int traySize) { for (CtBehavior behavior : behaviors) { - CodeIterator methodIterator = behavior.getMethodInfo().getCodeAttribute().iterator(); + MethodInfo methodInfo = behavior.getMethodInfo(); + CodeIterator methodIterator = methodInfo.getCodeAttribute().iterator(); while (methodIterator.hasNext()) { int index;