Guardsquare / proguard

ProGuard, Java optimizer and obfuscator
https://www.guardsquare.com/en/products/proguard
GNU General Public License v2.0
2.85k stars 408 forks source link

Proguard replaces Methodref to InterfaceMethodref, but does not change instructions #48

Open xxDark opened 4 years ago

xxDark commented 4 years ago

Hello. We are using this awesome framework for our needs (https://github.com/SpongePowered/Mixin) and everything works fine.

However, Proguard breaks valid bytecode after obfuscation. Before Proguard:

00000000 : aload_0
00000001 : invokevirtual       java.util.List hh.a()
00000004 : areturn

cp After Proguard: cp2

We will attempt to fix that issue in Mixin framework, however, can Proguard: a) Also change instructions? b) Don't touch constant pool in that case? Thanks.

P.S The problem is that INVOKEVIRTUAL requires Methodref, not InterfaceMethodref. That change triggers JVM's verifier.

 java.lang.VerifyError: Illegal type at constant pool entry 6 in class hh
             Exception Details:
                Location:
                  hh.appendSibling(Lhh;)Lhh; @2: invokevirtual
                Reason:
                  Constant pool index 6 is invalid
                Bytecode:
                  0x0000000: 2a2b b600 06b0                         
                    at qs.a(Unknown Source)
                    at vi$a.<init>(Unknown Source)
                    at vi.a(Unknown Source)
                    at vi.c(Unknown Source)
                    at ni.c(Unknown Source)
                    at bib.<init>(Unknown Source)
xxDark commented 4 years ago

SpongePowered/Mixin#413

ingdas commented 4 years ago

Thanks for taking the time to report this to us. Would it be possible for you to provide us with a (minimal) example jar or source file to start from?

xxDark commented 4 years ago

proguard.zip java -cp . Test

ingdas commented 4 years ago

Thanks for that. Can you also give us the same classes in a version which isn't processed by ProGuard (and thus working?). That way we can trace the execution and find out where it goes wrong.

xxDark commented 4 years ago

Sure. proguard.zip

ingdas commented 4 years ago

I'll need to bother you once more. I can't replicate your error.

-injars ./pre
-outjars ./output.jar

-libraryjars <java.home>/lib/rt.jar

-keep class Test {
    <methods>;
}
xxDark commented 4 years ago

I guess that I provided not transformed class files, sorry. Try on these: dist.zip

xxDark commented 4 years ago

Configuration:

-injars app-merged.jar
-outjars dist/app-proguard.jar

-libraryjars libs
-libraryjars <java.home>/lib/rt.jar

-dontshrink
-dontobfuscate
-optimizations class/marking/*,method/marking/*,method/inlining/tailrecursion,code/*
-optimizationpasses 1
-allowaccessmodification
-printmapping roguard.map
-overloadaggressively
-repackageclasses ''
-keepattributes *Annotations*,*Signature*,LineNumberTable,SourceFile
-verbose

-keepclassmembers enum  * {
    <fields>;
    <methods>;
}

-keep class App {
    void main(java.lang.String[]);
}

# Keep - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * {
    native <methods>;
}