Skip to content

Commit 7fc41e4

Browse files
committed
Add ThreeAppBypass functionality and MobileGestalt view
- Implemented ThreeAppBypassManager for patch loading and application. - Created ThreeAppBypassView for user interaction with patch management. - Added MobileGestaltView for managing MobileGestalt entries with save/load functionality. - Introduced Makefile and README for the ThreeAppBypass tweak. - Developed scripts for symbol resolution, IPSW extraction, and binary handling. - Added example symbol maps and patches for demonstration. - Implemented logging and error handling throughout the new features.
1 parent c70d758 commit 7fc41e4

29 files changed

Lines changed: 1564 additions & 0 deletions

Docs/3AppBypass_Plan.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 3 App Bypass — Implementation Plan (sideload 3‑app limit)
2+
3+
Goal
4+
- Provide a jailbroken-device feature to bypass Apple's 3‑app sideload limit so users can install more than three sideloaded apps via free provisioning approaches.
5+
6+
Summary of approaches
7+
8+
A) User-level tooling (low-risk)
9+
- Use or integrate with AltStore/AltServer workflows to avoid the limit (refresh provisioning, re-sign apps periodically).
10+
- Pros: safe, no kernel/daemon patching. Cons: limited automation and needs a companion host app.
11+
12+
B) Daemon-level patch (medium-risk, recommended first prototype)
13+
- Target daemons that enforce installation/validation (primarily `installd`, `installcoordination`, and related processes) and intercept logic that rejects additional installations.
14+
- Alternatively, patch `amfid` to accept unsigned/modified signatures for selected bundles.
15+
- Pros: precise, can be scoped to specific processes or bundle IDs. Cons: requires jailbreak (code injection or tweaks), reverse-engineering per iOS version.
16+
17+
C) Kernel-level bypass (high-risk)
18+
- Patch AMFI kernel enforcement (AppleMobileFileIntegrity) or code-signing enforcement points in kernel/kexts to globally disable signing/count checks.
19+
- Pros: broad coverage. Cons: highest risk, version-specific offsets, dangerous if incorrect (can brick device).
20+
21+
Recommended path
22+
1. Prototype a daemon-level tweak that hooks `amfid` or `installd` behavior for the install/validation code path used during sideload with free developer provisioning. This mirrors historical approaches (AppSync-style) and avoids direct kernel patches.
23+
2. Provide a conservative UI to enable/disable the bypass per-app and to create automatic rollback (restore original binaries or restart daemons).
24+
3. If daemon patching proves insufficient (server-side checks or external enforcement), evaluate a narrowly scoped kernel patch with extensive backups and explicit user warnings.
25+
26+
Required components
27+
- Jailbreak or kernel write primitives from `lara` (for persistent patching and overwriting system files).
28+
- Offset mapping for target iOS versions (function addresses in `amfid`/`installd`/kernel). Keep an offsets checklist per iOS build.
29+
- A tweak skeleton to inject code into `amfid`/`installd` (Theos/MobileSubstrate or Substitute) with per-OS symbol resolution.
30+
- Safe backup & revert: backup original daemons/binaries and the AMFI cache before applying changes.
31+
32+
Known references / PoCs
33+
- AppSync-style packages (historical jailbreak solutions that allow unsigned apps).
34+
- ProjectManticore / amfid bypass PoCs on GitHub (search results: ProjectManticore, amfidont).
35+
- The iPhone Wiki entries for `AMFI` and `installd` describing historical approaches.
36+
- AltStore (non-jailbreak sideload alternative) for user-level strategy.
37+
38+
Testing and safety
39+
- Only enable bypass on confirmed jailbroken devices; detect jailbreak early and refuse on stock devices.
40+
- Create an explicit backup before modifying any system binary or the code-sign trust cache. Provide a one-tap restore.
41+
- Test across a small matrix of iOS builds (17.5–18.6.2 baseline as with `lara`) and device types.
42+
43+
Next steps (immediate)
44+
1. Locate and extract `amfid`/`installd` symbols for target iOS builds (requires device access or symbol dumps). Produce a short list of candidate functions to hook.
45+
2. Scaffold a MobileSubstrate tweak skeleton that logs calls and can return a forced "valid" result for signature checks in-process.
46+
3. Validate the tweak on a test device and implement safe revert.
47+
48+
Helpers added
49+
- `other/3app-bypass/scripts/get_device_binaries.sh` — SCP helper to pull binaries from a jailbroken device.
50+
- `other/3app-bypass/scripts/scan_symbols.py` — scan local binaries for likely amfid/installd/AMFI-related symbols using `nm`/`otool`/`strings`.
51+
52+
Usage examples
53+
- Pull binaries from device:
54+
55+
```bash
56+
./other/3app-bypass/scripts/get_device_binaries.sh root@192.168.1.42 ./work/binaries
57+
```
58+
59+
- Scan the pulled binaries:
60+
61+
```bash
62+
./other/3app-bypass/scripts/scan_symbols.py ./work/binaries/amfid ./work/binaries/installd
63+
```
64+
65+
66+
Notes
67+
- This feature is intended for jailbroken devices only. It may violate App Store/Apple policies if used to distribute apps circumventing platform protections; include clear warnings and an opt-in flow.
68+
- Keep patches minimal and reversible.
69+
70+
Status: plan created. Next: scaffold tweak skeleton and start identifying amfid/installd symbols on-device.

