#How to inject a method at runtime? (only needs to be accessed via reflection)

1 messages · Page 1 of 1 (latest)

hollow pivot
#

Due to changes in an API that I don't control and a very common reflection-based usage of said API, to patch some crashes I need to inject a method into a class during runtime that is restricted from being altered via ASM. It's a whole thing, I don't want to get into it.

Is there any way to inject a method (or even just pretend that there's a method there for people using reflective access, even if it doesn't have any behavior attached to it) without ASM?

However this happens, it's going to be illegal and unsafe, and I am aware of this. I'm trying to soft-patch a bytecode manipulation framework, so there isn't any legal way to do it.

crimson basinBOT
#

This post has been reserved for your question.

Hey @hollow pivot! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

charred seal
#

at runtime? difficult to say the least

#

adding methods to an existing class is illegal via the hotswapping and class dedefinition spec

#

you'd have to add the method before the class is even loaded

#

eg from a custom classloader or directly on the disk

#

and then, you'd need asm or a similar library to parse the classfile, add the method and write it back to define the class

#

if you just need to pass a Method reference, you could make a new pseudo-class and use that to define an entirely new class and with that an entirely new method at runtime, that'd work, but it'd still need asm or a similar library