Android swizzling method with java

Is it possible to use swizzling method in android using java? I would like to intercept the system method and register its parameters, and then process it normally

+6
source share
1 answer

I think this method cannot be used using Java in any environment.

Perhaps you could achieve a similar result with AOP.

But what you can do with this is limited to Android. See Aspect Oriented Programming in android . In fact, since you will not compile the target code (system method), compiling in time (which seems to be all you can use on Android) will be useless for this case. Like this answer, I suppose.

Another thought ... I think you want to keep a consistent journal. But if you needed this to debug the problem, you could do it using a conditional breakpoint in Eclipse .

A conditional expression can contain arbitrary Java code and can contain more than one statement, allowing breakpoint conditions to implement functions such as tracing. For example, a condition may be executed by the print statement, and then return a hard coded value so as never to pause ("System.out.println (...); return false;").

I don't know specifically if this works with methods in the Android SDK. But it works with methods in the Java SDK. For example, here is a simple code:

System.err.println("foo"); 

I made a conditional breakpoint in PrintStream.print, for example:

 System.err.println("hello: " + arg0); return false; 

And console output when debugging in the program:

 hello: foo foo 

Note that since the JDK is not compiled using debugging symbols, I cannot refer to the method parameters by name, but using arg0..argn .

+3
source

Source: https://habr.com/ru/post/903206/


All Articles