Closed rupinder10 closed 6 days ago
You can instrument obfuscated code, but your advice classes need to be excluded from obfuscation. The templating mechanism can otherwise no longer use the byte code as a template.
That is the strange part. I have excluded the particular Advice class and also the class that implements the transformer. Here is the setting used:
-keep,allowshrinking public class *AgentTransformer*, *AgentTransformer$* {
*** *;
*** *(...);
}
-keep,includedescriptorclasses public class com.nbl.advice.reflect.* {
*** *;
*** *(...);
}
If you open the jar, you can use javap to inspect class files. I suspect you'd get different output for advice with obfuscation active.
You are correct. But decompiling both the classes yields logically the same code except that the parameter names for the methods are different. Which I assume should not matter. But I might be wrong based on the logic used in bytebuddy.
I have attached the classes, their decompiled versions and their javap outputs.
The parameter names should not matter, but if the files are altered, the exclusion does not seem to work. I still expect that a full exclusion would do the trick.
The issue is that the advice classes are a part of a jar file and the rest of the classes in the jar need to be obfuscated. So I can't exclude one class in the jar. So the only thing I can do is to control how much gets obfuscated. So I configured proguard to keep the advice classes name, the method and field names and then parameter names too. But the instrumentation still doesnt work.
On Wed, Dec 20, 2023 at 6:02 PM Rafael Winterhalter < @.***> wrote:
The parameter names should not matter, but if the files are altered, the exclusion does not seem to work. I still expect that a full exclusion would do the trick.
— Reply to this email directly, view it on GitHub https://github.com/raphw/byte-buddy/issues/1573#issuecomment-1865254503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56UZ6V2HWY632TN2Q6O63YKNU7XAVCNFSM6AAAAABAY5U4H6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRVGI2TINJQGM . You are receiving this because you authored the thread.Message ID: @.***>
I have encountered this issue before. If I remember correctly, proguard regenerates stack frame information for branch code and exception blocks during the preverify
stage. The format of the regenerated information does not match what javac generates, even though it can pass JVM class verification. Currently byte-buddy still cannot properly recognize it.
You cannot configure proguard to ignore this with -keep
or similar because it happens during the preverify
stage rather than the obfuscate
stage. And if you configure proguard to skip verify behavior, you will typically get other strange errors that ultimately cause the obfuscated classes to fail JVM verification.
Ultimately, some known workarounds are:
maven-dependency-plugin
.ASMVisitorWrapper.writeFlags(ClassWriter.COMPUTE_FRAMES)
internally in the Transformer
, which will cause ASM to recompute the stack frame information. However this can fail and ultimately prevent successful transformation of the target method if some types are not visible.Thanks a lot for the detailed response. This makes sense. Because I have several advice files and the only ones that are failing are that have a if statement in the Advice code.
If I remove the if statement I dont get the error. I will try to repackage the jars to avoid this problem.
From: yuwen @.> Sent: Thursday, December 21, 2023 2:33 AM To: raphw/byte-buddy @.> Cc: Rupinder Singh @.>; Author @.> Subject: Re: [raphw/byte-buddy] Inconsistent frame length when instrumenting a method (Issue #1573)
I have encountered this issue before. If I remember correctly, proguard regenerates stack frame information for branch code and exception blocks during the preverify stage. The format of the regenerated information does not match what javac generates, even though it can pass JVM class verification. Currently byte-buddy still cannot properly recognize it.
You cannot configure proguard to ignore this with -keep or similar because it happens during the preverify stage rather than the obfuscate stage. And if you configure proguard to skip verify behavior, you will typically get other strange errors that ultimately cause the obfuscated classes to fail JVM verification.
Ultimately, some known workarounds are:
— Reply to this email directly, view it on GitHubhttps://github.com/raphw/byte-buddy/issues/1573#issuecomment-1865765266, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB56UZ65JKXF27ZYQR5IOFLYKPQ5RAVCNFSM6AAAAABAY5U4H6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRVG43DKMRWGY. You are receiving this because you authored the thread.Message ID: @.***>
I have a simple setup of instrumenting a method that is working perfectly.
The class and method being instrumented:
The issue is that I turned on obfuscation using proguard and started getting the error below:
The real problem is that I excluded any obfuscation for the AgentTransformer and the LoopAdvice classes and only obfuscated other classes. But the error still persists.
Looking for any suggestions on what would cause this error and what can proguard mess up even when these classes are excluded in the obfuscation.