是否有一些 Kotlin 文件的反编译器可以反编译为 kotlin *.kt 文件

Exo*_*Kid 7 android decompiling kotlin

我尝试学习如何反编译 Android 程序(APK),并在网上找到了这个网站 Decompilers。它适用于 Java 代码,但是当有 Kotlin 文件代码时,反编译器会生成 Java 代码并将 Kotlin 和 Java 混合在一起。

这是我从文件中看到的ColorCircle.kt。正如你看到的 KotlinLazy和其他 Kotlin 代码。我的问题是:是否有其他一些用于反编译为 kotlin *.kt 文件的 Kotlin 文件的反编译器
我可以在*.java没有问题的文件中导入 Kotlin吗?

package io.coolbe.vai.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import io.coolbe.vai.C1300R;
import java.util.HashMap;
import kotlin.Lazy;
import kotlin.Metadata;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.PropertyReference1Impl;
import kotlin.jvm.internal.Reflection;
import kotlin.reflect.KProperty;
import org.jetbrains.annotations.NotNull;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0007\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001B\u000f\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004B\u0017\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0005\u001a\u00020\u0006¢\u0006\u0002\u0010\u0007J\u0010\u0010\u0014\u001a\u00020\u00152\u0006\u0010\u0016\u001a\u00020\u0017H\u0014R\u000e\u0010\b\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u001b\u0010\u000b\u001a\u00020\f8BX\u0002¢\u0006\f\n\u0004\b\u000f\u0010\u0010\u001a\u0004\b\r\u0010\u000eR\u000e\u0010\u0011\u001a\u00020\u0012X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0013\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000¨\u0006\u0018"}, d2 = {"Lio/coolbe/vai/view/ColoredCircle;", "Landroid/view/View;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "attrs", "Landroid/util/AttributeSet;", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "offsetX", "", "offsetY", "paint", "Landroid/graphics/Paint;", "getPaint", "()Landroid/graphics/Paint;", "paint$delegate", "Lkotlin/Lazy;", "strokeColor", "", "strokeWidth", "onDraw", "", "canvas", "Landroid/graphics/Canvas;", "app_release"}, k = 1, mv = {1, 1, 13})
/* compiled from: ColoredCircle.kt */
public final class ColoredCircle extends View {
    static final /* synthetic */ KProperty[] $$delegatedProperties = new KProperty[]{Reflection.property1(new PropertyReference1Impl(Reflection.getOrCreateKotlinClass(ColoredCircle.class), "paint", "getPaint()Landroid/graphics/Paint;"))};
    private HashMap _$_findViewCache;
    private float offsetX;
    private float offsetY;
    private final Lazy paint$delegate;
    private int strokeColor;
    private float strokeWidth;

    private final Paint getPaint() {
        Lazy lazy = this.paint$delegate;
        KProperty kProperty = $$delegatedProperties[0];
        return (Paint) lazy.getValue();
    }

    public vaid _$_clearFindViewByIdCache() {
        HashMap hashMap = this._$_findViewCache;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public View _$_findCachedViewById(int i) {
        if (this._$_findViewCache == null) {
            this._$_findViewCache = new HashMap();
        }
        View view = (View) this._$_findViewCache.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        view = findViewById(i);
        this._$_findViewCache.put(Integer.valueOf(i), view);
        return view;
    }

    public ColoredCircle(@NotNull Context context) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        super(context);
        this.strokeColor = -7829368;
        this.strokeWidth = 10.0f;
        this.paint$delegate = LazyKt__LazyJVMKt.lazy((Function0) new ColoredCircle$paint$2(this));
    }

    public ColoredCircle(@NotNull Context context, @NotNull AttributeSet attributeSet) {
        Intrinsics.checkParameterIsNotNull(context, "context");
        Intrinsics.checkParameterIsNotNull(attributeSet, "attrs");
        super(context, attributeSet);
        this.strokeColor = -7829368;
        this.strokeWidth = 10.0f;
        this.paint$delegate = LazyKt__LazyJVMKt.lazy(new ColoredCircle$paint$2(this));
        context = context.getTheme().obtainStyledAttributes(attributeSet, C1300R.styleable.ColoredCircle, 0, 0);
        try {
            this.offsetX = context.getDimension(0, this.offsetX);
            this.offsetY = context.getDimension(1, this.offsetY);
            this.strokeColor = context.getColor(2, this.strokeColor);
            this.strokeWidth = context.getDimension(3, this.strokeWidth);
        } finally {
            context.recycle();
        }
    }

    protected vaid onDraw(@NotNull Canvas canvas) {
        Intrinsics.checkParameterIsNotNull(canvas, "canvas");
        super.onDraw(canvas);
        float f = (float) getLayoutParams().width;
        float f2 = (float) getLayoutParams().height;
        float f3 = (float) 2;
        float min = (Math.min(f, f2) / f3) - (this.strokeWidth / f3);
        canvas.save();
        canvas.translate(this.offsetX, this.offsetY);
        canvas.drawCircle(f / f3, f2 / f3, min, getPaint());
        canvas.restore();
    }
}
Run Code Online (Sandbox Code Playgroud)

Gen*_*hen 7

是否有其他一些针对 Kotlin 文件的反编译器可以反编译为 kotlin *.kt 文件?

目前,还没有“舒适的”反编译器可以做.class -> .kt

有几个著名的反编译器可以做到这一点.class -> .java,但它们只适合Java编译器生成的字节码。如果您尝试使用它们来反编译 Kotlin 生成的某些字节码,您可能会看到一些奇怪的甚至错误。这是由编写和编译 Kotlin 时使用的一些技巧造成的。

那么,在大多数情况下,你不能直接使用反编译器的输出。

我可以在 *.java 文件中导入 Kotlin 而不会出现问题吗?

这是一个与“与Java 100%互操作”相关的问题。Kotlin 几乎可以.java毫无问题地导入到文件中(我不确定将 Java Lambda 传入 Kotlin 时是否会出现问题,但普通的函数调用方式肯定没有问题)。

  • @ch271828n 在我的测试中,主要的 Java 反编译器,如 JD-GUI、JaDX 或 FernFlower,仍然像 3 年前一样对 Kotlin 的支持很差。IDEA内置反编译器显示“分解”的函数签名,但不显示方法体的编译代码。像 [GitHub: Earthcomputer/kotlin-decompiler](https://github.com/Earthcomputer/kotlin-decompiler) 这样的个人努力可能会做一些很棒的事情,但是我无法测试它,因为我没有成功编译它给公司的代理人。 (3认同)
  • 你好,三年过去了,所以我想知道*现在*是否有这样的编译器?谢谢! (2认同)