booster icon indicating copy to clipboard operation
booster copied to clipboard

请问,booster支持在transform过程中新增加类文件吗

Open pidanxiangjiao opened this issue 1 year ago • 3 comments

pidanxiangjiao avatar Jan 16 '25 02:01 pidanxiangjiao

不支持,你的需求是什么?

johnsonlee avatar Jan 16 '25 03:01 johnsonlee

目前想基于booster,将另一个aop框架lancet功能整合成一个 transformer(https://github.com/eleme/lancet) 在lancet 插桩过程中,针对一个class 处理,有返回多个class,会新增加class文件,例如新创建多个inner class,原框架是在 jos中直接写入新的 class的字节码数组数据

        void run(String relativePath, byte[] bytes) throws IOException {
            if (!relativePath.endsWith(".class")) {
                ZipEntry entry = new ZipEntry(relativePath);
                jos.putNextEntry(entry);
                jos.write(bytes);
            } else {
                for (ClassData classData : weaver.weave(bytes, relativePath)) { <---------- 开始插桩处理,有可能返回多个处理后的class
                    ZipEntry entry = new ZipEntry(classData.getClassName() + ".class");
                    jos.putNextEntry(entry);
                    jos.write(classData.getClassBytes());
                }
            }
        }
public interface Weaver{

    /**
     * Transform input class with specified rules.
     * Input one class may return two classes, because weaver may create multiple inner classes.  <---------- 插桩处理中,有可能返回多个处理后的class
     * this method will be invoke in multi-threaded and multi-process
     *
     * @param input the bytecode of the class want to transform.
     * @param relativePath the file path of the class, end with .class, the new classes will output into the same path.
     * @return the bytecode of transformed classes.
     */
    ClassData[] weave(byte[] input, String relativePath);
}

pidanxiangjiao avatar Jan 16 '25 06:01 pidanxiangjiao

可以尝试在LancetX上去除bytex,再接入booster。

yihuajia avatar May 20 '25 10:05 yihuajia