Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8d14bbe
Run Apple's macOS CoreADI under an x86_64 emulator, as libmacadi.so
Oct 21, 2026
a0f9bf1
Sign in as the emulated Mac, so Find My answers again
Oct 21, 2026
420d9ac
Document the emulated Mac: rule 21, the host check and its workflow
Oct 21, 2026
2130d0e
Keep restored sessions on their own machine, and the emulated Mac in …
Nov 4, 2026
da1a784
Carry Unicorn's GPL-2.0 notice in the APK, and its source on each rel…
Nov 4, 2026
c73a064
Compare the C++ port with os-findmy-e's adi-core byte for byte
Nov 4, 2026
f67616d
Step the hsc 409 wrapper aside once FindMy.py reads it itself
Nov 4, 2026
17bf348
Note that MacBookPro13,2 never ran macOS 13.1, and why it is kept
Nov 4, 2026
6100a00
Rule 21: restored sessions keep their machine, and :macadi holds Unicorn
Nov 4, 2026
3ab2382
Move the FindMy.py pin to the hsc 409 fix and drop the runtime wrapper
parawanderer Nov 20, 2026
84e244f
Spell the emulated Mac's OS "Mac OS X", which Apple's edge still lets…
parawanderer Nov 20, 2026
1482a9e
Merge remote-tracking branch 'origin/main' into pr274
parawanderer Nov 20, 2026
29c1f2a
Merge branch 'fix/289-mac-os-x' into pr274
parawanderer Nov 20, 2026
9a8e960
Merge branch 'fix/289-mac-os-x' into pr274
parawanderer Nov 20, 2026
fec0831
Name the os-findmy-e commit the emulated Mac was ported from, and cre…
parawanderer Nov 20, 2026
023c1e5
Merge remote-tracking branch 'origin/main' into pr274
parawanderer Nov 20, 2026
1d0e5fc
Bound the emulated Mac's memory and time per call
parawanderer Nov 20, 2026
e72ab06
Let the byte comparison reach the OTP path
parawanderer Nov 20, 2026
5ab9bd9
Restore without side effects, recover a 433, one CloudKit id, idle close
parawanderer Nov 20, 2026
8b23e90
Document the emulator's bounds, the 433 recovery and the OTP comparison
parawanderer Nov 20, 2026
e8bc97a
Document the Windows prerequisites the emulated Mac's native build needs
parawanderer Nov 21, 2026
ed6d4a4
Name the missing tool when Unicorn's configure cannot run
parawanderer Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,28 @@ jobs:
# here, and fails with 403 "Resource not accessible by integration" after the APK has
# already been built and signed. That is exactly how the 1.0.5 exporter release went out
# with no assets attached; this workflow had the same wiring and was never re-run.
# The APK carries libmacadi.so, which links Unicorn (GPL-2.0). GPL-2.0 section 3 asks for the
# corresponding source to be offered from the same place as the binary, and FetchContent
# downloads Unicorn's at build time rather than it being in this repository's tag. So the
# exact tarball the build used goes on the release beside the APK, checked against the hash
# MacAdi.cmake pins, and the APK's assets/licences/unicorn/NOTICE.txt says where it is.
- name: Fetch Unicorn's source, as the APK was built from it
if: github.event_name == 'release'
run: |
url=$(sed -n 's/^ *URL \(https:[^ ]*unicorn[^ ]*\.tar\.gz\)$/\1/p' app/src/main/cpp/macadi/MacAdi.cmake)
sha=$(sed -n 's/^ *URL_HASH SHA256=\([0-9a-f]*\).*/\1/p' app/src/main/cpp/macadi/MacAdi.cmake)
test -n "$url" && test -n "$sha"
curl -sSfL "$url" -o "unicorn-$(basename "$url")"
echo "$sha unicorn-$(basename "$url")" | sha256sum -c -
echo "UNICORN_SOURCE=unicorn-$(basename "$url")" >> "$GITHUB_ENV"

- name: Upload APK Release Asset to GitHub Release
uses: softprops/action-gh-release@v2
if: github.event_name == 'release'
with:
files: ${{ env.main_project_module }}/build/outputs/apk/release/${{ env.app_name }}-${{ steps.extract_version.outputs.APP_VERSION }}.apk
files: |
${{ env.main_project_module }}/build/outputs/apk/release/${{ env.app_name }}-${{ steps.extract_version.outputs.APP_VERSION }}.apk
${{ env.UNICORN_SOURCE }}
name: ${{ env.app_name }} Android App ${{ steps.extract_version.outputs.APP_VERSION }}
token: ${{ secrets.ANDROID_BUILD_RELEASE_GITHUB_TOKEN }}

Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/macadi-host.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Emulated Mac (host)

