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

MOVE_RESULT instruction [core] #1046

Closed
danmaster2 opened this issue Dec 10, 2020 · 6 comments
Closed

MOVE_RESULT instruction [core] #1046

danmaster2 opened this issue Dec 10, 2020 · 6 comments
Labels
bug Core Issues in jadx-core module

Comments

@danmaster2
Copy link

Some Issue with MOVE_RESULT instructions, Below is two examples.

Using 1.2.0-b1435-e7598d43

EX 1

  /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    /*  JADX ERROR: MOVE_RESULT instruction can be used only in fallback mode
        jadx.core.utils.exceptions.CodegenException: MOVE_RESULT instruction can be used only in fallback mode
        	at jadx.core.codegen.InsnGen.fallbackOnlyInsn(InsnGen.java:604)
        	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:542)
        	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:230)
        	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:119)
        	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:103)
        	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:806)
        	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:663)
        	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:363)
        	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:249)
        	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:217)
        	at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:110)
        	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:56)
        	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
        	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
        	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
        	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
        	at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:246)
        	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:239)
        	at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:341)
        	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:294)
        	at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$2(ClassGen.java:263)
        	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)
        */

EX 2

/* JADX INFO: super call moved to the top of the method (can break code semantics) */
   /*  JADX ERROR: MOVE_RESULT instruction can be used only in fallback mode
       jadx.core.utils.exceptions.CodegenException: MOVE_RESULT instruction can be used only in fallback mode
       	at jadx.core.codegen.InsnGen.fallbackOnlyInsn(InsnGen.java:604)
       	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:542)
       	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:230)
       	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:119)
       	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:103)
       	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:806)
       	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:663)
       	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:363)
       	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:230)
       	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:119)
       	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:103)
       	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:428)
       	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:249)
       	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:217)
       	at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:110)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:56)
       	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
       	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:99)
       	at jadx.core.codegen.RegionGen.makeSwitch(RegionGen.java:274)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
       	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
       	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:99)
       	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:143)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:63)
       	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
       	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:93)
       	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:59)
       	at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:246)
       	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:239)
       	at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:341)
       	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:294)
       	at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$2(ClassGen.java:263)
       	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)
       */
@danmaster2 danmaster2 added Core Issues in jadx-core module bug labels Dec 10, 2020
@jpstotz
Copy link
Collaborator

jpstotz commented Dec 10, 2020

Can you please provide the apk/jar/... and name the class + method that caused these problems?

@nitram84
Copy link
Contributor

Here is a very basic example how to get those errors:

public class MoveResultTest {
  public void setListener(final Listener l) {}

  public interface Listener {
    void onEvent();
  }

  public void testMoveResultError() {
    this.setListener(() -> {
    });
  }
}

This sample can be used for unit tests.

@danmaster2
Copy link
Author

Yea Nitram84 is spot on, I can not share the source files as they are private but I can share bits of code or bytecode. Thanks for being so active, I have a few more examples that I will put some code to,

@danmaster2
Copy link
Author

I also had an issue from the same program
/* JADX ERROR: JadxRuntimeException in pass: RegionMakerVisitor jadx.core.utils.exceptions.JadxRuntimeException: Failed to find switch 'out' block at jadx.core.dex.visitors.regions.RegionMaker.processSwitch(RegionMaker.java:821) at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:157) at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:94) at jadx.core.dex.visitors.regions.RegionMaker.processIf(RegionMaker.java:731) at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:152) at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:94) at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:50) */

I was able to get some other programs to give bytecode but none worked, I will ask the Author if I am able to share the entire program.

Bytecode Ex1

         TryCatch: L1 to L2 handled by L3: Type is null.
         TryCatch: L3 to L4 handled by L3: Type is null.
         TryCatch: L4 to L5 handled by L6: Type is null.
         TryCatch: L7 to L8 handled by L8: Type is null.
         TryCatch: L7 to L8 handled by L6: java/lang/EnumConstantNotPresentException
         TryCatch: L9 to L8 handled by L7: java/lang/ArithmeticException
         TryCatch: L9 to L8 handled by L6: Type is null.
         TryCatch: L7 to L8 handled by L6: java/lang/IllegalStateException
             invokedynamic a.a(IIIIIIIIIIIIIIIIIIIIIIII)Ljava/lang/Throwable; : safe()Z
             pop
         L10 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[0]: null)
             goto L1
         }
         L6 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/Throwable)
             dup
             ifnull L4
             athrow
         }
         L1 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[0]: null)
             aconst_null
             getstatic one/two/three/0v.7:int
             ifeq L3
             checkcast a
         }
         L2 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/Object)
             pop
             aload0 // reference to self
             getfield one/two/three/c.c:java.util.List
             aload1
             goto L9
         }
         L7 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/ArithmeticException)
             athrow
         }
         L9 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[2]: java/util/List, java/util/UUID)
             invokeinterface java/util/List.contains(Ljava/lang/Object;)Z
             goto L11
         }
         L8 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/Throwable)
             athrow
         }
         L11 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: 1)
             ireturn
         }
         L3 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/Throwable)
             dup
             ifnull L2
             athrow
         }
         L4 {
             f_new (Locals[2]: one/two/three/c, java/util/UUID) (Stack[1]: java/lang/Throwable)
             aconst_null
             athrow
         }
         L5 {
         }
     }```


**Bytecode Ex2**

Byte code:
0: getstatic onetwothree0v.e : I
3: ifgt -> 17
6: while : ()V
11: fuck : ()Z
16: pop
17: goto -> 25
20: dup
21: ifnull -> 61
24: athrow
25: aconst_null
26: getstatic onetwothree0v.7 : I
29: ifeq -> 56
32: checkcast a
35: pop
36: aload #0
38: getfield c : LjavautilList;
41: aload_1
42: goto -> 46
45: athrow
46: invokeinterface contains : (LjavalangObject;)Z
51: goto -> 55
54: athrow
55: ireturn
56: dup
57: ifnull -> 35
60: athrow
61: aconst_null
62: athrow
Exception table:
from to target type
25 35 56 finally
45 54 54 finally
45 54 20 javalangEnumConstantNotPresentException
45 54 20 javalangIllegalStateException
46 54 45 javalangArithmeticException
46 54 20 finally
56 61 56 finally
61 63 20 finally
``

I am pretty sure that this has something to do with Chained For and catch loops, I hope to be able to share the source code. Thanks

@skylot
Copy link
Owner

skylot commented Dec 11, 2020

@danmaster2 actually this is a known issue.
Jadx for now does not support instructions needed for lambda execution, because these are used very rare in android app (for backward compatibility d8 desugar them to anonymous classes). List of unsupported instructions can be found in issues #384 and #385.
Another issue here that decoding error shown only in logs and not attached to method code. I made a fix for error reporting so now you can see original source of the issue: decode failed: Unknown instruction: '0x0000: INVOKE_CUSTOM '

@skylot skylot closed this as completed Dec 11, 2020
@lazyguoguo
Copy link

@danmaster2 actually this is a known issue.
Jadx for now does not support instructions needed for lambda execution, because these are used very rare in android app (for backward compatibility d8 desugar them to anonymous classes). List of unsupported instructions can be found in issues #384 and #385.
Another issue here that decoding error shown only in logs and not attached to method code. I made a fix for error reporting so now you can see original source of the issue: decode failed: Unknown instruction: '0x0000: INVOKE_CUSTOM '

https://github.com/GraxCode/threadtear supports all instructions

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

5 participants