The Java program to hook?

Under the first background

What I need is on the Android platform HOOK of a process JAVA code
This two days to check a lot of information that reflection can be found, is not the same thing.

Windows platform HOOK mean hook

Somewhere in the code you want to HOOK through a variety of methods to perform to your code.

Need to do now is the JAVA code A for an android in the process of calling the B method

I think in the A method calls the B method to the A to intercept the parameters of B filter

Don't know how to do this in JAVA.

In the final analysis, I will put B method completely replaced my code. Do not know that whether can understand

Started by Ken at December 02, 2016 - 12:10 PM

In fact, reflection can be done.
Spring there are examples of AOP like this.

Posted by Anthony at December 14, 2016 - 12:50 PM

Dare to elaborate ah brother. . .

Yesterday at the AOP didn't feel what I want. .

Posted by Ken at December 29, 2016 - 1:44 PM

This is a similar to the function of the filter.
AOP you know,
When you call A B, a C can get A to B something in the middle,

If you do not have AOP, you can use the JAVA dynamic proxy can reach your requirements.

Posted by Anthony at January 05, 2017 - 2:45 PM


package com.birds.aop;

public interface Action {
public void process(String msg);
}

package com.birds.aop;

public class MyAction implements Action {

@Override
public void process(String msg) {
System.out.println("result:" + msg);
}

}

public class MyHandler implements InvocationHandler {

private Object obj;

public MyHandler() {

}

public Object newProx(Object obj){
this.obj = obj;
return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
}

/*
* (non-Javadoc)
*
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
* java.lang.reflect.Method, java.lang.Object[])
*/
@Override
public Object invoke(Object arg0, Method method, Object[] arg2)
throws Throwable {
System.out.println("=============" + method + "," + arg2);
if (arg2 != null) {
for (Object pm : arg2) {
System.out.println("what:" + pm);
}
}
return null;
}

public static void main(String[] args) {
MyHandler handler = new MyHandler();
Action action = (Action) handler.newProx(new MyAction());
action.process("Hello,guys");
}
}


As long as the implementation of the process method, it will automatically call the invoke method, you can see what the parameters in this method, call what method.

Posted by Anthony at January 09, 2017 - 2:58 PM

Hello, you should not do what I want. You just watch. I saw yesterday.

I will not watch, I don't need to monitor it reflected. I only need to register a message.

What I need is A when calling B, called B is my code, I decided to send the B code is what.


You are JAVA don't need hook.?
Or you get Java without Windows platform? You can have a look Windows platform hook.

What I want is that.


Now A to B is direct.

I must realize is, set up checkpoints in the process of A to B. So always understand.?

Posted by Ken at January 11, 2017 - 2:03 PM