2015-04-12 20:34:20 +00:00
|
|
|
// A simple tool for sending raw messages to an adb server.
|
2015-04-11 21:45:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2015-05-04 01:21:49 +00:00
|
|
|
"github.com/zach-klippenstein/goadb"
|
2015-04-11 21:45:29 +00:00
|
|
|
"github.com/zach-klippenstein/goadb/wire"
|
|
|
|
)
|
|
|
|
|
2015-05-04 01:21:49 +00:00
|
|
|
var port = flag.Int("p", goadb.AdbPort, "port the adb server is listening on")
|
2015-04-11 21:45:29 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
fmt.Println("using port", *port)
|
|
|
|
|
|
|
|
printServerVersion()
|
|
|
|
|
|
|
|
for {
|
|
|
|
line := readLine()
|
|
|
|
err := doCommand(line)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("error:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func printServerVersion() {
|
|
|
|
err := doCommand("host:version")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readLine() string {
|
|
|
|
fmt.Print("> ")
|
|
|
|
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(line)
|
|
|
|
}
|
|
|
|
|
|
|
|
func doCommand(cmd string) error {
|
2016-01-10 21:33:22 +00:00
|
|
|
server, err := goadb.NewServer(goadb.ServerConfig{
|
|
|
|
Port: *port,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn, err := server.Dial()
|
2015-04-11 21:45:29 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
if err := wire.SendMessageString(conn, cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-12-28 23:28:53 +00:00
|
|
|
status, err := conn.ReadStatus("")
|
2015-04-11 21:45:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg string
|
|
|
|
for err == nil {
|
|
|
|
msg, err = wire.ReadMessageString(conn)
|
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("%s> %s\n", status, msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != io.EOF {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|