# The emulated Mac's native core, built for the host and run against Apple's real macOS CoreADI.
#
# Builds app/src/main/cpp/macadi/ exactly as the app does (MacAdi.cmake is shared), fetches the
# library with the same range request the app makes, checks both pinned hashes, and has the
# emulator load it and answer "not provisioned". Nothing is sent to Apple but that one download:
# provisioning, which would register a machine, is not run.

on:
pull_request:
branches: [ "main" ]
paths:
- "app/src/main/cpp/macadi/**"
- "app/src/test/macadi-host/**"
- "app/src/main/java/dev/wander/android/opentagviewer/anisette/MacCoreAdi*.java"
- "scripts/locate_mac_coreadi.py"
- "scripts/adi-emulator-diff/**"
- ".github/workflows/macadi-host.yml"
push:
branches: [ "main" ]
paths:
- "app/src/main/cpp/macadi/**"
- "app/src/test/macadi-host/**"
- "app/src/main/java/dev/wander/android/opentagviewer/anisette/MacCoreAdi*.java"
- "scripts/locate_mac_coreadi.py"
- "scripts/adi-emulator-diff/**"
- ".github/workflows/macadi-host.yml"
workflow_dispatch:

permissions:
contents: read

jobs:
host:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Fetch Apple's macOS CoreADI the way the app does, and check both hashes
run: python scripts/locate_mac_coreadi.py --remote --out "$RUNNER_TEMP/CoreADI.x86_64"

- name: Build the native core for the host
run: |
cmake -S app/src/test/macadi-host -B "$RUNNER_TEMP/macadi" -DCMAKE_BUILD_TYPE=Release
cmake --build "$RUNNER_TEMP/macadi" --parallel

- name: Load the library and ask whether it is provisioned
run: |
out=$("$RUNNER_TEMP/macadi/macadi_cli" "$RUNNER_TEMP/CoreADI.x86_64" 979a0 /nonexistent \
00112233445566778899aabbccddeeff -1 --load-only)
echo "$out"
test "$out" = '{"loaded": true, "provisioned": false}'

- name: A guest call that never returns is stopped by the call timeout
run: '"$RUNNER_TEMP/macadi/macadi_selftest" "$RUNNER_TEMP/CoreADI.x86_64" 979a0'

# The C++ port against the Rust it was ported from, byte for byte: os-findmy-e's adi-core and
# app/src/test/macadi-host/macadi_diff.cpp make the same offline CoreADI calls with a frozen
# clock and a fixed host UUID, and the outputs must be identical. A difference is a port bug a
# successful sign-in would not show. Nothing is sent to Apple beyond the library download.
against-adi-core:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Fetch Apple's macOS CoreADI the way the app does, and check both hashes
run: python scripts/locate_mac_coreadi.py --remote --out "$RUNNER_TEMP/CoreADI.x86_64"

# unicorn-engine-sys runs bindgen, which needs libclang.
- name: Install libclang
run: sudo apt-get update -qq && sudo apt-get install -y -qq libclang-dev

