现在 Obfuscated 在 Kotlin 或 Java 代码中不起作用,我该用什么?

问题描述

我尝试混淆我的项目,以便在 Gradle 中启用一些设置。然后我尝试反转代码但没有完全混淆

我参考了很多网站,我还没有找到确切的解决方

我尝试从 Play 商店中反编译非常著名的应用程序,例如任何谷歌应用程序和 Facebook(代码似乎完全混淆了)。

任何人都可以建议我应该怎么做才能使完整代码混淆

  • 以下 3 个步骤不会用于代码混淆

第 1 步: Gradle 属性

# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=obsolete
android.enableR8.fullMode=true

第 2 步:应用级 Gradle:

 buildTypes {
        release {
            useProguard true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }

第 3 步: proguard-rules.pro 我也尝试了 proguard 规则

# If you keep the line number information,uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFile

这是我的 kotlin 代码

package com.android.myapplication
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.d("mytag","on create")
        try{
            val deviceInfo = " MOBILE: Android" +
                    " APP VERSION:" + BuildConfig.VERSION_NAME +
                    " MODEL:" + Build.MODEL +
                    " Manufacture:" + Build.MANUFACTURER +
                    " BRAND:" + Build.BRAND +
                    " SDK:" + Build.VERSION.SDK +
                    " OS: " + Build.VERSION.RELEASE
            //Sets the text to be displayed.
            android_info.text =deviceInfo
        } catch (e: Exception){
            android_info.text =e.message
        }

    }
}

在这里,我尝试对我的发布版本进行逆向编码。 Android Apk 反编译器: http://www.javadecompilers.com/apk

反编译器输出

package com.android.myapplication;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.HashMap;
import p000a.p002b.p003c.C0034n;
import p082c.p083a.p084a.C0741a;

public final class MainActivity extends C0034n {

    /* renamed from: o */
    public HashMap f2788o;

    /* renamed from: o */
    public View mo2896o(int i) {
        if (this.f2788o == null) {
            this.f2788o = new HashMap();
        }
        View view = (View) this.f2788o.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View findViewById = findViewById(i);
        this.f2788o.put(Integer.valueOf(i),findViewById);
        return findViewById;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_main);
        Log.d("mytag","on create");
        try {
            TextView textView = (TextView) mo2896o(R.id.android_info);
            C0741a.m1859a(textView,"android_info");
            textView.setText(" MOBILE: Android APP VERSION:1.0 MODEL:" + Build.MODEL + " Manufacture:" + Build.MANUFACTURER + " BRAND:" + Build.BRAND + " SDK:" + Build.VERSION.SDK + " OS: " + Build.VERSION.RELEASE);
        } catch (Exception e) {
            TextView textView2 = (TextView) mo2896o(R.id.android_info);
            C0741a.m1859a(textView2,"android_info");
            textView2.setText(e.getMessage());
        }
    }
}

注意事项: 启用上述 Gradle 设置后:

  • 应用大小减少了 40%
  • 它还删除了我项目中未使用的类和 res 文件

解决方法

不可能 100% 混淆,因为入口点会丢失。例如,如果您对 MainActivity 进行混淆处理,那么 AndroidManifest.xml 中的引用将变得无效并且您无法再启动它。这是按预期工作的,没有什么可担心的。