go-ios

repository·main·Indexed 24 days ago

https://github.com/danielpaulus/go-ios

A cross-platform iOS automation tool for Linux, Windows, and macOS. It provides a CLI and modular Go library for tasks including app installation, XCUITest execution, device state emulation, and process management. Features include a REST API, syslog and OS trace viewing, network traffic capture via pcap, and crash report management. Supports iOS 17+ devices via a tunnel daemon.

Tokens
19.3K
Snippets
24
Records
127
Agent score
80%

What's inside go-ios

  1. Understand the Go-iOS REST API project structure

    main

    The restapi package is organized as follows:

    • api/routes.go: Defines all available API routes.
    • api/middleware.go: Contains all middleware implementations.
    • api/*_endpoints.go: Contains the endpoint logic, which largely mirrors the go-ios docopt commands.
    • api/server.go: Handles the server configuration.
  2. Configure and run the GitHub Actions runner

    main

    After extracting the runner, use ./config.sh to register the runner with your repository. You must provide the --url of the repository and a registration --token. Once configured, start the runner using ./run.sh.

    # Create the runner and start the configuration experience
    $ ./config.sh --url https://github.com/danielpaulus/go-ios --token ABBBQZJD7WV2MU6VWFLDE6DJ56XUQ
    
    # Last step, run it!
    $ ./run.sh
  3. Setup and run the Go-iOS REST API

    main

    To develop or run the Go-iOS REST API, follow these steps:

    1. Open the restapi directory in your editor (e.g., VS Code).
    2. Install the swag CLI tool to generate Swagger documentation: go install github.com/swaggo/swag/cmd/swag@latest.
    3. Initialize Swagger documentation with dependency parsing: swag init --parseDependency.
    4. Start the server: go run main.go.
    5. Connect an iOS device to your machine.
    6. Access the API at localhost:8080.
    go install github.com/swaggo/swag/cmd/swag@latest
    swag init --parseDependency
    go run main.go
  4. Download and extract the GitHub Actions runner

    main

    To set up a GitHub Actions runner on macOS (x64), create a dedicated directory, download the runner package using curl, and extract the contents using tar. You can optionally validate the integrity of the downloaded archive using shasum.

    # Create a folder
    $ mkdir actions-runner && cd actions-runner
    
    # Download the latest runner package
    $ curl -o actions-runner-osx-x64-2.334.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.334.0/actions-runner-osx-x64-2.334.0.tar.gz
    
    # Optional: Validate the hash
    $ echo "73a979ff7e9ce8a70244f3a959d896870be486fac92bb08ed90684f961474e0d  actions-runner-osx-x64-2.334.0.tar.gz" | shasum -a 256 -c
    
    # Extract the installer
    $ tar xzf ./actions-runner-osx-x64-2.334.0.tar.gz
  5. Configure go-ios for iOS 17+ devices

    main

    For devices running iOS 17 or newer, you must start a tunnel daemon to enable communication. Run the following command with administrative privileges:

    sudo ios tunnel start

    Windows Users: You must download the latest wintun.dll from https://git.zx2c4.com/wintun and copy it to C:/Windows/system32 for the tunnel to function correctly.

  6. Configure UI automation drivers

    main

    The UI command supports two primary automation backends. You can specify the driver using the --driver flag or by setting environment variables. If --driver=auto is used, the client will attempt to connect to DeviceKit first, then fallback to WDA.

    Drivers:

    • devicekit: Uses the DeviceKit RPC protocol. Supports advanced features like H264 streaming and app foregrounding.
    • wda: Uses WebDriverAgent (WDA) HTTP endpoints. Supports MJPEG streaming.
    • auto: Automatically detects which backend is reachable.

    Configuration Options:

    • --driver <driver>: Set the driver (wda, devicekit, or auto).
    • --wda-url <url>: The URL for the WDA server (default: http://127.0.0.1:8100).
    • --devicekit-url <url>: The URL for the DeviceKit server (default: http://127.0.0.1:12004).
    • --session-id <id>: Provide an existing WDA session ID.

    Environment Variables:

    • GO_IOS_UI_DRIVER
    • GO_IOS_WDA_URL
    • GO_IOS_DEVICEKIT_URL
  7. Configure WebDriverAgent (WDA) testing parameters

    main

    When running WebDriverAgent (WDA) via testmanagerd.RunTestWithConfig, you must provide specific bundle identifiers. If they are not provided, the system attempts to fall back to these defaults:

    • Bundle ID: com.facebook.WebDriverAgentRunner.xctrunner
    • Test Runner Bundle ID: com.facebook.WebDriverAgentRunner.xctrunner
    • XCTest Config: WebDriverAgentRunner.xctest

    Requirement: You must specify either none of the following or all of them. If you provide one but not the others, the command will fail:

    • --bundleid
    • --testrunnerbundleid
    • --xctestconfig
  8. How NCM Transfer Blocks (NTB) work in go-ios

    main

    NCM (Network Control Model) allows a device and host to transfer multiple Ethernet frames within a single USB transfer using a structured format called an NCM Transfer Block (NTB).

    An NTB consists of several layers:

    1. ntbHeader: Contains the Signature (must be 0x484D434E), HeaderLen, SequenceNum, BlockLen, and NdpIndex.
    2. datagramPointerHeader: Located at the NdpIndex offset. It contains a Signature (0x304D434E), the total Length of the pointer section, and the NextNpdIndex.
    3. Datagram Pointers: A list of (Index, Length) pairs that point to the actual locations of the Ethernet frames within the block.
    4. Payload: The actual Ethernet frames located at the offsets specified by the pointers.
  9. Icon Types in Springboard

    main

    The ListIcons method returns Icon interfaces. Depending on the underlying type, you can access different metadata:

    TypeDescriptionKey Fields
    AppIconA native applicationName, DisplayIdentifier, BundleId, BundleVersion
    WebClipA Safari bookmark or PWAName, DisplayIdentifier, URL
    FolderA collection of itemsName, Icons (nested pages), ListType
    CustomA widget or paginated widgetIconType (Note: DisplayName() returns empty for this type)
  10. Initialize an AFC Client

    main

    To access the iOS file system, you must create a new Client. You can initialize it using a ios.DeviceEntry which handles the service connection automatically, or by providing an existing ios.DeviceConnectionInterface using NewFromConn.

    Always remember to call Close() on the client when finished to release the connection.