今天查看源码发现如下代码
public class DebuggingClassWriter extends ClassVisitor {
public static final String DEBUG_LOCATION_PROPERTY = "cglib.debugLocation";
private static String debugLocation = System.getProperty(DEBUG_LOCATION_PROPERTY);
public byte[] toByteArray() {
if (DebuggingClassWriter.debugLocation != null) {
File file = new File(new File(DebuggingClassWriter.debugLocation), dirs + ".class");
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
out.write(b);
}
}
}
配置cglib.debugLocation可以在指定目录输出cglib代理类文件
查看后发现比通过类对象生成的香多了 瞬间发现生成类文件还是得找原滋原味的byte[]
看到System.getProperty("cglib.debugLocation"); 以为配置个cglib.debugLocation的环境变量就好了 折腾了半天没作用 发现它是个map获取了往里面添加了个配置 运行没问题 得到了想要的代理类文件 经过分析发现System有getProperty和getEnv方法 看名字就知道env是获取环境的 那就是获取系统环境变量的 getProperty获取属性的 即获取系统属性 存放的是一些系统配置信息 如当前用户名称和工作目录 系统名称 版本 java相关的配置信息等等 提供setProperty和setProperties设置系统属性 只要你想可以丢个Properties进去替换掉 环境变量虽然没有提供set方法 但是有反射这个java界的大流氓在 还怕添加不进去获取ProcessEnvironment的theEnvironment静态map字段 对就是要获取它别被烟雾弹theUnmodifiableEnvironment给蒙蔽了双眼 获取到了你想咋干就干 没人拦着你



