Skip to content

Commit

Permalink
Patch app label when repackaging
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Dec 3, 2018
1 parent 07bfdf3 commit 7b04386
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
android:exported="true" />
<activity
android:name="a.c"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:exported="true"
android:theme="@style/SplashTheme">
Expand Down
16 changes: 15 additions & 1 deletion app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.IntBuffer;
import java.security.SecureRandom;
import java.util.jar.JarEntry;

Expand Down Expand Up @@ -80,6 +81,18 @@ private static boolean findAndPatch(byte xml[], String a, String b) {
return true;
}

private static boolean findAndPatch(byte xml[], int a, int b) {
IntBuffer buf = ByteBuffer.wrap(xml).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
int len = xml.length / 4;
for (int i = 0; i < len; ++i) {
if (buf.get(i) == a) {
buf.put(i, b);
return true;
}
}
return false;
}

private static boolean patchAndHide() {
MagiskManager mm = Data.MM();

Expand Down Expand Up @@ -115,7 +128,8 @@ public static boolean patchPackageID(JarMap apk, String from, String to) {
byte xml[] = apk.getRawData(je);

if (!findAndPatch(xml, from, to) ||
!findAndPatch(xml, from + ".provider", to + ".provider"))
!findAndPatch(xml, from + ".provider", to + ".provider") ||
!findAndPatch(xml, R.string.app_name, R.string.re_app_name))
return false;

// Write in changes
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:allowBackup="false"
android:directBootAware="true"
android:icon="@drawable/ic_launcher"
android:label="@string/re_app_name"
android:label="@string/app_name"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">

Expand Down
1 change: 0 additions & 1 deletion app/src/stub/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<application
tools:ignore="GoogleAppIndexingWarning">
<activity
android:label="@string/app_name"
android:name=".MainActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
Expand Down

0 comments on commit 7b04386

Please sign in to comment.