Android 既然模糊处理在Kotlin或Java代码中不起作用,我现在该用什么?
我试图混淆我的项目,以便在Gradle中启用一些设置。然后我尝试反转代码,但没有完全混淆 我参考了许多网站,但还没有找到确切的解决方案 我尝试从play store反编译非常著名的应用程序,如任何google应用程序和Facebook(代码似乎完全混淆) 谁能给我一个建议,我应该怎么做才能使完整的代码变得模糊Android 既然模糊处理在Kotlin或Java代码中不起作用,我现在该用什么?,android,kotlin,proguard,android-r8,android-obfuscation,Android,Kotlin,Proguard,Android R8,Android Obfuscation,我试图混淆我的项目,以便在Gradle中启用一些设置。然后我尝试反转代码,但没有完全混淆 我参考了许多网站,但还没有找到确切的解决方案 我尝试从play store反编译非常著名的应用程序,如任何google应用程序和Facebook(代码似乎完全混淆) 谁能给我一个建议,我应该怎么做才能使完整的代码变得模糊 以下3个步骤不适用于代码混淆 步骤1:渐变属性: # Kotlin code style for this project: "official" or "
- 以下3个步骤不适用于代码混淆
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=obsolete
android.enableR8.fullMode=true
第2步:应用程序级别分级:
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
}
}
}
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());
}
}
}
在这里,我尝试反向编写我的发布版本。
Android Apk反编译器:
反编译器输出:
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
}
}
}
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());
}
}
}
注意事项:
启用上述渐变设置后:
- 应用程序大小减少40%
- 它还删除了我的项目中未使用的类和res文件
- 不可能100%混淆,因为入口点会丢失。例如,如果您混淆了
MainActivity
,则AndroidManifest.xml
中的引用将变得无效,您将无法再启动它。这是预期的工作,没有什么可担心的。感谢您的回复,我禁用了所有的低于等级设置,在反编译时得到相同的输出。我尝试反编译非常著名的应用程序,比如transit,miles,。。但是代码完全混淆了,我找不到类名本身。(我想他们正在上传一些映射文件)(minifyEnabled false/shrinkResources false/kotlin.code.style=official/android.enableR8.fullMode=false)他们什么也不做,否则他们的应用程序也不会运行……当混淆太多(可能会破坏应用程序)而不是太少时,人们通常会遇到更多的问题。映射文件仅适用于Crashlytics,但显然没有安装在任何终端设备上。甚至还有更多的类、成员变量等等,我们不能混淆它们<代码>可序列化可能是另一个很好的例子。那么,当它被混淆时,您将如何使用它呢?请不要使用useProguard true
。该设置已被弃用,我不确定它现在到底做了什么。仅使用minifyEnabled true
R8将用于收缩,而使用android.enableR8.fullMode=true
将使用最激进的收缩。您还可以尝试使用-repackageclasses
移动到根包。如果看到未模糊的类/方法,可以使用-whyareyoukeeping
查看该项使用的保留规则。