简体   繁体   English

ByteBuddy拦截对方法字节码内特定类实例的调用

[英]ByteBuddy intercept the calls toward specific class instances inside the bytecode of a method

I have a class A with a method m() and a class B with a method n(). 我有一个带有方法m()的类A和一个带有方法n()的类B. In AI have a field b of type B. In m() there is at some point a call to bn(). 在AI中有一个类型为B的字段b。在m()中,某些时候会调用bn()。 I need to change the code of A with ByteBuddy in order to do some action before and after the bn() call. 我需要使用ByteBuddy更改A的代码,以便在bn()调用之前和之后执行一些操作。 I need some advice/tips/hint to attack the problem. 我需要一些建议/提示/提示来解决问题。

Thanks in advance, 提前致谢,

Radu 拉杜

You can only do this in Byte Buddy by writing custom byte code using the underlying ASM API. 您只能通过使用基础ASM API编写自定义字节代码在Byte Buddy中执行此操作。 Byte Buddy does not offer any high-level constructs to alter any code within a method. Byte Buddy不提供任何高级构造来更改方法中的任何代码。

The API is exposed by registering an AsmVisitorWrapper. 通过注册AsmVisitorWrapper公开API。

Alternatively, you could create a subclass of Bn() where you add this interception logic and set it as the field of A. This would however affect all invokations via A. 或者,您可以创建Bn()的子类,您可以在其中添加此拦截逻辑并将其设置为A的字段。但是这将通过A影响所有调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ByteBuddy:如何在另一个类中使用自定义方法声明一个类 - ByteBuddy: How to declare a class with a custom method inside another class ByteBuddy 是否可以拦截由带有注释的接口声明的方法? - Is it possible with ByteBuddy to intercept a method that is declared by an interface with an annotation? ByteBuddy - 无法从超类拦截 static 方法 - ByteBuddy - unable to intercept static method from superclass 如何在现有类中定义新方法并使用 bytebuddy 在同一类中的现有方法中添加对它的调用? - How to define a new method inside an existing class and add a call to it in an existing method inside the same class using bytebuddy? 显示生成的bytebuddy字节码 - Display generated bytebuddy bytecode 在 ByteBuddy 中使用 @Advice.AllArguments 是否可以拦截没有 arguments 的方法? - Is it possible to intercept a method that has no arguments with using @Advice.AllArguments in ByteBuddy? 如何使用 ByteBuddy 拦截方法,就像在 CGLIB 中使用 MethodInterceptor 调用 MethodProxy.invokeSuper(...) - How to intercept method with ByteBuddy as in CGLIB with MethodInterceptor for calling MethodProxy.invokeSuper(…) ByteBuddy:在构造类期间在拦截中使用新定义的字段 - ByteBuddy: Use new defined field in intercept during construction of class 如何在ByteBuddy代理中检测/拦截Method.invoke? - How can I instrument/intercept Method.invoke in a ByteBuddy agent? Bytebuddy:是否可以通过用 lambda 表达式替换执行来拦截方法? - Bytebuddy: Is it possible to intercept a method by replacing the execution with a lambda expression?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM