Skip to content

BluetoothLibraryPatcher v2.9.2 loses generated libbluetooth.so after reboot on Galaxy S9 Android 10 unless service.sh is disabled before first reboot #103

Description

@Machoo255

Device

  • Device: Samsung Galaxy S9 (SM-G960F)
  • Codename: starlte
  • Android version: Android 10
  • ROM: Samsung stock / One UI 2.5
  • Root: Magisk
  • Magisk version used during debugging: 30.7
  • Module version: BluetoothLibraryPatcher_module_2.9.2.zip
  • Device is system-as-root: yes

Problem

BluetoothLibraryPatcher installs successfully and reports:

- Searching for relevant hex byte sequence
- Applying patch
- Successfully patched!
- Creating OTA survival service
- Done

Immediately after installation, before reboot, the generated patched library exists in modules_update:

/data/adb/modules_update/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
/data/adb/modules_update/BluetoothLibraryPatcher/service.sh
/data/adb/modules_update/BluetoothLibraryPatcher/module.zip

After reboot, the patched library is moved to the active module directory and appears to be mounted correctly:

/data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

The hashes also match:

md5sum /system/lib64/libbluetooth.so
d85f86c5866fdef4f2a67adba48f49e6  /system/lib64/libbluetooth.so

md5sum /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
d85f86c5866fdef4f2a67adba48f49e6  /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

However, after another reboot, the generated patched library disappears from the module directory.

The module directory ends up containing only the raw installer/module files:

/data/adb/modules/BluetoothLibraryPatcher/
├── 7z.tar.xz
├── 7z64.tar.xz
├── README.md
├── SUPPORT.md
├── bash.tar.xz
├── bash64.tar.xz
├── busybox.tar.xz
├── busybox64.tar.xz
├── customize.sh
├── hexpatch.sh
├── latestchange.log
├── module.prop
├── service.sh
└── update.json

Missing files/directories after the reboot:

/data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
/data/adb/modules/BluetoothLibraryPatcher/module.zip

At that point, the module is still listed as installed, but it no longer contains the generated patched libbluetooth.so, so it cannot actually mount the patched library anymore.

Steps to reproduce

  1. Remove the existing module:
rm -rf /data/adb/modules/BluetoothLibraryPatcher
rm -rf /data/adb/modules_update/BluetoothLibraryPatcher
  1. Install the module from root shell:
magisk --install-module /path/to/BluetoothLibraryPatcher_module_2.9.2.zip > /sdcard/blp-clean-install.log 2>&1
cat /sdcard/blp-clean-install.log
  1. Installation log shows:
- Device is system-as-root
***************************
 Bluetooth Library Patcher
 by 3arthur6
***************************
*******************
 Powered by Magisk
*******************
- Extracting module files
- Magisk Manager installation
- Searching for relevant hex byte sequence
- Applying patch
- Successfully patched!
- Creating OTA survival service
- Done
  1. Before reboot, verify generated files exist:
ls -la /data/adb/modules_update/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
ls -la /data/adb/modules_update/BluetoothLibraryPatcher/service.sh
ls -la /data/adb/modules_update/BluetoothLibraryPatcher/module.zip

Result:

-rw-rw-rw- 1 root root 4741896 ... /data/adb/modules_update/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
-rw-r--r-- 1 root root     384 ... /data/adb/modules_update/BluetoothLibraryPatcher/service.sh
-rw-rw---- 1 root root 5140963 ... /data/adb/modules_update/BluetoothLibraryPatcher/module.zip
  1. Reboot.

  2. After reboot, verify the patched library exists and hashes match:

md5sum /system/lib64/libbluetooth.so
md5sum /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

Result:

d85f86c5866fdef4f2a67adba48f49e6  /system/lib64/libbluetooth.so
d85f86c5866fdef4f2a67adba48f49e6  /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so
  1. Reboot again.

  2. After the next reboot, check again:

ls -la /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

Result:

No such file or directory

The active module directory no longer contains the generated system/lib64/libbluetooth.so.

Workaround found

If I disable the OTA survival service before the first reboot, the patched library remains after reboot.

Procedure:

  1. Remove existing module:
rm -rf /data/adb/modules/BluetoothLibraryPatcher
rm -rf /data/adb/modules_update/BluetoothLibraryPatcher
  1. Install again:
magisk --install-module /path/to/BluetoothLibraryPatcher_module_2.9.2.zip
  1. Before reboot, disable service.sh inside modules_update:
mv /data/adb/modules_update/BluetoothLibraryPatcher/service.sh /data/adb/modules_update/BluetoothLibraryPatcher/service.sh.disabled
rm -f /data/adb/modules_update/BluetoothLibraryPatcher/module.zip
  1. Reboot.

  2. After reboot, the patched library remains:

/data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

service.sh remains disabled:

/data/adb/modules/BluetoothLibraryPatcher/service.sh.disabled

Hashes still match:

d85f86c5866fdef4f2a67adba48f49e6  /system/lib64/libbluetooth.so
d85f86c5866fdef4f2a67adba48f49e6  /data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

Also, /data/adb/modules_update is empty or does not exist after this workaround.

Expected behavior

After successful installation and reboot, the generated patched library should remain in:

/data/adb/modules/BluetoothLibraryPatcher/system/lib64/libbluetooth.so

and should continue to be mounted by Magisk after subsequent reboots.

Actual behavior

After a later reboot, the generated patched library disappears from the active module directory, leaving only the raw installer/module files. The module still appears installed, but no patched libbluetooth.so is available to mount.

Suspected cause

This looks related to the OTA survival / service.sh logic.

My guess is that service.sh may compare the stored original hash against /system/lib64/libbluetooth.so, but after Magisk mounts the patched overlay, /system/lib64/libbluetooth.so already resolves to the patched library. This may cause the OTA survival logic to think the system library changed and reinstall/overwrite the module in a way that loses the generated patched library.

Disabling service.sh before the first reboot prevents the issue in my case.

Notes

This issue was observed during debugging on Magisk 30.7.

The Bluetooth pairing problem existed earlier as well, before Magisk 30.7, but I do not know for sure whether the same module-state issue was the cause back then.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions