In native code on windows functions can be hooked by replacing their prologue with a JMP
instruction.
Is there a way to do something similar with an application written in java? In the end I want to record all data sent to/from a javax.net.ssl.SSLSocket
.
I can't modify the jar file or the jre on disk, because it will bail if the hashes don't match up, but I can hook any function from native code during runtime.
I have a working solution right now, but it's very messy and not that flexible. I'm hooking JNI_CreateJavaVM
and inserting -Djavax.net.debug=all
into the arguments passed to it. This causes all data sent over the socket to be written to disk, and then I'm hooking WriteFile
to intercept that data before it gets written to disk.
I found something that looked close to what I want, the -javaagent
parameter, but by the time my agent is loaded all of the java standard library is loaded so I don't see a way to hook it using an agent.