Docs/3AppBypass_Research.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 3 App Bypass — Research Notes
2+
3+
Goal: Implement a feature to bypass the "3 App" limitation (context to confirm) and provide user controls in `lara`.
4+
5+
Open questions (to resolve via research):
6+
- Confirm meaning of "3 App Bypass" in project context: does it refer to:
7+
- Bypassing Apple's limit on sideloaded apps with free Apple IDs (3-app limit), or
8+
- Bypassing App Store / Managed Device restrictions that limit installed apps, or
9+
- A different, project-specific restriction (ask owner if ambiguous).
10+
11+
Potential technical approaches:
12+
1. Modify MobileDevice/amsd responses or provisioning checks to allow additional unsigned apps.
13+
2. Patch system daemons that enforce app count (if present) or alter code signing checks via kernel patches.
14+
3. Use per-app entitlements or container modifications to trick the system into treating apps differently.
15+
16+
Risks and prerequisites:
17+
- Many approaches require kernel privileges and correct offsets per iOS version.
18+
- High risk of device instability; must provide good rollback.
19+
20+
Next steps:
21+
1. Confirm exact intended bypass behavior with project owner (clarify scope).
22+
2. Search for existing bypass implementations and PoCs.
23+
3. Map required kernel hooks / entitlements and create minimal prototype plan.
24+
25+
Status: research started. Next: confirm meaning and gather PoCs.

Docs/3AppBypass_Sources.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 3 App Bypass — Community Sources & PoCs
2+
3+
Collected public resources (initial):
4+
5+
- `zqxwce/amfidont` — simple amfid bypass utility (GitHub): https://github.com/zqxwce/amfidont
6+
- `ProjectManticore` — jailbreak project with historical amfid bypass references: https://github.com/ProjectManticore/Manticore
7+
- Historical AppSync-style packages and discussions (search GitHub for AppSync / installd tweaks).
8+
- The iPhone Wiki pages for AMFI and `installd` (background): https://www.theiphonewiki.com/wiki/AppleMobileFileIntegrity and https://www.theiphonewiki.com/wiki/Installd
9+
- Community MobileGestalt and MobileGestalt patcher repos discovered earlier (for reference): `MGKeys`, `autoPatcher-mobilegestalt`, `MobileGestalt-hook` (search GitHub for "MobileGestalt").
10+
11+
Notes:
12+
- Public PoCs exist but may not include symbol maps or offsets for iOS 18.x; many projects target older iOS versions and need per-build offsets.
13+
- Next step: search community symbol dumps and offsets repos (e.g., `offsets` / `symbols` JSON in GitHub), or extract symbols from IPSW if unavailable.
14+
15+
How to contribute symbol maps:
16+
- If you have a device or IPSW for a target build, extract `amfid`/`installd` and run `other/3app-bypass/scripts/scan_symbols.py`.
17+
- Produce a JSON map at `/var/mobile/Library/lara/3appbypass_symbols.json` with resolved addresses for the tweak to use.

