skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.98k stars 4.9k forks source link

java.lang.IllegalArgumentException: newPosition > limit: (67079825 > 8454316) #1653

Closed janecms closed 2 months ago

janecms commented 2 years ago

version 1.4.4

The Error info / JADX WARN: Failed to parse debug info java.lang.IllegalArgumentException: newPosition > limit: (67079825 > 8454316) at java.base/java.nio.Buffer.createPositionException(Unknown Source) at java.base/java.nio.Buffer.position(Unknown Source) at java.base/java.nio.ByteBuffer.position(Unknown Source) at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82) at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84) at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118) at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:564) at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39) /

Now, I think how to resole this question. Thanks

skylot commented 2 years ago

Now, I think how to resole this question.

@janecms do you want to prepare a PR for that issue? PR is always welcome :slightly_smiling_face: Anyway, it will be nice to provide a sample, so we can reproduce/check this issue.

sulab999 commented 2 years ago

how to resole??

jpstotz commented 2 years ago

@sulab999 @janecms The best way to resolve an issue that is caused by a certain DEX/APK files is providing the APK file.

@janecms In your original post you wrote Now, I think how to resole this question. Most people would interpret this sentence this way "I think now I know what changes needed to be done in Jadx to resolve this issue in Jadx". Thus skyot proposed to you to open a PR. If this sentence was meant in a different way please tell it to us.

sulab999 commented 2 years ago

this apk https://www.amazon.com/clouddrive/share/jADAfCDcUu9dEnrxSUwe0MS3aCCVg7CBGWvthsD90mk

ya121y commented 9 months ago

Hey there! any updates about this?

skylot commented 9 months ago

@ya121y we still do not have sample to reproduce this issue. Sample provided by @sulab999 not having this exact issue (checked with latest unstable build).

@ya121y if you can share a sample please open a new issue, I will close this one because it is old and useless now.

draekko commented 2 months ago

I know this was closed for lack of info but am getting it with the coospo CoospoRide app (current app com.onecoder.coosporide v2.5.31 does as well as prior versions). Was trying to figure out how it talks to my ble hardware but nothing gets decoded. App can be had off the Play store or from apkpure https://apkpure.com/coosporide/com.onecoder.coosporide

One example error message from one of the fragment classes, but this seems to happen with pretty much all the classes.

`/ JADX WARN: Failed to parse debug info java.lang.IllegalArgumentException: newPosition > limit: (67042708 > 8843904) at java.base/java.nio.Buffer.createPositionException(Buffer.java:318) at java.base/java.nio.Buffer.position(Buffer.java:293) at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094) at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82) at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84) at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118) at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626) at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39) /

@Override // androidx.fragment.app.Fragment  
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {  
    return null;  
}  
`
jpstotz commented 2 months ago

@draekko Thanks for providing a sample app. Which Jadx version have you used when the posted error occurred?

I wasn't able to reproduce your problem using Jadx 1.5.0 and also not with latest stable version decompiling androidx.fragment.app.Fragment of CoospoRide_2.5.31_APKPure.apk (SHA-1 hash 9F8D9CFED84E2514EBE644235B289E26A914C41D).

draekko commented 2 months ago

I tried 1.5.0 release which i've been using since it was released and tried the latest unstable build this morning.

Java says this

openjdk 21.0.4 2024-07-16 OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu224.04) OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)

Using it on latest Ubuntu 24.04.1 LTS

draekko commented 2 months ago

hmmm seems to have a different hash as the one i extracted off the device which i got it via the play store using aurora store for v2.5.31.

7a14391791d3d9666bc784083dabd109f1a3aa8f

draekko commented 2 months ago

Same issue with the one from apkpure version locally, same has from the version i downloaded there.

when i open up com.onecoder.coosporide.main.ChartFragment i get this for one example.

package com.onecoder.coosporide.main;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.onecoder.coosporide.databinding.ChartFragmentBinding;
import kotlin.Deprecated;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;

/* compiled from: ChartFragment.kt */
@Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0007\u0018\u0000 \u00142\u00020\u0001:\u0001\u0014B\u0005\u00a2\u0006\u0002\u0010\u0002J\u0016\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\bJ\u0012\u0010\n\u001a\u00020\u000b2\b\u0010\f\u001a\u0004\u0018\u00010\rH\u0017J&\u0010\u000e\u001a\u0004\u0018\u00010\u000f2\u0006\u0010\u0010\u001a\u00020\u00112\b\u0010\u0012\u001a\u0004\u0018\u00010\u00132\b\u0010\f\u001a\u0004\u0018\u00010\rH\u0016R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082.\u00a2\u0006\u0002\n\u0000\u00a8\u0006\u0015"}, d2 = {"Lcom/onecoder/coosporide/main/ChartFragment;", "Landroidx/fragment/app/Fragment;", "()V", "binding", "Lcom/onecoder/coosporide/databinding/ChartFragmentBinding;", "createCircleGradientDrawable", "Landroid/graphics/drawable/Drawable;", "startColor", "", "endColor", "onActivityCreated", "", "savedInstanceState", "Landroid/os/Bundle;", "onCreateView", "Landroid/view/View;", "inflater", "Landroid/view/LayoutInflater;", "container", "Landroid/view/ViewGroup;", "Companion", "app_prdRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
/* loaded from: classes6.dex */
public final class ChartFragment extends Fragment {
    private ChartFragmentBinding binding;

