diff options
| author | Huizi Yang <yanghuiz@google.com> | 2021-09-10 01:41:42 -0700 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2021-09-10 20:57:52 +0200 |
| commit | 8a703291444d2233bd9179a4d1586111dab999b2 (patch) | |
| tree | bf373a64aeeae21f30ae31265614338045d7a787 /vm | |
| parent | 09a90cb2789a758ff9540eda063d49f30379249b (diff) | |
vm/adb: support both old and new device format
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/adb/adb.go | 40 | ||||
| -rw-r--r-- | vm/vmimpl/console.go | 4 |
2 files changed, 37 insertions, 7 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go index 45b0d7f2a..624fd7efc 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -8,6 +8,7 @@ package adb import ( "bytes" + "encoding/json" "fmt" "io" "io/ioutil" @@ -36,8 +37,8 @@ type Device struct { } type Config struct { - Adb string `json:"adb"` // adb binary name ("adb" by default) - Devices []Device `json:"devices"` // list of adb devices to use + Adb string `json:"adb"` // adb binary name ("adb" by default) + Devices []json.RawMessage `json:"devices"` // list of adb devices to use // Ensure that a device battery level is at 20+% before fuzzing. // Sometimes we observe that a device can't charge during heavy fuzzing @@ -66,6 +67,25 @@ type instance struct { debug bool } +var ( + androidSerial = "^[0-9A-Z]+$" + cuttlefishID = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}\:(?:[0-9]{1,5})$` // IP:port +) + +func loadDevice(data []byte) (*Device, error) { + devObj := &Device{} + var devStr string + err1 := config.LoadData(data, devObj) + err2 := config.LoadData(data, &devStr) + if err1 != nil && err2 != nil { + return nil, fmt.Errorf("failed to parse adb vm config: %v %v", err1, err2) + } + if err2 == nil { + devObj.Serial = devStr + } + return devObj, nil +} + func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { cfg := &Config{ Adb: "adb", @@ -81,10 +101,15 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { if len(cfg.Devices) == 0 { return nil, fmt.Errorf("no adb devices specified") } - devRe := regexp.MustCompile("[0-9A-F]+") + // Device should be either regular serial number, or a valid Cuttlefish ID. + devRe := regexp.MustCompile(fmt.Sprintf("%s|%s", androidSerial, cuttlefishID)) for _, dev := range cfg.Devices { - if !devRe.MatchString(dev.Serial) { - return nil, fmt.Errorf("invalid adb device id '%v'", dev) + device, err := loadDevice(dev) + if err != nil { + return nil, err + } + if !devRe.MatchString(device.Serial) { + return nil, fmt.Errorf("invalid adb device id '%v'", device.Serial) } } if env.Debug { @@ -102,7 +127,10 @@ func (pool *Pool) Count() int { } func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { - device := pool.cfg.Devices[index] + device, err := loadDevice(pool.cfg.Devices[index]) + if err != nil { + return nil, err + } inst := &instance{ cfg: pool.cfg, adbBin: pool.cfg.Adb, diff --git a/vm/vmimpl/console.go b/vm/vmimpl/console.go index 38314bcf5..5958b2a19 100644 --- a/vm/vmimpl/console.go +++ b/vm/vmimpl/console.go @@ -76,7 +76,9 @@ func (t *tty) Close() error { return nil } -func OpenRemoteKernelLog(ip string, console string) (rc io.ReadCloser, err error) { +// OpenRemoteKernelLog accesses to the host where Android VM runs on, not Android VM itself. +// The host stores all kernel outputs of Android VM so in case of crashes nothing will be lost. +func OpenRemoteKernelLog(ip, console string) (rc io.ReadCloser, err error) { rpipe, wpipe, err := osutil.LongPipe() if err != nil { return nil, err |
