Fork me on GitHub
#interop
<
2022-04-07
>
Nundrum22:04:58

I'm back with the crazy again

Nundrum22:04:46

Trying to instantiate https://github.com/openjdk/client/blob/master/src/java.desktop/share/classes/sun/awt/EmbeddedFrame.java using reflection

(def ef (new EmbeddedFrame (long 92285152)));; "It's private. Go away."

(def efc (Class/forName "sun.awt.EmbeddedFrame"))
(.getConstructors efc);; #object["[Ljava.lang.reflect.Constructor;" 0x263cb983 "[Ljava.lang.reflect.Constructor;@263cb983"]

(def efcons (.getDeclaredConstructor sun.awt.EmbeddedFrame (into-array Class [java.lang.Long/TYPE])) )
(.setAccessible efcons true)
(identity efcons);; #object[java.lang.reflect.Constructor 0x7b7e14d5 "protected sun.awt.EmbeddedFrame(long)"]

;;all lined up to call it
(.newInstance efcons (into-array Object [(long 92285152)]));; Clojure: class java.lang.InstantiationException
(clojure.lang.Reflector/invokeConstructor (resolve (symbol "sun.awt.EmbeddedFrame")) (into-array [92285152]));; Clojure: class java.lang.IllegalArgumentException

Nundrum22:04:43

ah heck it's an abstract class

Nundrum23:04:59

Wow. Got so close.

(def xef (clojure.lang.Reflector/invokeConstructor     
    (resolve (symbol "sun.awt.X11.XEmbeddedFrame"))    
    (into-array Object [92285152 ])) )                 
                                                       
(.synthesizeWindowActivation xef true)                 
                                                       
The number is a window ID. When I run that, it actually causes focus to jump to the correct window!
(def g (.getGraphics xef) )   
(.setColor g Color/RED)       
(.fillRect g 0,0,1000,1000)   
Sadly that does nothing. The rectangle doesn't show up.