- name: Compare libmacadi with adi-core
run: scripts/adi-emulator-diff/compare-libmacadi.sh "$RUNNER_TEMP/CoreADI.x86_64" "" "$RUNNER_TEMP/diff"
102 changes: 98 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ python -m venv .venv && .venv/bin/pip install "FindMy==<pinned version>"
the dependency tree resolve; every method raises. The stub is not a step toward enabling
`aniLocal`, and never will be.
- **Unicorn ships as native code, GPL-2.0 and all, and that was decided rather than missed.**
The emulated Mac (#274, in review) runs it in `libmacadi.so`. Before replacing it with a permissive
The emulated Mac (rule 21) runs it in `libmacadi.so`. Before replacing it with a permissive
emulator for licence reasons, read
[docs/emulated-mac-emulator-choice.md](./docs/emulated-mac-emulator-choice.md): a replacement
is invisible to users **only if it produces the same bytes**, because the emulator is not part
of the machine identity but its output is. `scripts/adi-emulator-diff/` is the check, and it has
not yet been run over the OTP path. The same doc says what the GPL obliges: a notice, and the
of the machine identity but its output is. `scripts/adi-emulator-diff/` is the check. CI runs it offline only; the OTP path was compared
by hand on 2026-11-20, identical, and needs `ADI_DIFF_HOST_UUID` set to the store's host UUID or
both sides just say "not provisioned" (CONTRIBUTING.md). The same doc says what the GPL obliges: a notice, and the
library kept in its own process.
- **The app does run ADI locally, by a different route.** `app/src/main/java/.../anisette/`
loads Apple's real Android ADI libraries in-process and produces Anisette here, falling
Expand Down Expand Up @@ -714,6 +715,92 @@ already sent you, and then reasoning from a guess while you wait.
had a phone number blacked out by hand, and the pixels either side of it were not. Quote the
error text, never the surrounding screen, and never re-upload the image.

### 21. Anisette comes from an emulated Mac, and it is one machine for the life of the install

Since 2026-10-12 Apple issues the Find My token (`searchPartyToken`) only to a sign-in whose
Anisette machine was minted by a Mac or an iPhone; an Android-minted one gets `mmeAuthToken` alone
and every report fetch answers 401 ([malmeloo/FindMy.py#278](https://github.com/malmeloo/FindMy.py/issues/278)).
From about 2026-10-20 the edge also answers 503 to any `X-MMe-Client-Info` whose OS token is
`Android`, whatever else is sent ([#261](https://github.com/parawanderer/OpenTagViewer/pull/261)).
So `LocalAnisette`'s Android libraries can no longer reach Find My by any combination of headers.

`EmulatedMacAnisette` runs Apple's **macOS** CoreADI - the x86_64 build in iTunes 12.8.3 - under
Unicorn, in `libmacadi.so` (`app/src/main/cpp/macadi/`, ported from sacca97/os-findmy-e; see its
`NOTICE.md`). **A fresh sign-in gets it; a restored session keeps the machine that signed it in.**

- **Never move an existing session onto the emulated Mac.** A session `LocalAnisette` signed in
before 2026-10-12 still fetches reports, and its token only works with Anisette from the Android
machine that obtained it (#248). Handing it the emulated Mac at restore downloads CoreADI,
provisions a new Mac at app start, and sends that Mac's `X-Apple-I-MD-M` beside the account's
Android `X-Mme-Device-Id` - a working session made to answer 401. `AnisetteForSession` decides,
from `SessionProvenance`: `LocalAnisette` for every session but the emulated Mac's own, and
`EmulatedMacAnisette.Purpose.RESTORE` for those, which **never provisions** - a Mac that lost its
store is not the machine that holds the token. `RestoringASessionOnTheMachineThatSignedItInTest`
pins it.
- **Provenance has one home**: `sessionEstablishedLocally` in `LocalAnisette.PREFERENCES`, the key
every older install already has, plus `sessionMachine = emulatedMac` beside it for the Mac's
sessions. A new preferences file reads "nothing recorded" for every upgrader, which silently
turned off the machine-change warning in `_preferLocalAnisette`.
- **`libmacadi.so` is loaded only in `:macadi`.** `MacAdiService` hosts the emulator and the app
reaches it over binder through `RemoteMacAdi`; nothing in the app process may touch `MacCoreAdi`,
whose static initialiser loads the library. Two reasons: a SIGSEGV from Unicorn or Apple's code
is a native crash no `catch` sees (rule 4, #232), and the GPL-2.0 emulator must stay a separate
program from the Apache-2.0 libraries and the map SDKs. A death during a call arrives as
`MacAdi.EmulatorDiedException`, is recorded per app version and library build, and the Mac is not
tried again until one of those changes. `OpenAirTagApplication` returns early in that process,
as it does in `:adiprobe`. `TheEmulatedMacInItsOwnProcessTest` checks the boundary for real.

- **The library is fetched from Apple, never shipped.** One HTTP range request: in that exact disk
image the package payload is stored uncompressed and contiguous, so its offset is a constant.
`scripts/locate_mac_coreadi.py` re-derives and checks every constant, reading them from the Java
sources. Both the payload and the library are pinned by SHA-256, and the dispatcher offset
(`0x979A0`) is only valid for that one build.
- **One identity, kept forever** - rule 11, with more at stake. `files/anisette/mac/identity.json`
and `store/` belong together: the library hashes the host UUID into the machine id, Apple binds
the provisioning to the device id, and the Find My token only works alongside Anisette from the
machine that obtained it. Apple will provision a device id **once** (a second attempt answers
HTTP 433 / -29002), so a lost store means a new machine and a new device-list entry. The same
holds for a process that died after Apple answered `midFinishProvisioning` and before the store
was saved: a sign-in that gets 433 for a never-provisioned identity draws a new one and tries
once more, or it would fall back to a server on every sign-in after.
- **Never leave `adi.pb` in the store.** Provisioning writes the legacy whole-machine blob beside
the per-user one, and while it exists the library says "not provisioned". A process that
provisioned and then asked for headers sent Apple an empty machine id, which surfaces as
**`ec -80009`, "MID is invalid"** - and looked like an emulation fault until a restart, which
never reloads the file, made it go away. `CoreAdi::beginSession` drops it before every session.
- **A Mac's device id is not a UUID**, and FindMy.py's CloudKit client parses it as one. The
keychain and CloudKit clients get `icloud_bridge._forCloudKit`'s view of the account instead,
which answers `device_uuid` with a UUID derived from the device id and forwards everything
else. Not the Mac's host UUID: a session that falls back to a remote server has no Mac to ask,
and it would tell CloudKit a second device. Anything new that
hands the account to CloudKit has to go through it.
- **Never freeze the emulated clock outside a byte-for-byte comparison.** A constant OTP is
accepted for about a minute and then refused.
- **Grand Slam now asks for a second factor with `hsc` 409 and no `au`**, which FindMy.py before
parawanderer/FindMy.py#9 read as "no 2FA needed". The pinned FindMy.py handles it in
`_gsa_authenticate` (`_normalize_2fa_status`, as malmeloo/FindMy.py#279 has it), so the app no
longer wraps `_gsa_request`. `test_emulated_mac.TestHsc409` fails if a pin move loses it.
- **The APK carries GPL-2.0 code** (Unicorn). Keep it in `libmacadi.so`, not in
`libopentagviewer.so`, and keep its obligations met: `assets/licences/unicorn/` carries the
licence files and a notice naming the exact source (`UnicornNoticeTest` keeps it in step with
`MacAdi.cmake`), and `build-release.yml` attaches that source tarball to every release.
- **The C++ port is checked against os-findmy-e's Rust byte for byte**, offline:
`scripts/adi-emulator-diff/compare-libmacadi.sh`, in `macadi-host.yml`. Change `vm.cpp`,
`core_adi.cpp` or `macho.cpp` and that job is what says whether the port still matches.
- **`:macadi` is long-lived, so the emulator must not grow or hang.** One engine serves every
header set for the process's life. Unicorn's default 1 GiB translation cache, flushed only when
full, grew it ~20 KB a call without end; `Vm` caps it at 8 MiB. A guest call has a 30 s timeout,
because a loop under emulation would otherwise hold a core and the app's binder call forever.
The process is let go after five idle minutes (`EmulatedMacAnisette.IDLE_CLOSE_MS`) and reopened
from the store. `macadi_selftest` checks the timeout in CI and memory over many calls by hand.

The emulator suite's sign-in tests cannot cover any of this - they swap the Anisette source for a
fake. What does: the JVM tests (`EmulatedMacAnisetteTest`, `MacIdentityTest`,
`MacProvisioningTest` against `FakeGrandSlam`, `RestoringASessionOnTheMachineThatSignedItInTest`,
the fetcher's), `macadi-host.yml` (the library loads in the ported emulator, and matches adi-core),
`TheEmulatedMacInItsOwnProcessTest` on the device, the Python tests in `test_emulated_mac.py`, and a
real sign-in on a phone.

---

## Building and testing
Expand Down Expand Up @@ -1079,7 +1166,14 @@ Each of these has already produced a hang that looked like something else:
wrap one in a `grep` or a `timeout` that can swallow the error message — that turns a fast,
legible failure into an apparent hang. `JAVA_HOME` pointing below 17 is the usual culprit,
and it fails deep inside the Android Gradle Plugin with a message that reads like a plugin
bug.
bug. Above 21 fails too: Android Studio's bundled Java 25 makes Gradle 8.10 fail with only
`25.0.4` as its message.
- **The native build needs `sh`, `strings` and `pkg-config`.** Unicorn's CMake runs
`sh qemu/configure` without checking the result, so from PowerShell or Android Studio it used
to "succeed" and the compile then died on `'config-host.h' file not found`. `MacAdi.cmake` now
names the missing tool up front. A Git Bash shell can still pass where the IDE fails, because
it puts more on `PATH`: test with the PATH the IDE gets, not your shell's. See CONTRIBUTING's
setup table, and delete `app/.cxx` after fixing it.

## Conventions

Expand Down
Loading
Loading