skylot / jadx

Dex to Java decompiler
Apache License 2.0
40.09k stars 4.75k forks source link

[core] Miss of casts among primitive types #921

Open bagipro opened 4 years ago

bagipro commented 4 years ago

Hi, a small test case for the issue in kotlin.NumbersKt__NumbersKt

    public static final byte rotateLeft(byte b, int i) {
        byte b2 = i & 7; // missing cast
        return (byte) (((b & 255) >>> (8 - b2)) | (b << b2));
    }

    public static final short rotateLeft(short s, int i) {
        short s2 = i & 15; // missing cast
        return (short) (((s & 65535) >>> (16 - s2)) | (s << s2));
    }

    public static final byte rotateRight(byte b, int i) {
        byte b2 = i & 7; // missing cast
        return (byte) (((b & 255) >>> b2) | (b << (8 - b2)));
    }

    public static final short rotateRight(short s, int i) {
        short s2 = i & 15; // missing cast
        return (short) (((s & 65535) >>> s2) | (s << (16 - s2)));
    }

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

bagipro commented 3 years ago

@skylot May you please also fix this one too?

skylot commented 3 years ago

@sergey-wowwow I commit a fix, hope it will resolve some cases.

bagipro commented 3 years ago

@skylot I've noticed a different error. Class com.ebay.mobile.common.RefineContentFragment

    /* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: boolean */
    /* JADX WARN: Multi-variable type inference failed */
    private void setRefineVisible(boolean z) {
        if (this.isRefineEnabled) {
            this.refineButton.setVisibility(z != 0 ? 0 : 8); // <<< should be only "z ? 0 : 8"
            this.drawerLayout.setDrawerLockMode(!z);
        }
    }
skylot commented 3 years ago

@sergey-wowwow thanks!

bagipro commented 3 years ago

@skylot And one more thing in kotlinx.coroutines.CompletedExceptionally

    private volatile int _handled;
    /* JADX WARN: Type inference failed for: r0v0, types: [int, boolean] */
    public final boolean getHandled() {
        return this._handled;
    }
skylot commented 3 years ago

@sergey-wowwow yeah, this time it is int to boolean conversion :facepalm:

bagipro commented 3 years ago

@skylot And a few more invalid operations.

Class com.ebay.common.view.DefaultItemAdapter

    /* JADX DEBUG: Multi-variable search result rejected for r6v3, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r6v4, resolved type: boolean */
    /* JADX WARN: Multi-variable type inference failed */
    /* access modifiers changed from: protected */
    public boolean setCurrencyWithBaseUnitPriceAuctionWithBin(android.widget.TextView textView, com.ebay.nautilus.domain.data.ItemCurrency itemCurrency, com.ebay.nautilus.domain.data.ItemCurrency itemCurrency2, com.ebay.nautilus.domain.data.ItemCurrency itemCurrency3, com.ebay.nautilus.domain.data.ItemCurrency itemCurrency4, boolean z, Item item) {
        com.ebay.nautilus.domain.data.ItemCurrency convertedPrice;
        com.ebay.nautilus.domain.data.ItemCurrency convertedPrice2 = getConvertedPrice(itemCurrency, itemCurrency2);
        android.text.Spannable spannable = null;
        spannable = null;
        spannable = null;
        if (convertedPrice2 != null) {
            int i = 1;
            i = 1;
            boolean z2 = !convertedPrice2.code.equals(itemCurrency.code);
            java.lang.String formatCurrency = formatCurrency(convertedPrice2.value, convertedPrice2.code, z2 | 2); // invalid operation on boolean `z2 | 2`
            if (!(z2 == 0 || formatCurrency == null)) { // also invalid operation `z2 == 0`

Class com.ebay.nautilus.shell.databinding.UxcompDiscoverySelectionCapsuleBindingImpl

    /* access modifiers changed from: protected */
    @Override // androidx.databinding.ViewDataBinding
    public void executeBindings() {
        long j;
        boolean z;
        boolean z2;
        java.lang.String str;
        synchronized (this) {
            j = this.mDirtyFlags;
            this.mDirtyFlags = 0;
        }
        com.ebay.nautilus.shell.uxcomponents.viewmodel.SelectionViewModel selectionViewModel = this.mUxContent;
        int i = ((j & 11) > 0 ? 1 : ((j & 11) == 0 ? 0 : -1));
        java.lang.CharSequence charSequence = null;
        charSequence = null;
        boolean z3 = false;
        z3 = false;
        if (i != 0) {
            androidx.databinding.ObservableBoolean observableBoolean = selectionViewModel != null ? selectionViewModel.isSelected : null;
            updateRegistration(0, observableBoolean);
            if (observableBoolean != null) {
                z3 = observableBoolean.get();
            }
            if (i != 0) {
                j |= z3 ? 32 : 16;
            }
            boolean z4 = !z3 ? 1 : 0; // invalid assignment
            if ((j & 10) == 0 || selectionViewModel == null) {
                z = z4;
                str = null;
            } else {
                charSequence = selectionViewModel.getTitle();
                str = selectionViewModel.getTitleContentDescription();
                z = z4;
            }
            z2 = z3 ? 1 : 0; // invalid assignment