Skip to content

Commit

Permalink
Fixes #57: Wait for device on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
zner0L authored and baltpeter committed May 23, 2023
1 parent 8503ea4 commit f0d5e40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
20 changes: 10 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ A supported attribute for the `getDeviceAttribute()` function, depending on the

#### Defined in

[index.ts:373](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L373)
[index.ts:374](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L374)

___

Expand All @@ -100,7 +100,7 @@ The options for each attribute available through the `getDeviceAttribute()` func

#### Defined in

[index.ts:379](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L379)
[index.ts:380](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L380)

___

Expand All @@ -112,7 +112,7 @@ An ID of a known permission on iOS.

#### Defined in

[ios.ts:389](https://github.com/tweaselORG/appstraction/blob/main/src/ios.ts#L389)
[ios.ts:392](https://github.com/tweaselORG/appstraction/blob/main/src/ios.ts#L392)

___

Expand Down Expand Up @@ -199,7 +199,7 @@ The options for the `platformApi()` function.

#### Defined in

[index.ts:311](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L311)
[index.ts:312](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L312)

___

Expand All @@ -218,7 +218,7 @@ Connection details for a proxy.

#### Defined in

[index.ts:387](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L387)
[index.ts:388](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L388)

___

Expand Down Expand Up @@ -248,7 +248,7 @@ The options for a specific platform/run target combination.

#### Defined in

[index.ts:338](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L338)
[index.ts:339](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L339)

___

Expand All @@ -266,7 +266,7 @@ A capability for the `platformApi()` function.

#### Defined in

[index.ts:366](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L366)
[index.ts:367](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L367)

___

Expand Down Expand Up @@ -308,7 +308,7 @@ Configuration string for WireGuard.

#### Defined in

[index.ts:394](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L394)
[index.ts:395](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L395)

## Variables

Expand All @@ -332,7 +332,7 @@ The IDs of known permissions on iOS.

#### Defined in

[ios.ts:372](https://github.com/tweaselORG/appstraction/blob/main/src/ios.ts#L372)
[ios.ts:375](https://github.com/tweaselORG/appstraction/blob/main/src/ios.ts#L375)

## Functions

Expand Down Expand Up @@ -425,4 +425,4 @@ The API object for the given platform and run target.

#### Defined in

[index.ts:403](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L403)
[index.ts:404](https://github.com/tweaselORG/appstraction/blob/main/src/index.ts#L404)
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export type PlatformApi<
/**
* Wait until the device or emulator has been connected and has booted up completely.
*
* @param tries The number of times to check if the device is present and booted. One try times out after 6 seconds
* on Android. It defaults to 20.
* @param tries The number of times to check if the device is present and booted. On Android, one try times out
* after 7 seconds and the default number of tries is 20. On iOS, one try takes about 1 second and the default
* number of tries is 100.
*/
waitForDevice: Platform extends 'android' ? (tries?: number) => Promise<void> : never;
waitForDevice: (tries?: number) => Promise<void>;
/**
* Assert that the selected device is connected and ready to be used with the selected capabilities, performing
* necessary setup steps. This should always be the first function you call.
Expand Down
12 changes: 10 additions & 2 deletions src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readFile } from 'fs/promises';
import { NodeSSH } from 'node-ssh';
import { Certificate } from 'pkijs';
import type { PlatformApi, PlatformApiOptions, Proxy, SupportedCapability, SupportedRunTarget } from '.';
import { asyncUnimplemented, getObjFromFridaScript, isRecord } from './util';
import { asyncUnimplemented, getObjFromFridaScript, isRecord, retryCondition } from './util';

const fridaScripts = {
getPrefs: `// Taken from: https://codeshare.frida.re/@dki/ios-app-info/
Expand Down Expand Up @@ -139,7 +139,15 @@ export const iosApi = <RunTarget extends SupportedRunTarget<'ios'>>(
},

resetDevice: asyncUnimplemented('resetDevice') as never,
waitForDevice: asyncUnimplemented('waitForDevice') as never,
async waitForDevice(tries = 100) {
if (
!(await retryCondition(
async () => (await execa('ideviceinfo', ['-k', 'DeviceName'], { reject: false })).exitCode === 0,
tries
))
)
throw new Error('Failed to wait for device: No booted device found after timeout.');
},
async ensureDevice() {
if ((await execa('ideviceinfo', ['-k', 'DeviceName'], { reject: false })).exitCode !== 0)
throw new Error('You need to connect your device and trust this computer.');
Expand Down

0 comments on commit f0d5e40

Please sign in to comment.