APKEditor icon indicating copy to clipboard operation
APKEditor copied to clipboard

XML entity shows up as "&" instead of "&" after repacking apk

Open Gbr22 opened this issue 2 years ago • 6 comments

Describe the bug It appears that APKEditor cannot correctly handle XML entities in resource strings. String in source code: <string name="test_string">\"Alma\" &amp; Körte</string>. Expected behaviour: The string should show up as "Alma" & Körte after repacking the apk. Actual behaviour: The string shows up as "Alma" &amp; Körte after repacking the apk.

To Reproduce Steps to reproduce the behavior:

  1. Used version '1.2.5'
  2. Operating system 'Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 GNU/Linux'
  3. Commands java -jar APKEditor-1.2.5.jar d -dex -i app-debug.apk and java -jar APKEditor-1.2.5.jar b -i app-debug_decompile_xml -o packed.apk

Log/Stacktrace

Used apk file app-debug.apk.zip

Additional context image

Source code for apk (android studio, new project, empty activity)

strings.xml

<resources>
    <string name="app_name">APKEditorTest</string>
    <string name="test_string">\"Alma\" &amp; Körte</string>
</resources>

MainActivity.kt

package com.example.apkeditortest

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.apkeditortest.ui.theme.APKEditorTestTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            APKEditorTestTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting(getString(R.string.test_string))
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    APKEditorTestTheme {
        Greeting("Android")
    }
}

Gbr22 avatar Jul 15 '23 12:07 Gbr22

I think it has something to do with #49

naijun0403 avatar Jul 15 '23 15:07 naijun0403

I confirmed this and will be fixed soon

REAndroid avatar Jul 15 '23 19:07 REAndroid

The issue seems to be fixed in APKEditor 1.2.6

Gbr22 avatar Jul 16 '23 11:07 Gbr22

I am having the issue is APKEditor 1.3.2

SZRabinowitz avatar Mar 13 '24 22:03 SZRabinowitz

to add more details:

I believe this line in resources.arsc.json is where the string is.

        "entry_name": "reset_phone_sdcard_title",
        "value": {
         "value_type": "STRING",
         "data": "Phone & SD card"
        },
        "id": 3384
       },

Here is how it looks on the phone: Screenshot_20240129-214726

I guess my situations is a bit different because it doesnt show "&amp", it shows something else strange.

link to apk: https://filetransfer.io/data-package/6UuDwzLZ#link Mirror: https://murena.io/s/kCTBjTXAHQLAs8y

Keep in mind that this is a system app and you probably cannot install it on your phone

SZRabinowitz avatar Mar 15 '24 02:03 SZRabinowitz

Update

Hey folks, quick update on this!

After a day of digging around (and probably way too many Google searches), I think I’ve cracked the mystery.

Here’s what was happening:

  • On Windows:
    It was showing this weird behavior:
    Windows Screenshot

  • On Debian Linux (via WSL):
    It looked like this instead:
    Linux Screenshot

After some sleuthing, I found out that this is likely a file encoding issue. A helpful StackOverflow thread pointed me in the right direction.

Turns out, Java 18 and above defaults to UTF-8 encoding (source), while I was still running Java 17. Once I upgraded to Java 23, everything started working perfectly on both Windows and Linux.

🎉 Problem solved!

For anyone still using older Java versions, it would probably help if apkeditor (or arsclib maybe? Not sure) explicitly set file encoding to utf-8. I’m not super familiar with Java, so I won’t be submitting a PR (sorry), but hopefully, this info helps someone out there.

Cheers!

SZRabinowitz avatar Dec 18 '24 18:12 SZRabinowitz