Alex Rivera | Logout

Hooking an existing method in Java

Asked 2011-05-03T00:38:14.717
13

I want to hook the method System.out.print in Java and have the ability to read/change the variables used in the method before the part of the method is called that actually adds the string to whatever the output stream is.

In C++ I would just detour the function, or set an int3 instruction so I could access the registers but in java I have no idea how to accomplish something similar.

Edit
Report

1 Answer

3

Have a look at this link.

He sneakily defines a static anonymous class so that System.out points to something different, and therefore print and println will route through that object.

answered 2011-05-03T00:43:58.203

Your Answer