Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.VerifyError: Expecting a stackmap frame at branch target 14 #411

Open
kodewithaayush opened this issue Jun 3, 2024 · 3 comments

Comments

@kodewithaayush
Copy link

Hi Team,

While obfuscation my Shadow Jar which is dependent on multiple modules I have added rule to keep class inside one package
-keep class com.service.** {
*;
}
Still I can see that proguard is modifying the byteCode irrespective of using above rule.

I have tried everything like
-dontshrink
-dontoptimize
-dontpreverify

also used
-keepattributes SourceFile,ConstantValue,LineNumberTable,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,StackMapTable,EnclosingMethod

ERROR BELOW:

java.lang.VerifyError: Expecting a stackmap frame at branch target 14
Exception Details:
Location:
com//service/Service.$getStaticMetaClass()Lgroovy/lang/MetaClass; @6: if_acmpeq
Reason:
Expected stackmap frame at this location.
Bytecode:
0000000: 2ab6 005e 1207 a500 082a b800 63b0 b200
0000010: 224c 2bc7 000f 2ab6 005e b800 6059 4cb3
0000020: 0022 2bb6 0061 b0

I believe Proguard should not change the byteCode of the class file if I use to -keep it using pro rule.

Sample Bytecode is attached showing obfuscated and original class file.

KryoFactory_getKryoInstance_closure1_obfuscate.txt
KryoFactory_getKryoInstance_closure1_original.txt

Could you please help me with the solution if I am missing something.
@kodewithaayush
Copy link
Author

kodewithaayush commented Jun 7, 2024

Update:

I was able to resolve this.
Now I am facing another issue while deserialization

I just want to obfuscate one package and want to keep rest of my classes as it is, still I guess proguard is modifying the byte code of the class I added as Keep in the pro rules.
java.lang.IllegalStateException: unread block data
at java.base/java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:3033)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1722)
at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2496)
at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2390)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2228)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1687)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:489)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:447)
at org.apache.spark.serializer.JavaDeserializationStream.readObject(JavaSerializer.scala:87)
at org.apache.spark.serializer.JavaSerializerInstance.deserialize(JavaSerializer.scala:129)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:507)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

sample.pro
-keep class java.** { ; }
-keep class kotlin.
* { ; }
-keep class groovy.
* { *; }

-keep interface java.** { ; }
-keep interface kotlin.
* { ; }
-keep interface groovy.
* { *; }

#-dontnote kotlin.**
#-dontnote kotlinx.**
#-dontnote com.google.gson.**

-keep class com.xxx.yyyy.service.* {
*;
}

-keep class com.xxx.yyyy.input.* {
;
}
-keep class com.xxx.yyyy.enrichstatement.result.
* {
*;
}

-keep class com.xxx.yyyy.enrichstatement.domain.entity.** {
;
}
-keep class com.xxx.yyyy.relationshipextraction.services.
{
;
}
-keep class com.xxx.yyyy.schema.
{
;
}
-keep class com.xxx.yyyy.sql.dictionary.
{
;
}
-keep class com.xxx.yyyy.extensions.
{
;
}
-keep class com.xxx.yyyy.relationshipextraction.domain.
{
*;
}

-keep interface com.xxx.yyyy.relationshipextraction.domain.* {
*;
}

-keep interface com.xxx.yyyy.relationshipextraction.services.* {
;
}
-keep,includedescriptorclasses,includecode class com.xxx.yyyy.serialization.kryo.
* {
*;
}

-keep enum ** {
*;
}

-keepclassmembers class ** {
static java.lang.String *;
}

-keepclassmembers class ** {
synthetic ;
synthetic ;
}
-keepparameternames

-keep class com.xxx.yyyy.commons.dictionary.* {
;
}
-keep class com.xxx.yyyy.provider.querylogprovider.
{
;
}
-keep class com.xxx.yyyy.enrichstatement.builder.domain.
{
;
}
-keep class com.xxx.yyyy.enrichstatement.expression.
{
;
}
-keep interface com.xxx.yyyy.enrichstatement.expression.
{
;
}
-keep public class com.xxx.yyyy.definitionExtraction.helper.
{
;
}
-keep public class com.xxx.yyyy.definitionExtraction.domain.
{
;
}
-keep public class com.xxx.yyyy.definitionExtraction.core.
{
;
}
-keep public class com.xxx.yyyy.calcite.
* {
*;
}
#Testing purpose

-keepattributes Signature
-keepattributes SourceFile,ConstantValue,LineNumberTable,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,StackMapTable,EnclosingMethod
-keepnames class **
-keepnames interface **
-keeppackagenames

-dontshrink
-dontoptimize
-ignorewarnings
-dontpreverify
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontusemixedcaseclassnames
-printconfiguration config-output.txt
-verbose
-forceprocessing
#-dontobfuscate
#-target 11
-printmapping proguard.map

Thanks in advance

@mrjameshamilton
Copy link
Collaborator

If you're running code on the JVM then you must preverify the classes: so you should remove -dontpreverify from the configuration.

If you enable any of shrinking, optimization or obfuscation, then the stackmap frames are removed at the beginning of ProGuard here.

The preverification is then executed at the end of ProGuard to recompute the stackmap frames after any modifications that ProGuard would have made due to shrinking, optimization or obfuscation here.

It's not clear how your problem is related to your configuration though. Can you provide a reproducible sample?

@nthieu90
Copy link

Hi @mrjameshamilton,
I tried to remove -dontpreverify, but the StackMapTable is still gone.
I'm using DexGuard 6.0.24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants