From 6e4c7f0eaae72a5997ed1fd668e6ec006e9e4342 Mon Sep 17 00:00:00 2001 From: timoxa0 Date: Sun, 16 Jun 2024 17:41:56 +0500 Subject: [PATCH] Add GerVar --- fastboot/FastbootDevice.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fastboot/FastbootDevice.go b/fastboot/FastbootDevice.go index a8ead34..30bfb02 100644 --- a/fastboot/FastbootDevice.go +++ b/fastboot/FastbootDevice.go @@ -1,6 +1,7 @@ package fastboot import ( + "errors" "fmt" "log" @@ -21,6 +22,12 @@ var Status = struct { INFO: "INFO", } +var Error = struct { + VarNotFound error +}{ + VarNotFound: errors.New("Variable not found"), +} + type FastbootDevice struct { Serial string Device *gousb.Device @@ -148,6 +155,18 @@ func (d *FastbootDevice) Recv() (FastbootResponseStatus, []byte, error) { 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 { err := d.download(data) if err != nil {