#!/usr/bin/env bash # make_app.sh — materialise the Track B probe and zip it to app.zip set -euo pipefail OUT="AVEProbe" rm -rf "$OUT" app.zip mkdir -p "$OUT" cd "$OUT" cat > MANIFEST.txt <<'EOF' Target: iOS app, arm64, deployment target 15.0 Bundle id: ai.chollima.aveprobe Executable: AVEProbe Frameworks: UIKit, IOKit, Foundation ARC: on (-fobjc-arc) Signing: none — Sideloadly signs on Windows. Do not run ldid or codesign. Toolchain: Theos application template, TARGET = iphone:clang::15.0 Output: AVEProbe.ipa containing Payload/AVEProbe.app Info.plist must sit beside the sources; Theos picks it up as the app plist. Entitlements are optional and will not survive a free certificate. Do not rewrite the IOKit call shapes — the probe depends on exact return codes. EOF cat > AVEClient.h <<'EOF' #import #import @interface AVEClient : NSObject - (BOOL)matchService; - (BOOL)openType:(uint32_t)type; - (void)closeConn; - (kern_return_t)callSelector:(uint32_t)sel input:(NSData *)in; - (void)sweepTypes; - (void)sweepSelectors; - (void)bisectSelector:(uint32_t)sel; - (void)prepareThenStart; - (NSString *)logText; @end EOF cat > AVEClient.m <<'EOF' #import "AVEClient.h" // ---- knobs: all UNKNOWN until the sweep and bisection have run ---- static uint32_t SEL_PREPARE = 0; static uint32_t SEL_START = 1; static size_t IN_SIZE = 0x1000; static uint32_t CLIENT_TYPE = 1; // offsets inside pInfo, NOT inside pIn. Relation between the two is unknown. static NSInteger OFF_MODE = 0x5c; static NSInteger OFF_LAYERS = 0x68; static NSInteger PPS_COUNT = 0x14d8; // pInfo side of pClient+0x2138; unverified @interface AVEClient () @property (nonatomic) io_service_t service; @property (nonatomic) io_connect_t conn; @end @implementation AVEClient - (instancetype)init { if ((self = [super init])) { _service = 0; _conn = 0; } return self; } - (void)log:(NSString *)fmt, ... { va_list ap; va_start(ap, fmt); NSString *s = [[NSString alloc] initWithFormat:fmt arguments:ap]; va_end(ap); NSLog(@"AVEC %@", s); NSURL *u = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject]; NSURL *f = [u URLByAppendingPathComponent:@"ave.txt"]; NSData *d = [[s stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]; NSFileHandle *h = [NSFileHandle fileHandleForWritingAtPath:f.path]; if (h) { [h seekToEndOfFile]; [h writeData:d]; [h closeFile]; } else { [d writeToURL:f atomically:YES]; } } - (NSString *)logText { NSURL *u = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject]; return [NSString stringWithContentsOfURL:[u URLByAppendingPathComponent:@"ave.txt"] encoding:NSUTF8StringEncoding error:NULL] ?: @""; } - (BOOL)matchService { io_service_t s = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleAVE2")); self.service = s; [self log:@"service %u", s]; return s != 0; } - (BOOL)openType:(uint32_t)type { if (!self.service && ![self matchService]) return NO; io_connect_t c = 0; kern_return_t r = IOServiceOpen(self.service, mach_task_self(), type, &c); [self log:@"open type %u -> 0x%08x", type, r]; if (r == KERN_SUCCESS) { self.conn = c; return YES; } return NO; } - (void)closeConn { if (self.conn) { IOServiceClose(self.conn); self.conn = 0; } } - (kern_return_t)callSelector:(uint32_t)sel input:(NSData *)in { uint8_t out[0x1000]; size_t outSize = sizeof out; kern_return_t r = IOConnectCallStructMethod(self.conn, sel, in.bytes, in.length, out, &outSize); [self log:@"sel %u in %lu -> 0x%08x out %lu", sel, (unsigned long)in.length, r, (unsigned long)outSize]; return r; } - (void)sweepTypes { if (![self matchService]) return; for (uint32_t t = 0; t <= 5; t++) { if ([self openType:t]) [self closeConn]; } [self log:@"types done"]; } - (void)sweepSelectors { if (![self openType:CLIENT_TYPE]) return; NSData *zero = [NSMutableData dataWithLength:IN_SIZE]; for (uint32_t s = 0; s < 40; s++) { kern_return_t r = [self callSelector:s input:zero]; if (r != kIOReturnUnsupported && r != kIOReturnBadArgument) [self log:@"CANDIDATE sel %u -> 0x%08x", s, r]; } [self closeConn]; [self log:@"selectors done"]; } // assert order: pIn != null, inSize >= sizeof, pOut != null. - (void)bisectSelector:(uint32_t)sel { if (![self openType:CLIENT_TYPE]) return; size_t lo = 0x20, hi = 0x4000; while (hi - lo > 8) { size_t mid = (lo + hi) / 2; kern_return_t r = [self callSelector:sel input:[NSMutableData dataWithLength:mid]]; [self log:@"bisect %lu -> 0x%08x", (unsigned long)mid, r]; if (r == kIOReturnBadArgument) lo = mid; else hi = mid; } [self log:@"boundary %lu..%lu", (unsigned long)lo, (unsigned long)hi]; [self closeConn]; } - (void)prepareThenStart { if (![self openType:CLIENT_TYPE]) return; NSMutableData *in = [NSMutableData dataWithLength:IN_SIZE]; uint8_t *b = in.mutableBytes; if ((size_t)OFF_MODE < IN_SIZE) b[OFF_MODE] = 2; if ((size_t)OFF_LAYERS < IN_SIZE) b[OFF_LAYERS] = 2; if ((size_t)PPS_COUNT + 4 <= IN_SIZE) *(uint32_t *)(b + PPS_COUNT) = 9; if ([self callSelector:SEL_PREPARE input:in] == KERN_SUCCESS) [self callSelector:SEL_START input:in]; [self closeConn]; [self log:@"prepare/start done"]; } @end EOF cat > ViewController.h <<'EOF' #import @interface ViewController : UIViewController @end EOF cat > ViewController.m <<'EOF' #import "ViewController.h" #import "AVEClient.h" @interface ViewController () @property (nonatomic) AVEClient *client; @property (nonatomic) UITextView *logView; @property (nonatomic) UITextField *selField; @property (nonatomic) UITextField *startField; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.client = [AVEClient new]; self.view.backgroundColor = UIColor.systemBackgroundColor; UIStackView *v = [[UIStackView alloc] init]; v.axis = UILayoutConstraintAxisVertical; v.spacing = 8; v.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:v]; UIStackView *row1 = [[UIStackView alloc] init]; row1.distribution = UIStackViewDistributionFillEqually; row1.spacing = 8; [row1 addArrangedSubview:[self button:@"Sweep types" action:@selector(sweepTypes)]]; [row1 addArrangedSubview:[self button:@"Sweep selectors" action:@selector(sweepSelectors)]]; [v addArrangedSubview:row1]; self.selField = [self field:@"prepare sel" text:@"0"]; self.startField = [self field:@"start sel" text:@"1"]; UIStackView *row2 = [[UIStackView alloc] init]; row2.spacing = 8; [row2 addArrangedSubview:self.selField]; [row2 addArrangedSubview:self.startField]; [v addArrangedSubview:row2]; UIStackView *row3 = [[UIStackView alloc] init]; row3.distribution = UIStackViewDistributionFillEqually; row3.spacing = 8; [row3 addArrangedSubview:[self button:@"Bisect" action:@selector(bisect)]]; [row3 addArrangedSubview:[self button:@"Prepare+Start" action:@selector(prepareStart)]]; [v addArrangedSubview:row3]; self.logView = [[UITextView alloc] init]; self.logView.editable = NO; self.logView.font = [UIFont monospacedSystemFontOfSize:10 weight:UIFontWeightRegular]; self.logView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:self.logView]; [NSLayoutConstraint activateConstraints:@[ [v.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:8], [v.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:12], [v.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-12], [self.logView.topAnchor constraintEqualToAnchor:v.bottomAnchor constant:12], [self.logView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:12], [self.logView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-12], [self.logView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-8], ]]; [self refresh]; } - (UIButton *)button:(NSString *)t action:(SEL)a { UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem]; [b setTitle:t forState:UIControlStateNormal]; [b addTarget:self action:a forControlEvents:UIControlEventTouchUpInside]; b.backgroundColor = UIColor.secondarySystemBackgroundColor; b.layer.cornerRadius = 8; b.titleLabel.font = [UIFont systemFontOfSize:13]; [b.heightAnchor constraintEqualToConstant:40].active = YES; return b; } - (UITextField *)field:(NSString *)ph text:(NSString *)t { UITextField *f = [[UITextField alloc] init]; f.placeholder = ph; f.text = t; f.borderStyle = UITextBorderStyleRoundedRect; f.keyboardType = UIKeyboardTypeNumberPad; return f; } - (void)sweepTypes { [self.client sweepTypes]; [self refresh]; } - (void)sweepSelectors { [self.client sweepSelectors]; [self refresh]; } - (void)bisect { [self.client bisectSelector:(uint32_t)self.selField.text.intValue]; [self refresh]; } - (void)prepareStart { [self.client prepareThenStart]; [self refresh]; } - (void)refresh { self.logView.text = [self.client logText]; } @end EOF cat > AppDelegate.m <<'EOF' #import #import "ViewController.h" @interface AppDelegate : UIResponder @property (nonatomic) UIWindow *window; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts { self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; self.window.rootViewController = [ViewController new]; [self.window makeKeyAndVisible]; return YES; } @end int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, @"AppDelegate"); } } EOF cat > Info.plist <<'EOF' CFBundleExecutableAVEProbe CFBundleIdentifierai.chollima.aveprobe CFBundleNameAVEProbe CFBundleVersion1 CFBundleShortVersionString0.1 LSRequiresIPhoneOS MinimumOSVersion15.0 UIFileSharingEnabled LSSupportsOpeningDocumentsInPlace UILaunchScreen UISupportedInterfaceOrientations UIInterfaceOrientationPortrait EOF cat > AVEProbe.entitlements <<'EOF' com.apple.security.iokit-user-client-class AppleAVE2UserClient com.apple.security.exception.iokit-user-client-class AppleAVE2UserClient EOF cat > Makefile <<'EOF' TARGET = iphone:clang:16.5:15.0 ARCHS = arm64 INSTALL_TARGET_PROCESSES = AVEProbe include $(THEOS)/makefiles/common.mk APPLICATION_NAME = AVEProbe AVEProbe_FILES = AVEClient.m ViewController.m AppDelegate.m AVEProbe_FRAMEWORKS = UIKit IOKit Foundation AVEProbe_CFLAGS = -fobjc-arc include $(THEOS_MAKE_PATH)/application.mk EOF cat > package.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail export THEOS=${THEOS:-$HOME/theos} make clean all APP=$(find .theos -name 'AVEProbe.app' -type d | head -1) [ -n "$APP" ] || { echo "no .app built"; exit 1; } rm -rf Payload AVEProbe.ipa && mkdir -p Payload cp -R "$APP" Payload/ zip -qry AVEProbe.ipa Payload && rm -rf Payload echo "AVEProbe.ipa ready" EOF cat > README.md <<'EOF' # Track B probe AppleAVE2 user-client probe for iOS 27.0.1 / T8140. Builds on Linux with Theos, sideloaded from Windows. Answers three questions: does the sandbox allow the open, which external-method selectors exist, and how big is S_AVE_UCInParam_Prepare. ## Order 1. Sweep types. 0xe00002c1 on all of them means the sandbox blocks it and the track needs mediaserverd instead. 2. Sweep selectors. CANDIDATE lines are real calls; the driver log names which is IO_Prepare / IO_Start. 3. Enter the prepare selector, press Bisect. The size where the return code changes is sizeof(S_AVE_UCInParam_Prepare). 4. Prepare+Start only after the layout is filled in. ## Knobs, AVEClient.m SEL_PREPARE, SEL_START, IN_SIZE, OFF_MODE, OFF_LAYERS, PPS_COUNT. All guesses except CLIENT_TYPE. Nothing here has been run. ## Entitlement com.apple.security.iokit-user-client-class. A free profile does not carry it. Try the plain build first; add it in Sideloadly Advanced only if the open is denied. EOF chmod +x package.sh cd .. if command -v zip >/dev/null 2>&1; then zip -qry app.zip "$OUT" else python3 -c "import zipfile,os,sys z=zipfile.ZipFile('app.zip','w',zipfile.ZIP_DEFLATED) for r,_,fs in os.walk(sys.argv[1]): for f in fs: z.write(os.path.join(r,f))" "$OUT" fi unzip -l app.zip