I'm trying to redefine classes on the java.lang package such as String.class or Integer.class using ByteBuddy but with no success. My question is if that's even possible?
This is the code I'm trying in my java agent:
public static void premain(String agentArgs, Instrumentation inst) {
new AgentBuilder.Default()
.type(named("java.lang.String"))
.transform((builder, typeDescription, classLoader) ->
builder.method(named("toString"))
.intercept(FixedValue.value("toString() got hacked!")))
.with(AgentBuilder.Listener.StreamWriting.toSystemOut())
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.installOn(inst);
}
When I check the output of the logs and what I see regarding the String class is:
[Byte Buddy] IGNORE [[Ljava.lang.String; [null, null]
[Byte Buddy] COMPLETE [[Ljava.lang.String; [null, null]
Does this means that ByteBuddy is not redefining the String class? Is that even possible?
Many thanks.