Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pidanxiangjiao opened this issue Jan 16, 2025 · 2 comments
Open

Comments

@pidanxiangjiao
Copy link

No description provided.

@johnsonlee
Copy link
Collaborator

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

@pidanxiangjiao
Copy link
Author

目前想基于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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants