Recently in learning Hook technology, if you have some understanding of Hook before, might as well do Hook 3 related topics! Do not know how to also do not matter, here also to you popularize once!

What is a Hook?

The Android operating system maintains its own set of event distribution mechanisms. Applications, including application triggering events and background logic processing, are also executed step by step down the event flow. A Hook is a Hook that intercepts and monitors the transmission of an event before it reaches its destination, just like a Hook on an event, and can handle some of its own specific events when the event is on the Hook.

By Hook, it can “integrate” its own code into the process of the program that is hooked, becoming a part of the target process. API Hook technology is a technology used to change the result of API execution, which can redirect the system’s API function execution. The Sandbox mechanism is used in the Android system. The process space of the ordinary user program is independent, and the operation of the program does not interfere with each other.

1.Hook technology and pile insertion technology to achieve plug-in which of the following description is correct [multiple choice]

A. Pegs are loaded using the that syntax

B. Hook is done by merging the dex of the plug-in into the dex array of the host

C. Cook combines two APKs into one APK file and loads it

D. Piling is implemented by rewriting two methods gerResourse and getClassloader through ProxyActivity

2. Is the Application in the plug-in the Application in the host?

A. Yes.

B is not

3. When is the ClassLoader object in LoadApk assigned

A is assigned during Application initialization when the App is started

B When the Activity starts, it is assigned when the Activity initializes

C Activity is assigned when it calls the declaration cycle onResume method

D None of the above

For the answer to the question, just reply Hook in the background.

Preliminary understanding of Hook

Hook technology, generally through reflection to create dynamic proxy, replace the system API, to implement their own logic.

For example, Hook to launch plug-in APK, and the idea is to use reflection to replace the system object with the proxy object that we created, and get the IActivityManager object, also through reflection.

The specific implementation steps are as follows:
  • Get the IActivityManager object by reflection;
  • Define a scheduling class for a proxy class that implements the Invoke method of InvocationHandler.
  • Create a scheduling class instance using IActivityManager as the parameter.
  • Generate an instance of the proxy class with IActivityManager and scheduling class instances as parameters.
  • Replace the IActivityManager object obtained in the first step with an instance of the proxy class.
Recently, I studied the implementation planning of Hook technology
  • The principle of Hook
  • How to find Hook points
  • Java dynamic proxy mechanism analysis
  • App startup process
  • Commonly used Hook framework
  • Implement API hooks using Java reflection
  • Dynamic proxy technology Hook system AMS service

Hook technology implementation is relatively difficult at the beginning, requires a certain technical background, especially familiar with the source code. If you want to further study Android to learn Hook technology, welcome to pay attention to my terminal RESEARCH and development department can learn with me!