Docs/FinishAndReleasePlan.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Finish & Release Plan — lara
2+
3+
Goal: finish a working release that includes MobileGestalt Editor (viewer + runtime overrides + KFS persistence) and a tested 3‑App bypass prototype (daemon/tweak approach) for jailbroken devices.
4+
5+
Milestones (2–5 days estimate depending on device access):
6+
7+
1) MobileGestalt polish (0.5 day)
8+
- Add concise logging in `MobileGestaltManager` and `MobileGestaltView` (already present).
9+
- Ensure Save/Load/Apply show clear status and errors across cases.
10+
- Add UI link in settings or main menu (done).
11+
12+
2) KFS verification & backups (0.5–1 day)
13+
- Verify `saveOverridesToKFS`, `loadOverridesFromKFS`, `applyOverridesToSystemCache`, and restore on a test device.
14+
- Confirm backup file exists and restore works across reboots.
15+
16+
3) Tests & compatibility matrix (0.5 day)
17+
- Create manual test checklist and minimal unit tests where possible (plist serialization, override persistence).
18+
- Document tested iOS builds and device types.
19+
20+
4) Tweak symbol resolution & scripts (1 day)
21+
- Use `get_device_binaries.sh` + `scan_symbols.py` to identify candidate symbols.
22+
- Populate `/var/mobile/Library/lara/3appbypass_symbols.json` example for target builds.
23+
- Verify tweak hooks by address via the JSON map.
24+
25+
5) Prototype and test tweak on-device (1–2 days)
26+
- Build Theos package (`make package`), install on test device, observe logs.
27+
- Iterate until signature checks are reliably bypassed for test bundles.
28+
- Always keep backups and a documented rollback (restore AMFI cache + original daemon).
29+
30+
6) Safety, docs, and release (0.5 day)
31+
- Add warnings, opt-in toggles, and recovery instructions to `Docs/3AppBypass_Plan.md` and `README.md`.
32+
- Package example symbol maps under `other/3app-bypass/examples/`.
33+
- Tag release and produce short changelog.
34+
35+
Quick test commands (local dev)
36+
37+
- Pull binaries:
38+
39+
```bash
40+
./other/3app-bypass/scripts/get_device_binaries.sh root@<device_ip> ./work/binaries
41+
```
42+
43+
- Scan binaries:
44+
45+
```bash
46+
./other/3app-bypass/scripts/scan_symbols.py ./work/binaries/amfid ./work/binaries/installd
47+
```
48+
49+
- Build tweak (on host with Theos):
50+
51+
```bash
52+
cd other/3app-bypass
53+
make package
54+
```
55+
56+
Notes & warnings
57+
- 3 App Bypass is intended for jailbroken devices only. Provide explicit warnings and require manual confirmation for any destructive actions.
58+
- Do not attempt kernel-level patches until daemon-level prototype is exhausted; kernel patches are high-risk.
59+
60+
Status: plan created. Begin with MobileGestalt verification and KFS tests, then move to tweak symbol resolution.

