1# Microdroid Payload 2 3Payload disk is a composite disk referencing host APEXes and an APK so that microdroid 4reads activates APEXes and executes a binary within the APK. 5 6## Format 7 8Payload disk has 1 + N(number of APEX/APK payloads) partitions. 9 10The first partition is a Microdroid Signature partition which describes other partitions. 11And APEXes and an APK are following as separate partitions. 12 13For now, the order of partitions are important. 14 15* partition 1: Microdroid Signature 16* partition 2 ~ n: APEX payloads 17* partition n + 1: APK payload 18 19It's subject to change in the future, though. 20 21### Microdroid Signature 22 23Microdroid Signature contains the signatures of the payloads so that the payloads are 24verified inside the Guest OS. 25 26Microdroid Signature is composed of header and body. 27 28| offset | size | description | 29|--------|------|----------------------------------------------------------------| 30| 0 | 4 | Header. unsigned int32: body length(L) in big endian | 31| 4 | L | Body. A protobuf message. [schema](microdroid_signature.proto) | 32 33### Payload Partitions 34 35At the end of each payload partition the size of the original payload file (APEX or APK) is stored 36in 4-byte big endian. 37 38For example, the following code shows how to get the original size of host apex file 39when the apex is read in microdroid as /dev/block/vdc2, 40 41 int fd = open("/dev/block/vdc2", O_RDONLY | O_BINARY | O_CLOEXEC); 42 uint32_t size; 43 lseek(fd, -sizeof(size), SEEK_END); 44 read(fd, &size, sizeof(size)); 45 size = betoh32(size); 46 47## How to Create 48 49### `mk_payload` 50 51`mk_payload` creates a payload image. 52``` 53$ cat payload_config.json 54{ 55 "system_apexes": [ 56 "com.android.adbd", 57 ], 58 "apexes": [ 59 { 60 "name": "com.my.hello", 61 "path": "hello.apex" 62 } 63 ], 64 "apk": { 65 "name": "com.my.world", 66 "path": "/path/to/world.apk" 67 } 68} 69$ adb push payload_config.json hello.apex /data/local/tmp/ 70$ adb shell 'cd /data/local/tmp; /apex/com.android.virt/bin/mk_payload payload_config.json payload.img 71$ adb shell ls /data/local/tmp/*.img 72payload.img 73payload-footer.img 74payload-header.img 75payload-signature.img 76payload.img.0 # fillers 77payload.img.1 78... 79``` 80 81In the future, [VirtManager](../../virtmanager) will handle this.