Pre-loading of Java class libraries

Source: Internet
Author: User

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!

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.