# Corellium CLI

## Table of contents

- [Introduction](#introduction)
- [Quick start](#quick-start)
- [What's included](#whats-included)
- [Authentication Login](#authentication-login)
- [Extension](#extension)
- [Firmware](#firmware)
- [Instance](#instance)
- [Image](#image)

## Introduction

Corellium CLI is a command-line collection of tools necessary for managing extensions on certain account types.

## Quick start

```
git clone git@gitlab01.corellium.co:middleware/corellium-cli.git
cd corellium-cli
npm install
npm link
```

From here, the `corellium` command will be available.

The basic workflow is login, load extension, load firmware, create project, create instance, delete instance, delete
project, and logout. More details can be found below including examples.

```code
corellium login --endpoint https://app.corellium.com --username admin --password password
corellium extension load charmSDKExtension.zip
corellium firmware load fw.zip
corellium project create --cores 2 --instances 2 --ram 16000 "Test Project"
corellium instance create flavor os projectId
corellium instance delete instanceId
corellium instance start instanceId
corellium instance stop instanceId
corellium project delete projectId
corellium logout
```

## What's included

```text
> corellium
Usage: corellium [OPTIONS]

Commands:
  corellium login      Login and save authentication token to local profile
  corellium logout     Logout and remove local profile
  corellium signup     Create subscriber invite account
  corellium extension  Extension related commands
  corellium instance   Instance related commands
  corellium firmware   Firmware related commands
  corellium image      Image related commands
  corellium project    Project related commands

Options:
  --help     Show help  [boolean]
  --version  Show version number  [boolean]

Run 'corellium --help' for more information on a command.
```

## Authentication Login

Upon successful login, your authentication token, token expiration, and endpoint will be saved to the current user's
home directory.

`corellium login [endpoint] [username] [password]`

```text
> corellium login --endpoint https://app.corellium.com --username user --password password
Login succesful, profile saved to /Users/user/.corellium/profile.json
```

A .corellium folder will be created in the user's home directory to store the profile.json if it doesn't already exist.
The token will expire; therefore subsequent logins will be needed to refresh authentication. If you need to change
endpoints, run the login command again.

`corellium logout`

```text
> corellium logout
Logout succesful, deleted profile at /Users/user/.corellium/profile.json
```

Logout will remove the profile.json and leave the .corellium folder in place.

## Extension

Commands exist for deleting, listing, and loading extensions.

`corellium extension load <files...>`

```text
> corellium extension load rpi4b.zip
loading rpi4b.zip [================] 100%
+------------------------------------+
|imageId                             |
+------------------------------------+
|a81cc107-e6ed-4298-a2d8-af6e0effd274|
+------------------------------------+
```

Extension load can load multiple files in one operation in parallel. If the loading progress doesn't progress past 0 in
a reasonable amount of time, check network connectivity to endpoint.

For large extensions and firmwares, the upload is resumable and chunkable meaning that when encountering network
instability chunks will be retried until successful.

`corellium extension list`

```text
> corellium extension list
+---------+------------------------+------------------------+------------------------------------+
|identifer|createdAt               |updatedAt               |imageId                             |
+---------+------------------------+------------------------+------------------------------------+
|rpi4b    |2022-08-03T00:52:44.000Z|2022-08-03T06:41:04.000Z|3685ec03-a1a3-4e03-8743-dda92458dc48|
+---------+------------------------+------------------------+------------------------------------+
```

`corellium extension list --format json`

```text
> corellium extension list --format json
[
  {
    "volume": {
      "allocate": 32,
      "partitions": [
        {
          "name": "nand",
          "block_size": 512,
          "blocks": 62500000,
          "filename": "nand"
        }
      ]
    },
    "bootargs": [...
  ...
  }
]
```

`corellium extension list --format csv`

```text
> corellium extension list --format csv
identifier,category,vendor,product,type,model,name,createdAt,updatedAt,imageId
rpi4b,iot,,rpi4b,rpi4b,rpi4b,Raspberry Pi 4,2022-08-03T00:52:44.000Z,2022-08-03T06:41:04.000Z,3685ec03-a1a3-4e03-8743-dda92458dc48
```

`corellium extension delete <extensionId>`

```text
> corellium extension delete 3685ec03-a1a3-4e03-8743-dda92458dc48
Deleted extension 3685ec03-a1a3-4e03-8743-dda92458dc48
```

`corellium extension validate <extensionJson>`

```text
> corellium extension validate ./extension.json
Valid
```

## Firmware

`corellium firmware list`

```text
> corellium firmware list
+-------+--------+----------+------------------------------------------+
|buildid|filename|size      |version                                   |
+-------+--------+----------+------------------------------------------+
|12.1.4 |16D57   |3119653482|iPhone_4.7_12.1.4_16D57_Restore.ipsw      |
|11.2.2 |15C202  |2806509985|iPhone_5.5_11.2.2_15C202_Restore.ipsw     |
|10.3.3 |14G60   |2318924124|iPodtouch_10.3.3_14G60_Restore.ipsw       |
|11.4   |15F79   |3073763592|iPhone_5.5_P3_11.0_11.4_15F79_Restore.ipsw|
|11.0   |15A372  |2775383489|iPhone_7Plus_11.0_15A372_Restore.ipsw     |
+-------+--------+----------+------------------------------------------+
```

Firmware list also has the --format csv|json flag to modify output format.

`corellium firmware load <files...>`

```text
> corellium firmware load iPhone_5.5_p2_11.0.11.4_15F79_Restore.ipsw
loading iPhone_5.5_p2_11.0.11.4_15F79_Restore.ipsw [================] 100%
```

Firmware load can load multiple files in one operation.

## Project

`corellium project create [cores] [instances] [ram] <name>`

```text
> corellium project create --cores 2 --instances 2 --ram 16000 "Test Project"
+------------------------------------+
|id                                  |
+------------------------------------+
|dc69ee87-06c6-42c0-bf17-accc3ace5912|
+------------------------------------+
```

`corellium project list`

```text
> corellium project list
+------------------------------------+------------------------+
|id                                  |name                    |
+------------------------------------+------------------------+
|0650b468-ba57-45ed-82e5-f828daaedc2e|Test Project            |
+------------------------------------+------------------------+
```

`corellium project delete <projectId>`

```text
> corellium project delete 0650b468-ba57-45ed-82e5-f828daaedc2e
Deleted project 0650b468-ba57-45ed-82e5-f828daaedc2e
```

## Instance

`corellium instance create <flavor> <os> <project>`

```text
> corellium instance create iphone8plus 11.4 aa8baade-3b1c-4465-a4da-d2038ece0698
+------------------------------------+--------+
|id                                  |state   |
+------------------------------------+--------+
|8921f1c4-6780-4a99-9775-1943b036236c|creating|
+------------------------------------+--------+
```

`corellium instance list`

```text
> corellium instance list
+------------------------------------+-----------+----+-----+----+
|id                                  |flavor     |type|state|os  |
+------------------------------------+-----------+----+-----+----+
|bb68bc30-acff-48be-8f79-82c94def3c38|iphone8plus|ios |on   |11.4|
+------------------------------------+-----------+----+-----+----+
```

`corellium instance delete <instanceId>`

```text
> corellium instance delete 182647cb-22c0-4000-88df-4a9dc60d1018
Successfully deleted instance bb68bc30-acff-48be-8f79-82c94def3c38
```

`corellium instance start <instanceId>`

```text
> corellium instance start 7eb2a108-ebae-41fd-8c46-eb039a878726
Successfully started instance 7eb2a108-ebae-41fd-8c46-eb039a878726
```

`corellium instance stop <instanceId>`

```text
> corellium instance stop 7eb2a108-ebae-41fd-8c46-eb039a878726
Successfully stopped instance 7eb2a108-ebae-41fd-8c46-eb039a878726
```

## Image

`corellium image create [project] [instance] <imageName> <imageType> <encoding> <file>`

```text
> corellium image create --instance 8921f1c4-6780-4a99-9775-1943b036236c rpiFWName fw plain rpi4b.zip
+------+------------------------------------+------------+---------+------------------------------------+
|status|id                                  |name        |type     |project                             |
+------+------------------------------------+------------+---------+------------------------------------+
|active|4d59d0e0-d4d5-4f9d-9145-bcb04df24bef|rpiFWName   |fwpackage|aa8baade-3b1c-4465-a4da-d2038ece0698|
+------+------------------------------------+------------+---------+------------------------------------+
```

`corellium image list`

```text
> corellium image list
+------+------------------------------------+------------+---------+------------------------------------+
|status|id                                  |name        |type     |project                             |
+------+------------------------------------+------------+---------+------------------------------------+
|active|4d59d0e0-d4d5-4f9d-9145-bcb04df24bef|appleWatchFw|fwpackage|aa8baade-3b1c-4465-a4da-d2038ece0698|
+------+------------------------------------+------------+---------+------------------------------------+
```

`corellium image delete <imageId>`

```text
> corellium image delete <imageId>
Successfully deleted image 18264789-a1c0-4000-82d9-70c99234b701
```
