More Android Video Advanced Architecture Advanced Learning Click: https://space.bilibili.com/474380680
This article from the following elements to illustrate reflection and class loader:
- [Three kinds of ways to obtain the Class object]
- [Get instance constructor object attribute information]
- [Configure two methods the Android packaged signature information]
- [Hook dynamic code injection]
First, the basic concept of reflection Get Class object to the three way
Class class is the root of all reflection.
What Class class represents?
A lot of people - you can define a Person class (age, gender, name, etc.)
a lot of cars - you can define a Car class (engine, color, wheels, etc.)
a lot of class --Class class (class name, structure methods, properties, methods)
Class objects of the class obtained in three ways:
first: getClass Object class () method of
a second: class .class
third: Class class by the forName () method
Why learn reflection?
Can in turn reflected by an object class Class acquire class information (public private attributes, methods, etc.) of the target class;
most javaEE frame of the source is reflective manner, we can pave the way to learn this learning javaEE frame
code is as follows:
Second, the object instance constructor acquiring attribute information
code show as below:
Three, Android are two ways to configure package signature information
Directory structure is as follows:
There are two ways:
The first, direct configuration:
The second, by reading the file
New keystore.properties file
Four, Hook dynamic injection Code
Hook mechanism is a callback mechanism, general callback is static, we must write callback interface in advance; and Hook mechanism in Java you can use reflection, for an entry point (usually a member variable), the use of alternative means the code is changed at runtime, it sounds a bit abstract, following a brief introduction, and then I look at the code.
Looking for Hook point, it should be a member variable, and its method should call the method we need to inject in too, or use its value;
creating a subclass inherits from Hook Point objects, modified according to the needs of its corresponding method;
a reflective target object instance to replace an object to create our own, to achieve the purpose of the substitution.
Summary
due to limited content, I will not summarize the previous review, we examine one of the kind of thinking Hook prevent intrusion.
We add a checking mechanism in Hero class.
Now run the program again, the output is as follows:
More Android Video Advanced Architecture Advanced Learning Click: https://space.bilibili.com/474380680
Reference: https://www.jianshu.com/p/8bf24de75a7a
https://blog.csdn.net/qq_31370269/ Article This article was / the Details / 85,780,165
https://www.cnblogs.com/danew/p/11511952.html
https://www.jianshu.com/p/1a0c368da1b8