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

[core] inlined classes are lot loaded #1379

Closed
oriori1703 opened this issue Feb 12, 2022 · 8 comments
Closed

[core] inlined classes are lot loaded #1379

oriori1703 opened this issue Feb 12, 2022 · 8 comments
Labels
bug Core Issues in jadx-core module
Milestone

Comments

@oriori1703
Copy link
Contributor

I find a lot of decomplication errors for inlined classes with the cause being that they are not loaded.
it seems to be an issue with double inlined classes (inlined classes inside and inlined classes ).

For example, X.B5o.A0s has the following decompiled code without inlining turned on:

public final void A0S() {
        C25733B5s b5s = new C25733B5s(this);
        C0VB r2 = this.A02;
        C26231BRr.A00(new B69(b5s, C2OS.A01(r2).A05()), r2);
    }

In it's first line it creates a new instance of X.B5s, which is only used there, therefore it is inlined when the option is on. and has only the method called Bfg, with the following code:

@Override // p000X.C8WH
    public final void Bfg() {
        C25729B5o b5o = this.A00;
        C209798zB.A0A(b5o.getContext(), new B64(b5o));
    }

In it's last line it creates a new instance of X.B64. This class is also only used there, so it is also inlined.
I think this double inline is what causes the issue.

  • full name of method or class with error: X.B5o.A0S
  • full java stacktrace (no need to copy method fallback code (commented pseudocode))
    • /* JADX ERROR: Method code generation error
      jadx.core.utils.exceptions.CodegenException: Error generate insn: 0x000b: INVOKE
      (wrap: android.content.Context : 0x0002: INVOKE (r1v0 android.content.Context A[REMOVE]) = (r2v0 'b5o' X.B5o) type: VIRTUAL call: androidx.fragment.app.Fragment.getContext():android.content.Context)
      (wrap: android.content.DialogInterface$OnClickListener : 0x0008: CONSTRUCTOR (r0v0 android.content.DialogInterface$OnClickListener A[REMOVE]) = (r2v0 'b5o' X.B5o A[DONT_INLINE]) call: X.B64.(X.B5o):void type: CONSTRUCTOR)
      type: STATIC call: X.8zB.A0A(android.content.Context, android.content.DialogInterface$OnClickListener):void in method: X.B5s.Bfg():void, file: classes4.dex
      at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:278)
      at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:241)
      at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:90)
      at jadx.core.dex.nodes.IBlock.generate(IBlock.java:15)
      at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:62)
      at jadx.core.dex.regions.Region.generate(Region.java:35)
      at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:62)
      at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:267)
      at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:260)
      at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:369)
      at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:304)
      at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$3(ClassGen.java:270)
      at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
      at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
      at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
      at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
      Caused by: jadx.core.utils.exceptions.JadxRuntimeException: Expected class to be processed at this point, class: X.B64, state: NOT_LOADED
      at jadx.core.dex.nodes.ClassNode.ensureProcessed(ClassNode.java:297)
      at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:676)
      at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:386)
      at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:140)
      at jadx.core.codegen.InsnGen.addArg(InsnGen.java:116)
      at jadx.core.codegen.InsnGen.addArg(InsnGen.java:103)
      at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:996)
      at jadx.core.codegen.InsnGen.makeInvoke(InsnGen.java:807)
      at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:390)
      at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:271)
      ... 15 more
      */

https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-192-0-0-35-123-release/

@oriori1703 oriori1703 added bug Core Issues in jadx-core module labels Feb 12, 2022
@skylot
Copy link
Owner

skylot commented Feb 12, 2022

@oriori1703 thanks for report!
Actually, I already saw these kinds of issue, but still not sure how to fix them.
Anyway, I will increase priority and will try to find a solution.

@skylot skylot added this to the TBD milestone Feb 12, 2022
@skylot
Copy link
Owner

skylot commented Feb 14, 2022

@oriori1703 fixed, at least for this case 😃

@skylot skylot closed this as completed Feb 14, 2022
@oriori1703
Copy link
Contributor Author

oriori1703 commented Feb 14, 2022

@skylot first of all thanks for the fix.
It indeed seemed to fix my issue, so I wanted to test in some other apps to be sure. Unfortunately, it seems that the fix is not fully working as expected.
When trying to decompile some apps with inlining turned on, I get a huge amount of NullPointerException that weren't there before the change.
For example in whatsapp 2.21.24.23 I get 164142 errors while before the fix I only got 100.
I don't have time to give you specific errors right now, but if you still need it tomorrow I get some for you.
Should I open a new issue for this?

Also, I noticed that Jadx uses a lot of memory while this APK (more than 16 GB). I'm not sure if this is related to this fix, but I'm pretty sure it's from a semi recent change, because it didn't happen before.

@skylot
Copy link
Owner

skylot commented Feb 14, 2022

I get 164142 errors while before the fix I only got 100

Sad 😕
Sure, I will try to fix regressions and check memory usage.
Thanks for feedback!

@skylot skylot reopened this Feb 14, 2022
@skylot
Copy link
Owner

skylot commented Feb 14, 2022

@oriori1703 I commit a fix to prevent endless loop. Anonymous classes with dependency loop will be not inlined and warning will be added ("Loop in anonymous inline"). This will resolve new errors :)

@skylot
Copy link
Owner

skylot commented Feb 14, 2022

This commit: af2f14f (added wrong issue number 😞 )

@skylot
Copy link
Owner

skylot commented Feb 15, 2022

And a few more improvements:

  • better performance of ternary mod for large methods. Reduce decompilation pauses in this sample
  • prevent several NPEs in try/catch/finally processing. This is not fixing root causes, but at least allows viewing inconsistent code.

@oriori1703 please check these changes.
I think I handle most of all critical issues in your sample, hope it helps 👍

@oriori1703
Copy link
Contributor Author

Yep, It seems you have fixed all of the errors I was experiencing after the fix, and the ram usage is way better.
Thanks for your help 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

2 participants