zoukankan      html  css  js  c++  java
  • 用户自定义类加载器(java防止反编译)

    使用场景:

      1.隔离加载类

      2.修改类加载的方式

      3.扩展加载源

      4.防止源码泄露

    public class CustomClassLoader extends ClassLoader {
        @Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
    
            try {
                byte[] result = getClassFromCustomPath(name);
                if(result == null){
                    throw new FileNotFoundException();
                }else{
                    return defineClass(name,result,0,result.length);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    
            throw new ClassNotFoundException(name);
        }
    
        private byte[] getClassFromCustomPath(String name){
            //从自定义路径中加载指定类:细节略
            //如果指定路径的字节码文件进行了加密,则需要在此方法中进行解密操作。
            return null;
        }
    
        public static void main(String[] args) {
            CustomClassLoader customClassLoader = new CustomClassLoader();
            try {
                Class<?> clazz = Class.forName("One",true,customClassLoader);
                Object obj = clazz.newInstance();
                System.out.println(obj.getClass().getClassLoader());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    harbor镜像拉取到本地
    hadoop单机部署
    tcpdump抓包
    centos7安装桌面启动`
    lvm虚拟机扩容虚拟机根目录
    ubuntu 18 静态网址及生效
    ubuntu安装微信
    QPS、TPS、PV、UV、GMV、IP、RPS
    RabbitMQ死信队列
    mysql update语句与limit的结合使用
  • 原文地址:https://www.cnblogs.com/zyf-yxm/p/13547333.html
Copyright © 2011-2022 走看看