Docs/ImplementationPlan.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Implementation Plan — MobileGestalt Editor & 3 App Bypass
2+
3+
Summary
4+
- MobileGestalt Editor: provide safe viewer + runtime override ability, plus optional persistent patching for keys that cannot be overridden in userland.
5+
- 3 App Bypass: implement (device-jailbreak-only) kernel/daemon patches to bypass Apple's 3-app sideload limit; high-risk, requires kernel privileges and careful rollback.
6+
7+
MobileGestalt — technical approaches
8+
1. Read-only viewer
9+
- Use existing Swift wrappers (e.g., `p-x9/swift-mobile-gestalt`) to call `MGCopyAnswer`/`Gestalt` APIs and list keys.
10+
2. Runtime overrides (preferred first-step)
11+
- Hook MobileGestalt API calls in-process using:
12+
- `fishhook` for C symbol rebinding (works for non-Objective-C symbols bound via dyld), or
13+
- MobileSubstrate / Substrate-like hooking (for tweaks), or
14+
- `DYLD_INSERT_LIBRARIES` / dyld interpose for processes we control.
15+
- Create an in-memory override table that returns patched values for selected keys.
16+
3. Persistent patching (fallback)
17+
- Some keys are generated by system daemons or from binary blobs. For these, use an offsets-based patcher (see `Rust505/autoPatcher-mobilegestalt`) to modify MobileGestalt.plist or daemon behavior using kernel write primitives provided by `lara`.
18+
19+
3 App Bypass — technical approaches
20+
1. User-level workaround (low-risk)
21+
- Recommend using tools like AltStore/AltServer to sideload without addressing system limits.
22+
2. Daemon/Service patch (medium-risk)
23+
- Identify the system daemon enforcing the limit (install-related or server-side checks). Hook or patch its enforcement path to ignore the count. Needs careful reverse-engineering per iOS version.
24+
3. Kernel-level bypass (high-risk)
25+
- Patch code-signing checks (amfid/ksystem) or interception points where the system validates developer provisioning counts. Requires kernel offsets and write primitives from `lara`.
26+
27+
Security, risk, and rollback
28+
- All persistent or kernel patches must implement safe revert operations and backups of modified blobs.
29+
- Warn users and provide an explicit confirmation plus automated revert option.
30+
- Limit UI options to jailbroken devices / devices where `lara` confirms privileges.
31+
32+
Immediate next steps (short-term tasks)
33+
1. Build a read-only MobileGestalt viewer in `lara` using `swift-mobile-gestalt`.
34+
2. Implement runtime hooking prototype for MobileGestalt using `fishhook` in a test target to validate overrides for `ProductType`, `RegionInfo`, etc.
35+
3. Confirm exact target for 3 App Bypass (we have confirmation: sideload 3-app limit). Start by searching amfid/installd/related daemons for enforcement logic.
36+
4. Map kernel offsets and entitlements needed for persistent patching; add to `Docs/OffsetsChecklist.md`.
37+
38+
References (initial)
39+
- Fishhook: https://github.com/facebook/fishhook
40+
- GitHub search results for MobileGestalt (repos: `MGKeys`, `MobileGestaltHooking`, `autoPatcher-mobilegestalt`, `retr0devops/MobileGestalt-hook`)
41+
- AltStore: https://altstore.io/
42+
43+
Delivery
44+
- Create `MobileGestalt` viewer UI and backend API in `lara`.
45+
- Add a developer-only "Experiment" section for runtime overrides with logs and revert.
46+
- If you approve, I will start implementing the read-only viewer and the `fishhook`-based runtime override prototype next.

Docs/MobileGestalt_Research.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# MobileGestalt Editor — Research Notes
2+
3+
Goal: Add UI + backend to view and edit MobileGestalt keys on-device.
4+
5+
Background summary:
6+
- MobileGestalt is an iOS system service (private API) that provides device properties (e.g., "ProductType", "SerialNumber", "RegionInfo").
7+
- Many keys are derived from hardware, provisioning profiles, or system configuration; some are read-only without kernel or sandbox bypass.
8+
9+
Areas to research (next actions):
10+
1. MobileGestalt API surfaces (libMobileGestalt, MobileGestalt.c) and how to call from Swift.
11+
2. Which keys are stored in preferences/plists vs. derived by kernel/hardware.
12+
3. Existing tools that patch MobileGestalt responses (MobileGestaltServer patching, jailbreak tweaks, dyld interpose approaches).
13+
4. Feasibility of per-key runtime interception (xpc proxy, function interpose) vs. persistent system plist edits.
14+
5. Required entitlements, sandbox/kext/kernel access, and offsets for supported iOS versions (17.5–18.6.2 baseline).
15+
16+
Deliverables for implementation:
17+
- A safe read-only viewer for MobileGestalt keys.
18+
- An edit flow that attempts non-destructive runtime overrides first (in-memory/interpose), with fallback to persistent patching when possible.
19+
- Backend APIs in `lara` to get/set keys and to revert changes.
20+
21+
References (to gather):
22+
- Apple internal docs and libMobileGestalt headers (search web)
23+
- Jailbreak tweak sources that modify MobileGestalt
24+
- dyld interposing examples and XPC proxy hooking patterns
25+
26+
Status: research started. Next: gather authoritative resources and examples.

