dex2c: After turning on the default R8 obfuscation, the wrong effect is produced
- Android Version 14
- ApkTools Version : apktool_2.10.0.jar
- Ndk Version : 23.0.7599858
- Apk isMinifyEnabled = true
// dcc.py config
current_dir = os.path.dirname(os.path.abspath(__file__))
APKTOOL = os.path.join(current_dir, 'tools', 'apktool.jar')
APKTOOL2 = os.path.join(current_dir, 'tools', 'apktool.bat')
APKTOOL3 = os.path.join(current_dir, 'tools', 'apktool')
SIGNJAR = os.path.join(current_dir, 'tools', 'apksigner.jar')
MANIFEST_EDITOR = os.path.join(current_dir, 'tools', 'manifest-editor.jar')
NDKBUILD = "ndk-build"
- Use the default obfuscation configuration without any changes and install app-release.apk to run normally
- Then the following is the preparation work before dex2c configuration, and some code is posted
// config fillter.txt
com/example/testproject/MainActivity;getResources\(.*
// MainActivity Source Code
package com.example.testproject
class MainActivity : AppCompatActivity() {
val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }
override fun getResources(): Resources {
val resources = super.getResources()
val widthPixels = resources.displayMetrics.widthPixels.toFloat()
val heightPixels = resources.displayMetrics.heightPixels.toFloat()
if (widthPixels > heightPixels) {
if (widthPixels / 1024 * 600 > heightPixels) {
resources.displayMetrics.density = heightPixels / 600
} else {
resources.displayMetrics.density = widthPixels / 1024
}
} else {
resources.displayMetrics.density = widthPixels / 1024
}
return resources
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
enableEdgeToEdge()
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.root.updateLayoutParams<FrameLayout.LayoutParams> {
topMargin = systemBars.top
}
binding.root.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
lifecycleScope.launch { }
initView()
printHelloWorld()
}
private fun printHelloWorld() {
"Hello World".log()
}
private fun initView() {
// TODO....
}
}
- run command
python .\dcc.py -a .\app-release.apk -o output3.apk - install output3.apk , throw Exception
exception : java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testproject/com.example.testproject.MainActivity}: android.content.res.Resources$NotFoundException: Drawable com.example.testproject:drawable/abc_vector_test with resource ID #0x7f070078
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3987)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4140)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:99)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2585)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:224)
at android.os.Looper.loop(Looper.java:318)
at android.app.ActivityThread.main(ActivityThread.java:8772)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.testproject:drawable/abc_vector_test with resource ID #0x7f070078
Caused by: android.content.res.Resources$NotFoundException: File res/hq.xml from drawable resource ID #0x7f070078
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:972)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:729)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:322)
at android.content.res.Resources.loadDrawable(Resources.java:1055)
at android.content.res.Resources.getDrawableForDensity(Resources.java:1043)
at android.content.res.Resources.getDrawable(Resources.java:982)
at android.content.Context.getDrawable(Context.java:959)
at m.N0.g(SourceFile:52)
at m.N0.f(SourceFile:3)
at m.N0.g(SourceFile:11)
at g.B.n(SourceFile:55)
at g.B.w(SourceFile:17)
at g.B.c(SourceFile:6)
at g.g.a(SourceFile:17)
at b.l.onCreate(SourceFile:30)
at g.h.onCreate(SourceFile:1)
at com.example.testproject.MainActivity.onCreate(SourceFile:1)
at android.app.Activity.performCreate(Activity.java:8891)
at android.app.Activity.performCreate(Activity.java:8856)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1471)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3969)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4140)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:99)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2585)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:224)
at android.os.Looper.loop(Looper.java:318)
at android.app.ActivityThread.main(ActivityThread.java:8772)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by: android.content.res.Resources$NotFoundException: File res/hq.xml from xml type drawable resource ID #0x7f070078
at android.content.res.ResourcesImpl.loadXmlResourceParser(ResourcesImpl.java:1321)
at android.content.res.ResourcesImpl.loadXmlDrawable(ResourcesImpl.java:1002)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:936)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:729)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:322)
at android.content.res.Resources.loadDrawable(Resources.java:1055)
at android.content.res.Resources.getDrawableForDensity(Resources.java:1043)
at android.content.res.Resources.getDrawable(Resources.java:982)
at android.content.Context.getDrawable(Context.java:959)
at m.N0.g(SourceFile:52)
at m.N0.f(SourceFile:3)
at m.N0.g(SourceFile:11)
at g.B.n(SourceFile:55)
at g.B.w(SourceFile:17)
at g.B.c(SourceFile:6)
at g.g.a(SourceFile:17)
at b.l.onCreate(SourceFile:30)
at g.h.onCreate(SourceFile:1)
at com.example.testproject.MainActivity.onCreate(SourceFile:1)
at android.app.Activity.performCreate(Activity.java:8891)
at android.app.Activity.performCreate(Activity.java:8856)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1471)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3969)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4140)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:99)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2585)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:224)
at android.os.Looper.loop(Looper.java:318)
at android.app.ActivityThread.main(ActivityThread.java:8772)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by: java.io.FileNotFoundException: res/hq.xml
at android.content.res.AssetManager.nativeOpenXmlAsset(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:1137)
- Even without obfuscating getResource, when I changed it to printHelloWorld, after running the command line, it prompted No methods compiled! “Check your filter file.” So I found the obfuscated printHelloWorld, as follows
Modify the filtering rule to: h1/AbstractC0290a;a\(.*
When I run the dex2c command again, I still get the following message: “Check your filter file.”
- And when I confuse the onCreate method, it still throws the same exception as above. Is it impossible to confuse resources after using dex2c? Is the code obfuscated?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (2 by maintainers)
Commits related to this issue
- Attempt Fix apktool issue on windows (#33) — committed to codehasan/dex2c by AbhiTheModder 2 years ago
- Fix/windows (#39) * Attempt Fix apktool issue on windows (#33) * Add note for Windows * update windows jdk recommendation — committed to codehasan/dex2c by AbhiTheModder 2 years ago
No problem, I can package normally on Windows, thank you very much