Load the jar Package class library When Java runs if there is the same package path and the same class name appears, will the JVM report an error?
Of course not! The JVM will only load the first occurrence of class
First, the JVM loads its own default package and then loads all the jars underneath the Ext directory to Classpath
So now there are 2 jars, respectively, Kj021320.jar Summer.jar with package paths Cn.isto
There are also class Jcrack.class so the JVM will see which class is loaded into the VM first! Read in the back if the path name will be discarded!
Think of the above loading method what would you imagine?
We first design a class
//这个是专门破解的类
package cn.isto;
public class Jcrack{
public Jcrack(){}
boolean getLogin(String pwd){
return true;
}
}
There is only one way to determine whether a login succeeds directly returns a true
Package This class as Kj021320.jar
Now let's write 2 more classes.
//这个是真正运行时候判断登陆的类
package cn.isto;
public class Jcrack {
public Jcrack() {
}
boolean getLogin(String pwd){
return "KJ021320".equals(pwd);
}
}
//调用登陆验证的类
package cn.isto;
public class JMain {
public JMain() {
}
public static void main(String[] args){
System.out.println(new Jcrack().getLogin("Summer"));
}
}
It is clear that we compile the above 2 classes to run directly after the OK! You don't have to look at the console to print false
However, we'll load the top Kj021320.jar back and run the Jmain class.
The system will show true simply because the JVM abandoned the normal user's Jcrack Class! and loaded with our own modified Jcrack Class!
The Java application is so simple to crack!