REAndroid / APKEditor

Powerful android apk editor - aapt/aapt2 independent
Apache License 2.0
847 stars 127 forks source link

xmlns:app breaks down #41

Closed kiber-io closed 1 year ago

kiber-io commented 1 year ago

Describe the bug During decompilation, the xmlns:app attribute of the FrameLayout root element turns into xmlns:ru. Xml from the original apk obtained via JADX:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/mainContentRoot" android:visibility="invisible" android:layout_width="match_parent" android:layout_height="match_parent">
   <FrameLayout android:id="@+id/mainTabContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/bottom_tab_bar_size" />
   <View android:layout_gravity="bottom" android:id="@+id/bottomBarShadow" android:layout_marginBottom="@dimen/bottom_tab_bar_size" style="@style/Widget.WB.BottomBarShadow" />
   <androidx.compose.ui.platform.ComposeView android:layout_gravity="bottom" android:id="@+id/bottomBarCompose" android:layout_width="match_parent" android:layout_height="56dp" app:cardCornerRadius="0dp" />
   <androidx.compose.ui.platform.ComposeView android:id="@+id/rateAppCompose" android:layout_width="match_parent" android:layout_height="match_parent" />
   <ru.wildberries.widgets.SimpleStatusView android:id="@+id/mainActivityStatusView" android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>

Decompiled xml from apkeditor:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ru="http://schemas.android.com/apk/res-auto" android:id="@id/mainContentRoot" android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent">
   <FrameLayout android:id="@id/mainTabContainer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="@dimen/bottom_tab_bar_size" />
   <View android:layout_gravity="bottom" android:id="@id/bottomBarShadow" android:layout_marginBottom="@dimen/bottom_tab_bar_size" style="@style/Widget.WB.BottomBarShadow" />
   <androidx.compose.ui.platform.ComposeView android:layout_gravity="bottom" android:id="@id/bottomBarCompose" android:layout_width="fill_parent" android:layout_height="56.0dp" ru:cardCornerRadius="0.0dp" />
   <androidx.compose.ui.platform.ComposeView android:id="@id/rateAppCompose" android:layout_width="fill_parent" android:layout_height="fill_parent" />
   <ru.wildberries.widgets.SimpleStatusView android:id="@id/mainActivityStatusView" android:layout_width="fill_parent" android:layout_height="fill_parent" />
</FrameLayout>

After the compilation of the same apk, this attribute disappears (xml from JADX):

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainContentRoot" android:visibility="invisible" android:layout_width="match_parent" android:layout_height="match_parent">
   <FrameLayout android:id="@+id/mainTabContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/bottom_tab_bar_size" />
   <View android:layout_gravity="bottom" android:id="@+id/bottomBarShadow" android:layout_marginBottom="@dimen/bottom_tab_bar_size" style="@style/Widget.WB.BottomBarShadow" />
   <androidx.compose.ui.platform.ComposeView android:layout_gravity="bottom" android:id="@+id/bottomBarCompose" android:layout_width="match_parent" android:layout_height="56dp" android:cardCornerRadius="0dp" />
   <androidx.compose.ui.platform.ComposeView android:id="@+id/rateAppCompose" android:layout_width="match_parent" android:layout_height="match_parent" />
   <ru.wildberries.widgets.SimpleStatusView android:id="@+id/mainActivityStatusView" android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>

If you fix xmlns:ru to xmlns:app in the file with your hands, then after compilation the attribute disappears anyway

To Reproduce Steps to reproduce the behavior:

  1. Used version: APKEditor - 1.2.3, ARSCLib - 1.2.0
  2. Operating system: Ubuntu 22.04 (WSL)
  3. Command: java -jar bin/arsclib.jar d -t xml -i ../../tests/app.apk

Log/Stacktrace

00.000 I: [DECOMPILE] Decompiling ...
   Input: ../../tests/app.apk
 Output: ../../tests/app_decompile_xml
 Type: xml
 ---------------------------- 
