PDA

View Full Version : Hooking with Java?


AttonRand
October 7th, 2009, 09:05
Is it possible, in your opinion, to do an api hooking or a simple d3d hook like this (http://www.ring3circus.com/wp-content/uploads/bioshock_hooked.png) but in JAVA?
just curious.

I saw this on wiki:
Code:
http://en.wikipedia.org/wiki/Java_3D

but it is useless if i cant code a good hooking engine in java.

bye

Alex

BanMe
October 7th, 2009, 10:35
I dont think its has been done..not to say its not possible just no viable examples of such a occurance...the only interesting thing I did find on this was

http://xantorohara.blogspot.com/2007/09/java-code-injection-via-winapis.html

and thats mostly unrelated to the question can you make a JAVA hooking engine..I'm sure it could be done but I think C++ would be a more viable development path to take.

regards BanMe

OHPen
October 7th, 2009, 10:49
Hi AttonRand,

there are many ways to establish hooking in java. It depends on following questions:


What do you want your hook to do ?
Which language do you want to use ?
Do you want to hide your hook ?


First you can use reflection framework from java. You can code your own classloader and write a small wrapper which gets access when a class is going to be loaded. Then you can do some instrumentation with one of the known instrumentation frameworks (asm, bcel, etc...).

Another way would be to use the JVMTI interface to directly set hooks at native site. As far as i known there are special handlers which can be registered to get access before a class file is loaded or maybe also before a method is executed. Its not easy to JVMTI if you are not an expert in JNI programming, but a try worth.

Also you could reach your goal if do static instrumentation. Therefore you need to write a framework which is capable of transforming code depending on your needs, thus capable inserting calls directly in the bytecode. I wrote such a framework for the company I'm working in and I can tell you its not difficult but you will have to spend a lot of time to cover all cases which might be appear in a method.

If i were you, I would try learn how java reflection is working. Maybe in your case it provides what you need to do.

Regards,
OHPen.

BanMe
October 7th, 2009, 10:55
I think you missed the point of the question OH

He wants to do a Java Hooking engine capable of being used in a non java way..IE d3d hooking, I think hes trying to 'Window mode' and 'fullscreen' window, but as I am not able to read or look at "this" from above I am unable to verify my assumptions..but damn good info either way..

BanMe

AttonRand
October 7th, 2009, 11:30
Thanks all for replies. Sorry but i havent figured that direct links were disabled (this is the image from admiral http://www.ring3circus.com/wp-content/uploads/bioshock_hooked.png).

Ok, i think i must start learning c++ syntax to achieve my goal but i wont give up and i will still try to use java.

Quote:
If i were you, I would try learn how java reflection is working. Maybe in your case it provides what you need to do.


Thats what i am going to do, thank you very much for your suggestions

OHPen
October 7th, 2009, 17:12
@banme: you are right , after reading the post again in a more detailed way, i have to admit that i was to fast in answering this one, hehe.

So if he really wants to apply hooking native functions in other programs, he MUST use the JNI interface of java. in that case hooking is nothing more than standard hooking engines with c/c++ + proper use of javas jni interface

Anyway,
somehow he will be able to do what he wants to do, as always, hrhr.

Regards,
OHPen

AttonRand
October 8th, 2009, 08:53
Thank you very much OH
I am now reading docs about JNI. It is a new field for me: i want to make what admiral did but in java, just to prove that even java is capable of d3d hooking.

Alex

OHPen
October 8th, 2009, 09:29
@AttonRand: I think its a nice project if you want to learn something, but if you want to do something better than others do, probably java is not the best choice, at least performance wise.

Nevertheless you will learn a lot

Regards,
OHPen