jeudi 30 mars 2017

Extract JFrame from external jar file

i am working on a project in Eclipse where i need to extract a Jframe component from one external jar file.

The intention of this is to access via code to all java swing / awt components included. Something like control+shift+F1 debug mode of Eclipse.

I'm using Java Reflection to open the interface, read fields and read the methods; but i don't know how to do the next step to extract the swing objects.

File f = new File("C:/.../File.jar");
    ClassLoader cl = new URLClassLoader(new URL[] { f.toURI().toURL() }, null);
    final Class<?> claxx = cl.loadClass("JSwing");
    final Method main = claxx.getMethod("main", String[].class);

    Field[] fields = claxx.getDeclaredFields();
    for (Field field : fields) {
       System.out.println("field: " + field.getName());
    }

    Method[] methods = claxx.getDeclaredMethods();
    for (Method method : methods) {
        System.out.println("method: " + method.toString());
    }
EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                main.invoke(claxx, new Object[] {null} );
            } catch (Throwable th) {
                // TODO
            }
        }
    });

Obtained------------------------------------------

field: frmJavaswingui

field: txtJavaSwingUi

method: public static void JSwing.main(java.lang.String[])

method: private void JSwing.initialize()

The interface of the application

¿Any idea to extract the components of "frmJavaswingui"?





Aucun commentaire:

Enregistrer un commentaire