Docs/References.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# References — collected links
2+
3+
MobileGestalt resources and examples:
4+
- GitHub search: https://github.com/search?q=MobileGestalt
5+
- MGKeys (deobfuscation): https://github.com/PoomSmart/MGKeys
6+
- MobileGestalt hooking examples: https://github.com/Naville/MobileGestaltHooking
7+
- autoPatcher-mobilegestalt (offset-based patcher): https://github.com/Rust505/autoPatcher-mobilegestalt
8+
- Example hooks: https://github.com/retr0devops/MobileGestalt-hook
9+
- Swift wrapper: https://github.com/p-x9/swift-mobile-gestalt
10+
11+
Hooking and interpose tools:
12+
- fishhook (symbol rebinding): https://github.com/facebook/fishhook
13+
- dyld interposing (OSX/iOS dyld technique): https://opensource.apple.com/
14+
15+
3 App / sideloading resources:
16+
- AltStore (sideloading tooling): https://altstore.io/
17+
18+
Notes:
19+
- Collected links are a starting point for implementation and reverse-engineering.
20+
- Several community PoCs exist for MobileGestalt; examine licensing and copyright before reuse.

lara/MobileGestaltBridge.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// MobileGestaltBridge.h
3+
// Bridge to call MGCopyAnswer from Swift
4+
//
5+
6+
#import <Foundation/Foundation.h>
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
FOUNDATION_EXPORT NSString * _Nullable MGCopyAnswerString(NSString *key);
11+
12+
NS_ASSUME_NONNULL_END

lara/MobileGestaltBridge.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// MobileGestaltBridge.m
3+
// Objective-C bridge implementation that calls MGCopyAnswer via dlsym.
4+
//
5+
6+
#import "MobileGestaltBridge.h"
7+
#import <dlfcn.h>
8+
#import <CoreFoundation/CoreFoundation.h>
9+
10+
typedef CFTypeRef (*MGCopyAnswerFunc)(CFStringRef key);
11+
12+
NSString * MGCopyAnswerString(NSString *key) {
13+
if (!key) return nil;
14+
static MGCopyAnswerFunc mgFunc = NULL;
15+
if (!mgFunc) {
16+
mgFunc = (MGCopyAnswerFunc)dlsym(RTLD_DEFAULT, "MGCopyAnswer");
17+
}
18+
if (!mgFunc) return nil;
19+
20+
CFStringRef cfKey = (__bridge CFStringRef)key;
21+
CFTypeRef result = mgFunc(cfKey);
22+
if (!result) return nil;
23+
24+
NSString *str = nil;
25+
CFTypeID t = CFGetTypeID(result);
26+
if (t == CFStringGetTypeID()) {
27+
str = CFBridgingRelease(result);
28+
} else if (t == CFNumberGetTypeID()) {
29+
long long v = 0;
30+
CFNumberGetValue((CFNumberRef)result, kCFNumberLongLongType, &v);
31+
str = [NSString stringWithFormat:@"%lld", v];
32+
CFRelease(result);
33+
} else if (t == CFBooleanGetTypeID()) {
34+
Boolean b = CFBooleanGetValue((CFBooleanRef)result);
35+
str = b ? @"true" : @"false";
36+
CFRelease(result);
37+
} else {
38+
CFStringRef desc = CFCopyDescription(result);
39+
if (desc) {
40+
str = CFBridgingRelease(desc);
41+
} else {
42+
str = @"<non-string>";
43+
}
44+
CFRelease(result);
45+
}
46+
47+
return str;
48+
}

0 commit comments

Comments
 (0)