0

Is there a tool/method in ASM to collect all the methods in a class and then replace the invocation of a class with those overloading methods?

I'm trying to use ASM with mutation testing to do these:

  • replace a method with its overloading methods
  • replace it with another method with the same parameters and return type (different name)
knt5784
  • 129
  • 1
  • 2
  • 16

1 Answers1

0

I don't know of any tool that does specifically what you want, but it shouldn't be hard to code.

For the second case, it's just a matter of searching for that method, and replacing the name, assuming you don't care about reflection or virtual calls.

For this, you can just implement MethodVistor.visitMethodInsn() and replace all the instructions with the desired (owner, name, desc) triple. Note that in the case of inheritance, owner might be different than what you expect. For example, suppose you are trying to replace Foo bar (II)V, and there is a subclass Child of Foo. In that case, the client code may invoke the method using the triple Child bar (II)V instead.

The first case is more challenging, because the overloaded methods presumably have different type descriptors, and hence you'll have to add bytecode to convert the arguments and/or return type to the right types. However, this is just a matter of reading the ASM documentation and then implementing it.

Antimony
  • 37,781
  • 10
  • 100
  • 107