00.014 I: [DECOMPILE] Loading ...
00.270 I: [DECOMPILE] Initializing android framework ...
00.270 I: [DECOMPILE] Loading android framework for version: 33
00.332 I: [DECOMPILE] Initialized framework: android-33 (UpsideDownCake)
00.332 I: [DECOMPILE] Decompiling to XML ...
00.359 I: [DECOMPILE] [SANITIZE]: Sanitizing paths ...
00.362 I: [DECOMPILE] Validating resource names ...
00.414 I: [DECOMPILE] Spec names validated, duplicates = 0, bad = 2, removed specs = 2
00.414 I: [DECOMPILE] Decode: uncompressed-files.json
00.434 I: [DECOMPILE] Decoding: AndroidManifest.xml
00.486 I: [DECOMPILE] public.xml: com.wildberries.ru -> package_1
00.503 I: [DECOMPILE] Res files: resources
03.291 [DECOMPILE] classes5.dex                                                                 
03.344 I: [DECOMPILE] Extracting root files ...
04.067 I: [DECOMPILE] Dumping signatures ...
04.067 I: [DECOMPILE] Saved to: ../../tests/app_decompile_xml

Used apk file https://drive.google.com/file/d/1IZDCRmzyaqWdMex2x4vXh6jqcHVu6c0z/view?usp=sharing

Problematic file layout/activity_main.xml

REAndroid commented 1 year ago

Namespace prefix is corrected according to last suffix of package name where attribute is referred . Such distinctive naming is vital when dealing with multi package resources. Check your package name on manifest should end with .ru, APKEditor has no problem. you can check for consistency by running decompile > compile > decompile ...

kiber-io commented 1 year ago

@REAndroid But the application stops working after decompilation - compilation :) Crashes with an error:

FATAL EXCEPTION: main
Process: com.wildberries.ru, PID: 10378
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wildberries.ru/ru.wildberries.SplashActivity}: android.view.InflateException: Binary XML file line #13 in com.wildberries.ru:layout/activity_main: Binary XML file line #13: You must supply a layout_width attribute., theme={InheritanceMap=[id=0x7f140346com.wildberries.ru:style/Theme.WB.NoActionBar.MainActivity, id=0x7f140344com.wildberries.ru:style/Theme.WB.NoActionBar, id=0x7f140340com.wildberries.ru:style/Theme.WB, id=0x7f140331com.wildberries.ru:style/Theme.MaterialComponents.Light.DarkActionBar.Bridge, id=0x7f140069com.wildberries.ru:style/Base.Theme.MaterialComponents.Light.DarkActionBar.Bridge, id=0x7f14008ecom.wildberries.ru:style/Base.V14.Theme.MaterialComponents.Light.DarkActionBar.Bridge, id=0x7f1402ebcom.wildberries.ru:style/Theme.AppCompat.Light.DarkActionBar, id=0x7f140051com.wildberries.ru:style/Base.Theme.AppCompat.Light.DarkActionBar, id=0x7f140050com.wildberries.ru:style/Base.Theme.AppCompat.Light, id=0x7f1400aecom.wildberries.ru:style/Base.V28.Theme.AppCompat.Light, id=0x7f1400abcom.wildberries.ru:style/Base.V26.Theme.AppCompat.Light, id=0x7f1400a5com.wildberries.ru:style/Base.V23.Theme.AppCompat.Light, id=0x7f1400a3com.wildberries.ru:style/Base.V22.Theme.AppCompat.Light, id=0x7f140099com.wildberries.ru:style/Base.V21.Theme.AppCompat.Light, id=0x7f1400b1com.wildberries.ru:style/Base.V7.Theme.AppCompat.Light, id=0x7f140171com.wildberries.ru:style/Platform.AppCompat.Light, id=0x7f14017ccom.wildberries.ru:style/Platform.V25.AppCompat.Light, id=0x1030241android:style/Theme.Material.Light.NoActionBar, id=0x1030237android:style/Theme.Material.Light, id=0x103000candroid:style/Theme.Light, id=0x1030005android:style/Theme], Themes=[com.wildberries.ru:style/Theme.WB.NoActionBar.MainActivity, forced, com.wildberries.ru:style/Theme.WB.Splash, forced, com.wildberries.ru:style/Theme.AppCompat.Empty, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4169)

You can check it yourself. Launch the original application - it works. And then try to run the rebuilt application.

REAndroid commented 1 year ago

Yes i confirmed its bug, FYI you can fix the faulty apk by decompile > compile with -t json. I will fix it soon

kiber-io commented 1 year ago

fixed in 1.2.4