    /* renamed from: Companion, reason: from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);
    public static final int $stable = 8;

    /* compiled from: ChartFragment.kt */
    @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002\u00a2\u0006\u0002\u0010\u0002J\u0006\u0010\u0003\u001a\u00020\u0004\u00a8\u0006\u0005"}, d2 = {"Lcom/onecoder/coosporide/main/ChartFragment$Companion;", "", "()V", "newInstance", "Lcom/onecoder/coosporide/main/ChartFragment;", "app_prdRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
    /* loaded from: classes6.dex */
    public static final class Companion {
        /* JADX WARN: Failed to parse debug info
        java.lang.IllegalArgumentException: newPosition > limit: (67042716 > 8843904)
            at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
            at java.base/java.nio.Buffer.position(Buffer.java:293)
            at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
            at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
            at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
            at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
            at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
            at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
         */
        private Companion() {
        }

        /* JADX WARN: Failed to parse debug info
        java.lang.IllegalArgumentException: newPosition > limit: (67042715 > 8843904)
            at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
            at java.base/java.nio.Buffer.position(Buffer.java:293)
            at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
            at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
            at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
            at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
            at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
            at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
         */
        public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
        }

        /* JADX WARN: Failed to parse debug info
        java.lang.IllegalArgumentException: newPosition > limit: (67042714 > 8843904)
            at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
            at java.base/java.nio.Buffer.position(Buffer.java:293)
            at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
            at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
            at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
            at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
            at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
            at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
         */
        public final ChartFragment newInstance() {
            return null;
        }
    }

    /* JADX WARN: Failed to parse debug info
    java.lang.IllegalArgumentException: newPosition > limit: (67042710 > 8843904)
        at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
        at java.base/java.nio.Buffer.position(Buffer.java:293)
        at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
        at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
        at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
        at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
        at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
        at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
     */
    public final Drawable createCircleGradientDrawable(int startColor, int endColor) {
        return null;
    }

    /* JADX WARN: Failed to parse debug info
    java.lang.IllegalArgumentException: newPosition > limit: (67042709 > 8843904)
        at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
        at java.base/java.nio.Buffer.position(Buffer.java:293)
        at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
        at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
        at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
        at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
        at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
        at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
     */
    @Override // androidx.fragment.app.Fragment
    @Deprecated(message = "Deprecated in Java")
    public void onActivityCreated(Bundle savedInstanceState) {
    }

    /* JADX WARN: Failed to parse debug info
    java.lang.IllegalArgumentException: newPosition > limit: (67042708 > 8843904)
        at java.base/java.nio.Buffer.createPositionException(Buffer.java:318)
        at java.base/java.nio.Buffer.position(Buffer.java:293)
        at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1094)
        at jadx.plugins.input.dex.sections.SectionReader.absPos(SectionReader.java:82)
        at jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser.process(DebugInfoParser.java:84)
        at jadx.plugins.input.dex.sections.DexCodeReader.getDebugInfo(DexCodeReader.java:118)
        at jadx.core.dex.nodes.MethodNode.getDebugInfo(MethodNode.java:626)
        at jadx.core.dex.visitors.debuginfo.DebugInfoAttachVisitor.visit(DebugInfoAttachVisitor.java:39)
     */
    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return null;
    }
}
draekko commented 2 months ago

Does jadx use JAVA_HOME or does it use the default path for the jdk?

Edit: nevermind i figured out it does :)

I just tried 11, 17, and 21 for openjdk java version, same results.

jpstotz commented 2 months ago

Verified - com.onecoder.coosporide.main.ChartFragment causes multiple errors like java.lang.IllegalArgumentException: newPosition > limit: (67042709 > 8843904) in APK CoospoRide_2.5.31_APKPure.apk (SHA-1 hash 9F8D9CFED84E2514EBE644235B289E26A914C41D) from https://apkpure.com/coosporide/com.onecoder.coosporide

Tested with latest unstable Jadx-gui version.

draekko commented 2 months ago

As far as i can tell all the classes under com.onecoder.coosporide.* seem to be having the issue.

jackwpa commented 2 months ago

It is likely to be caused by NOP padding in the method bytecode, after the return instruction. It can be seen below with JEB, with the "Show instructions in gap" option enabled.

image

skylot commented 2 months ago

@draekko, @jpstotz thanks for sample and issue confirm

This issue caused by incorrect debug info offset in dex method code section. (Check DEX format docs https://source.android.com/docs/core/runtime/dex-format#code-item for debug_info_off field.) Looks like it was corrupted intentionally to disrupt decompilation or disassemble. Anyway, such incorrect data clearly reported by ApkTool/Smali like this:

Lcom/onecoder/coosporide/main/ChartFragment;->createCircleGradientDrawable(II)Landroid/graphics/drawable/Drawable;: Invalid debug offset

So I also commit a similar check and now instead of error with stacktrace, simple warning is added:

    /* JADX WARN: Invalid debug info offset */
    public final Drawable createCircleGradientDrawable(int startColor, int endColor) {
        return null;
    }

Funny that here argument names comes from Kotlin metadata, which are not removed :rofl:

draekko commented 2 months ago

Just tried apktool and all the smali code is nop'ed out as jackpwa mentioned, any suggestions on how i might go about to retrieve the code? Thanks in advance

skylot commented 2 months ago

any suggestions on how i might go about to retrieve the code?

@draekko looks like this is not possible using only static analysis tools like jadx, so you also need a dynamic/runtime tool like frida to catch dex files restored/decrypted at runtime. ApkId report that this apk uses Ijiami packer, so you can try to search guides to fight it.

draekko commented 2 months ago

Thanks for the suggestion, will look into them.