Implement interception of any Java method in Android App development, androidapp

Source: Internet
Author: User

Implement interception of any Java method in Android App development, androidapp
During Android App development, there are often some Framework layer bugs that cause the App process to crash, such as the crash caused by Cookie synchronization. In this case, we can avoid this problem if we can intercept Api calls at the Framework layer and pack it to catch exceptions.
At that time, the pure Java layer was not available, and the Proxy mechanism in Java was only available for the classes defined by itself. The classes at the system Framework layer were useless. In this example, we use Java's JNI mechanism to intercept arbitrary Java methods of process classes.
Any Java Method corresponds to a Method class in the C ++ layer. If it is a JNI Method, the nativeFunc member variable of the Method class points to the Native Implementation of JNI. If it is not a JNI Method, it points to the Java method implementation and calls dvmInterpret to execute the Java method. With this mechanism, we can implement method interception. Suppose we have a Java-layer Method Java_Method that requires Hook. We will provide the Hook Method Java_Method_Hook to the C-Layer Method of Java_Method and place it in its member variable ins. Next, define a C-layer Method C_hookHandler and assign this Method to the nativeFunc member variable of Method. Then, when C_hookHandler is called, you can intercept Java_Method by calling Java_Method_Hook In the ins member variable.


For more detailed and systematic procedures, refer to the following article or Xposed source code.
Http://blog.csdn.net/luoshengyang/article/details/8914953
The biggest difference between Xposed is that it replaces app_process to implement Hack for other processes, so that it can intercept the method to any process.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.