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] "IF instruction can be used only in fallback mode" error #843

Closed
bagipro opened this issue Feb 2, 2020 · 3 comments
Closed

[core] "IF instruction can be used only in fallback mode" error #843

bagipro opened this issue Feb 2, 2020 · 3 comments
Labels
bug Core Issues in jadx-core module

Comments

@bagipro
Copy link
Collaborator

bagipro commented Feb 2, 2020

Hi, class com.uc.base.util.file.c

Decompiled code

    /* JADX WARNING: type inference failed for: r0v4, types: [java.util.HashMap] */
    /* JADX WARNING: type inference failed for: r1v11, types: [java.util.HashMap, java.lang.Object] */
    /* JADX WARNING: type inference failed for: r0v17 */
    /*  JADX ERROR: IF instruction can be used only in fallback mode
        jadx.core.utils.exceptions.CodegenException: IF instruction can be used only in fallback mode
        	at jadx.core.codegen.InsnGen.fallbackOnlyInsn(InsnGen.java:581)
        	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:487)
        	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:250)
        	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:221)
        	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.makeIf(RegionGen.java:157)
        	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.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.makeRegionIndent(RegionGen.java:99)
        	at jadx.core.codegen.RegionGen.makeLoop(RegionGen.java:233)
        	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:67)
        	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:211)
        	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:204)
        	at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:322)
        	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:275)
        	at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$3(ClassGen.java:244)
        	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
        	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
        	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
        	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
        	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        	at jadx.core.codegen.ClassGen.addInnerClsAndMethods(ClassGen.java:240)
        	at jadx.core.codegen.ClassGen.addClassBody(ClassGen.java:231)
        	at jadx.core.codegen.ClassGen.addClassCode(ClassGen.java:115)
        	at jadx.core.codegen.ClassGen.makeClass(ClassGen.java:81)
        	at jadx.core.codegen.CodeGen.wrapCodeGen(CodeGen.java:45)
        	at jadx.core.codegen.CodeGen.generateJavaCode(CodeGen.java:34)
        	at jadx.core.codegen.CodeGen.generate(CodeGen.java:22)
        	at jadx.core.ProcessClass.generateCode(ProcessClass.java:61)
        	at jadx.core.dex.nodes.ClassNode.decompile(ClassNode.java:288)
        	at jadx.core.dex.nodes.ClassNode.decompile(ClassNode.java:267)
        */
    /* JADX WARNING: Code restructure failed: missing block: B:50:0x0057, code lost:
        r0 = r0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:52:0x0057, code lost:
        r0 = r0;
     */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Unknown variable types count: 1 */
    private void aE(java.lang.String r7, boolean r8) throws java.io.IOException {
        /*
            r6 = this;
            java.util.HashMap<java.lang.String, java.util.HashMap<java.lang.String, java.lang.String>> r0 = r6.Ig
            r0.clear()
            r0 = 0
            if (r8 == 0) goto L_0x0022
            android.content.Context r8 = com.uc.p156a.p157a.p158a.C2723a.PP     // Catch:{ all -> 0x001d }
            android.content.res.AssetManager r8 = r8.getAssets()     // Catch:{ all -> 0x001d }
            java.io.InputStream r7 = r8.open(r7)     // Catch:{ all -> 0x001d }
            java.util.List r8 = com.uc.p156a.p157a.p164g.C2767b.m4810g(r7)     // Catch:{ all -> 0x001a }
            com.uc.p156a.p157a.p164g.C2767b.m4805b(r7)
            goto L_0x002b
        L_0x001a:
            r8 = move-exception
            r0 = r7
            goto L_0x001e
        L_0x001d:
            r8 = move-exception
        L_0x001e:
            com.uc.p156a.p157a.p164g.C2767b.m4805b(r0)
            throw r8
        L_0x0022:
            java.io.File r8 = new java.io.File
            r8.<init>(r7)
            java.util.List r8 = com.uc.p156a.p157a.p164g.C2766a.m4798m(r8)
        L_0x002b:
            if (r8 == 0) goto L_0x00e9
            int r7 = r8.size()
            if (r7 <= 0) goto L_0x00e9
            r7 = 0
            java.lang.Object r1 = r8.get(r7)
            java.lang.String r1 = (java.lang.String) r1
            r2 = 1
            if (r1 == 0) goto L_0x0053
            int r3 = r1.length()
            if (r3 <= 0) goto L_0x0053
            r3 = 65279(0xfeff, float:9.1475E-41)
            char r4 = r1.charAt(r7)
            if (r3 != r4) goto L_0x0053
            java.lang.String r1 = r1.substring(r2)
            r8.set(r7, r1)
        L_0x0053:
            java.util.Iterator r8 = r8.iterator()
        L_0x0057:
            boolean r1 = r8.hasNext()
            if (r1 == 0) goto L_0x00e9
            java.lang.Object r1 = r8.next()
            java.lang.String r1 = (java.lang.String) r1
            java.lang.String r1 = r1.trim()
            boolean r3 = com.uc.p156a.p157a.p170l.C2785a.cs(r1)
            if (r3 != 0) goto L_0x0057
            int r3 = r1.length()
            r4 = 2
            if (r3 < r4) goto L_0x0057
            char r3 = r1.charAt(r7)
            r4 = 91
            if (r3 != r4) goto L_0x00ad
            int r3 = r1.length()
            int r3 = r3 - r2
            char r3 = r1.charAt(r3)
            r4 = 93
            if (r3 != r4) goto L_0x00ad
            java.lang.String r0 = "["
            java.lang.String r3 = ""
            java.lang.String r0 = r1.replace(r0, r3)
            java.lang.String r0 = r0.trim()
            java.lang.String r1 = "]"
            java.lang.String r3 = ""
            java.lang.String r0 = r0.replace(r1, r3)
            java.lang.String r0 = r0.trim()
            java.util.HashMap r1 = new java.util.HashMap
            r1.<init>()
            java.util.HashMap<java.lang.String, java.util.HashMap<java.lang.String, java.lang.String>> r3 = r6.Ig
            r3.put(r0, r1)
            r0 = r1
            goto L_0x0057
        L_0x00ad:
            r3 = 61
            int r3 = r1.indexOf(r3)
            if (r3 <= 0) goto L_0x0057
            if (r0 != 0) goto L_0x00c3
            java.util.HashMap r0 = new java.util.HashMap
            r0.<init>()
            java.util.HashMap<java.lang.String, java.util.HashMap<java.lang.String, java.lang.String>> r4 = r6.Ig
            java.lang.String r5 = "Default"
            r4.put(r5, r0)
        L_0x00c3:
            java.lang.String r4 = r1.substring(r7, r3)
            if (r4 == 0) goto L_0x00ce
            java.lang.String r4 = r4.trim()
            goto L_0x00d0
        L_0x00ce:
            java.lang.String r4 = ""
        L_0x00d0:
            int r3 = r3 + 1
            java.lang.String r1 = r1.substring(r3)
            if (r1 == 0) goto L_0x00e4
            java.lang.String r1 = r1.trim()
            java.lang.String r3 = "\""
            java.lang.String r5 = ""
            java.lang.String r1 = r1.replace(r3, r5)
        L_0x00e4:
            r0.put(r4, r1)
            goto L_0x0057
        L_0x00e9:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.uc.base.util.file.C3892c.aE(java.lang.String, boolean):void");
    }

APK: https://drive.google.com/file/d/1ALQhK675Y2GTFK-aExkzD_V8wAApSBaH/view?usp=sharing

@bagipro bagipro added bug Core Issues in jadx-core module labels Feb 2, 2020
@jackwpa
Copy link

jackwpa commented Feb 2, 2020

I checked with JEB 3.11.1 to see if any incongruities were reported. It does not seem to be the case.

    private void aE(String filename, boolean isAsset) throws IOException {
        List contents;
        InputStream v7;
        this.Ig.clear();
        Closeable v0 = null;
        if(isAsset) {
            try {
                v7 = a.PP.getAssets().open(filename);
            }
            catch(Throwable v8) {
                b.b(v0);
                throw v8;
            }

            try {
                contents = b.g(v7);
            }
            catch(Throwable v8) {
                v0 = v7;
                b.b(v0);
                throw v8;
            }

            b.b(v7);
        }
        else {
            contents = com.uc.a.a.g.a.m(new File(filename));
        }

        if(contents != null && contents.size() > 0) {
            String v1 = (String)contents.get(0);
            if(v1 != null && v1.length() > 0 && 0xFEFF == v1.charAt(0)) {
                contents.set(0, v1.substring(1));
            }

            for(Object line0: contents) {
                String line = ((String)line0).trim();
                if((com.uc.a.a.l.a.cs(line)) || line.length() < 2) {
                    continue;
                }

                if(line.charAt(0) == 0x5B && line.charAt(line.length() - 1) == 0x5D) {
                    String v0_1 = line.replace("[", "").trim().replace("]", "").trim();
                    HashMap v1_3 = new HashMap();
                    this.Ig.put(v0_1, v1_3);
                    v0 = v1_3;
                    continue;
                }

                int v3 = line.indexOf(61);
                if(v3 <= 0) {
                    continue;
                }

                if(((HashMap)v0) == null) {
                    v0 = new HashMap();
                    this.Ig.put("Default", v0);
                }

                String v4 = line.substring(0, v3);
                String v4_1 = v4 == null ? "" : v4.trim();
                String v1_4 = line.substring(v3 + 1);
                if(v1_4 != null) {
                    v1_4 = v1_4.trim().replace("\"", "");
                }

                ((HashMap)v0).put(v4_1, v1_4);
            }
        }
    }

@bagipro
Copy link
Collaborator Author

bagipro commented Feb 4, 2020

@skylot
Thanks. The bug seems to be fixed.
There are still some printed warnings

    /* JADX WARN: Failed to insert an additional move for type inference into block B:49:0x0057 */
    /* JADX WARN: Failed to insert an additional move for type inference into block B:47:0x0057 */
    /* JADX WARN: Failed to insert an additional move for type inference into block B:53:0x0057 */
    /* JADX INFO: additional move instructions added (1) to help type inference */
    /* JADX WARN: Type inference failed for: r0v1 */
    /* JADX WARN: Type inference failed for: r0v2 */
    /* JADX WARN: Type inference failed for: r0v3 */
    /* JADX WARN: Type inference failed for: r0v4, types: [java.util.HashMap] */
    /* JADX WARN: Type inference failed for: r0v11 */
    /* JADX WARN: Type inference failed for: r0v12, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r0v14 */
    /* JADX WARNING: Multi-variable type inference failed */

But the method is at least present

@bagipro bagipro closed this as completed Feb 4, 2020
@skylot
Copy link
Owner

skylot commented Feb 4, 2020

@jackwpa actually a problem here in variable types. In JEB code check v0 = new HashMap(); while v0 is defined as Closeable v0 = null;. The problem here similar to this test. But jadx was trying to fix that by inserting additional move instructions and that fail method restructure. I made a commit with additional checks before move insertion, but type inference still failing and code will be shown only with Show inconsistent code options.

@sergey-wowwow I just made I fix for regression, but there are still some issues like InputStream inputStream = 0; and also a problem I mention above.

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

3 participants