# Replacing libusb in AJA Intercom object code

1. Obtain this version's complete `AJA-Intercom-1.0.0-code1-relink.apk` from the distributor.
   Verify SHA256SUMS. A split Play installation can be backed up with `adb shell pm path
   pl.ajastudio.intercom` and `adb pull` for each returned APK; replacement libraries belong in
   the corresponding ABI split. Using the supplied full APK is simpler and avoids split mismatch.
2. Build your modified libusb with rebuild-libusb.sh; keep ABI and SONAME unchanged. Keep license
   notices. Check ELF64 PT_LOAD/RELRO >=16 KB with the included native verifier.
3. Repackage the full APK with your libraries (Python 3 standard library only):

```sh
python3 repackage-apk.py AJA-Intercom-1.0.0-code1-relink.apk /absolute/path/rebuild/libs modified-unaligned.apk
"$ANDROID_HOME/build-tools/36.0.0/zipalign" -P 16 -f 4 modified-unaligned.apk modified-aligned.apk
"$ANDROID_HOME/build-tools/36.0.0/apksigner" sign --ks /absolute/path/YOUR-OWN-key.p12 --out modified.apk modified-aligned.apk
"$ANDROID_HOME/build-tools/36.0.0/apksigner" verify --verbose modified.apk
"$ANDROID_HOME/build-tools/36.0.0/zipalign" -c -P 16 4 modified.apk
python3 verify-android-native.py modified.apk
```

`apksigner` prompts locally for your own key's password; do not use AJA's keys. Create your own
key with interactive keytool if needed. Do not pass passwords in argv or save them in a script.
Repackaging removes old JAR signature metadata and the v2/v3 signing block. Other payload bytes
are preserved; native libraries are stored uncompressed before alignment.

4. Install on a separate test device without the Play-signed app. Your key cannot update an app
   signed by Google/AJA; uninstalling an existing app loses its local data. Do not do this to
   another user's installation. `adb install modified.apk` on your own clean test device.
5. Test USB permission grant/deny, hotplug/unplug/replug, YUY2 and MJPEG preview where supported,
   actual video TX/RX against a second participant, program-audio capture/TX/RX and stop/restart.
   Permission/routing and consent controls remain required. Do not bypass TLS or remote consent.

Reverse engineering to debug your LGPL modifications is permitted. The proprietary application
source and the owner's private signing keys are not needed for this dynamic replacement method.
