Add GerVar

This commit is contained in:
timoxa0 2024-06-16 17:41:56 +05:00
parent e0508069b2
commit 6e4c7f0eaa

View file

@ -1,6 +1,7 @@
package fastboot package fastboot
import ( import (
"errors"
"fmt" "fmt"
"log" "log"
@ -21,6 +22,12 @@ var Status = struct {
INFO: "INFO", INFO: "INFO",
} }
var Error = struct {
VarNotFound error
}{
VarNotFound: errors.New("Variable not found"),
}
type FastbootDevice struct { type FastbootDevice struct {
Serial string Serial string
Device *gousb.Device Device *gousb.Device
@ -148,6 +155,18 @@ func (d *FastbootDevice) Recv() (FastbootResponseStatus, []byte, error) {
return status, data[4:], nil return status, data[4:], nil
} }
func (d *FastbootDevice) GerVar(variable string) (string, error) {
d.Send([]byte(fmt.Sprintf("getvar:%s", variable)))
status, resp, err := d.Recv()
if status == Status.FAIL {
err = Error.VarNotFound
}
if err != nil {
return "", err
}
return string(resp), nil
}
func (d *FastbootDevice) BootImage(data []byte) error { func (d *FastbootDevice) BootImage(data []byte) error {
err := d.download(data) err := d.download(data)
if err != nil { if err != nil {