byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

Bytebuddy and obfuscator are incompatible

Open sgy-zihan opened this issue 4 years ago • 5 comments

[2021-12-30 09:16:24] [36804:xxx-logger] DEBUG cn.xsg.esp.j.c: onError(): { typeName=org.apache.catalina.core.StandardWrapper, classLoader=java.net.URLClassLoader@5b22b970, module=null, loaded=false } Execption: java.lang.IllegalStateException: public static void cn.xsg.esp.j.l$b.a(java.lang.String,java.lang.String,java.lang.Object[]) dropped 3 implicit frames at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$StackMapFrameHandler$Default.translateFrame(SourceFile:5614) at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$StackMapFrameHandler$Default$WithPreservedArguments.translateFrame(SourceFile:5985) at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$StackMapFrameHandler$Default$ForAdvice.translateFrame(SourceFile:6347) at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$Dispatcher$Inlining$CodeTranslationVisitor.visitFrame(SourceFile:8730) at cn.xsg.esp.thirdparty.net.bytebuddy.jar.asm.MethodVisitor.visitFrame(SourceFile:300) at cn.xsg.esp.thirdparty.net.bytebuddy.jar.asm.ClassReader.readCode(SourceFile:2039) at cn.xsg.esp.thirdparty.net.bytebuddy.jar.asm.ClassReader.readMethod(SourceFile:1481) at cn.xsg.esp.thirdparty.net.bytebuddy.jar.asm.ClassReader.accept(SourceFile:711) at cn.xsg.esp.thirdparty.net.bytebuddy.jar.asm.ClassReader.accept(SourceFile:394) at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.apply(SourceFile:7821) at cn.xsg.esp.thirdparty.net.bytebuddy.asm.Advice$AdviceVisitor.onAfterExceptionTable(SourceFile:9955) at cn.xsg.esp.thirdparty.net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor.considerEndOfExceptionTable(SourceFile:49)

I use a variety of obfuscators to try to obfuscate, but each one will expose a stack frame loss error. How can I fix it?
Is there a compatible obfuscation plugin for ByteBuddy ?
Execption: java.lang.IllegalStateException: public static void cn.xsg.esp.j.l$b.a(java.lang.String,java.lang.String,java.lang.Object[]) dropped 3 implicit frames

sgy-zihan avatar Dec 30 '21 01:12 sgy-zihan

Could you run your application with -Dnet.bytebuddy.dump=/some/folder and get the original and transformed class file and attach both to this ticket?

raphw avatar Dec 30 '21 05:12 raphw

The reason is that I use the root loader to load an abstract class (Dispatcher), then use the system class loader to load the implementation class of the interface (DispatcherImpl), and finally use reflection to bridge into properties in an abstract class (singleton design pattern) to achieve the purpose of the Hook JDK
When I'm not confused, the code works fine, but when I'm confused, it will report an error, which I can reproduce using Progurad, which will report an error 100% of the time
I can't solve this problem and need some help

1057105012 avatar Jan 04 '22 08:01 1057105012

I would need to see the original and transformed byte code to understand what pattern triggers the error. It seems like there are frames dropped when Byte Buddy would expect them to be appended. That's why I asked to run with the above option.

Alternatively, you can specify ClassWriter.COMPUTE_FRAMES in the class visitor wrapper.

raphw avatar Jan 04 '22 08:01 raphw

It was reported as an error during the bytecode conversion phase, so it was not generated by the ByteBuddy conversion class, so there is no enhanced class generation, can not dump I tested yesterday that once I used a control statement like ({},if , for) and obfuscated code, it would return to normal after it was removed This is a small example of an exception that can be raised https://github.com/1057105012/learn-demo.git

  • java -javaagent:/usr/local/demo-1.0-SNAPSHOT-pg.jar -jar demo-1.0-SNAPSHOT-pg.jar This command will raise the above exception

  • java -javaagent:/usr/local/demo-1.0-SNAPSHOT.jar -jar demo-1.0-SNAPSHOT.jar This command is normal

1057105012 avatar Jan 05 '22 08:01 1057105012

You are using a rather old version of Byte Buddy (1.10.19). Could you first try with the latest version?

raphw avatar Jan 06 '22 19:01 raphw