From cdf9b1e4a0cd2e50d138f69fb5d359aaf1651032 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 30 Jun 2023 12:55:49 +0300 Subject: [PATCH] Run goimports --- libgm/binary/protoUtil.go | 3 +- libgm/cache/settings.go | 7 ++- libgm/crypto/B64.go | 32 +++++++------- libgm/crypto/ECDSA.go | 28 ++++++------ libgm/crypto/generate.go | 2 +- libgm/crypto/imageCryptor.go | 4 +- libgm/debug/logger.go | 11 ++--- libgm/events/qr.go | 14 +++--- libgm/events/useralerts.go | 7 ++- libgm/json_proto/serialize.go | 78 +++++++++++++++++----------------- libgm/payload/conversations.go | 2 +- libgm/response_handler.go | 9 ++-- libgm/util/constants.go | 3 +- libgm/util/errors.go | 3 +- libgm/util/func.go | 30 ++++++------- libgm/util/paths.go | 24 +++++------ 16 files changed, 127 insertions(+), 130 deletions(-) diff --git a/libgm/binary/protoUtil.go b/libgm/binary/protoUtil.go index 5bbce76..66a4017 100644 --- a/libgm/binary/protoUtil.go +++ b/libgm/binary/protoUtil.go @@ -2,6 +2,7 @@ package binary import ( "fmt" + "google.golang.org/protobuf/proto" ) @@ -19,4 +20,4 @@ func DecodeProtoMessage(data []byte, message proto.Message) error { return fmt.Errorf("failed to decode proto message: %v", err) } return nil -} \ No newline at end of file +} diff --git a/libgm/cache/settings.go b/libgm/cache/settings.go index f1b97d2..7d65ba2 100644 --- a/libgm/cache/settings.go +++ b/libgm/cache/settings.go @@ -1,8 +1,7 @@ package cache - type Settings struct { CarrierName string `json:"carrierName,omitempty"` - HexHash string `json:"hexHash,omitempty"` - Version string `json:"version,omitempty"` -} \ No newline at end of file + HexHash string `json:"hexHash,omitempty"` + Version string `json:"version,omitempty"` +} diff --git a/libgm/crypto/B64.go b/libgm/crypto/B64.go index 6dc5913..f9f6627 100644 --- a/libgm/crypto/B64.go +++ b/libgm/crypto/B64.go @@ -15,27 +15,27 @@ func EncodeBase64(data []byte) string { } func Base64Decode(input string) ([]byte, error) { - padding := len(input) % 4 - if padding > 0 { - input += strings.Repeat("=", 4-padding) - } + padding := len(input) % 4 + if padding > 0 { + input += strings.Repeat("=", 4-padding) + } - data, err := base64.URLEncoding.DecodeString(input) - if err != nil { - return nil, err - } - return data, nil + data, err := base64.URLEncoding.DecodeString(input) + if err != nil { + return nil, err + } + return data, nil } func Base64DecodeStandard(input string) ([]byte, error) { - decoded, err := base64.StdEncoding.DecodeString(input) - if err != nil { - fmt.Println("decode error:", err) - return nil, err - } - return decoded, nil + decoded, err := base64.StdEncoding.DecodeString(input) + if err != nil { + fmt.Println("decode error:", err) + return nil, err + } + return decoded, nil } func Base64Encode(input []byte) string { return base64.StdEncoding.EncodeToString(input) -} \ No newline at end of file +} diff --git a/libgm/crypto/ECDSA.go b/libgm/crypto/ECDSA.go index 5d3b11c..6daaf32 100644 --- a/libgm/crypto/ECDSA.go +++ b/libgm/crypto/ECDSA.go @@ -11,14 +11,14 @@ import ( ) type JWK struct { - Kty string `json:"kty"` - Crv string `json:"crv"` - D string `json:"d"` - X string `json:"x"` - Y string `json:"y"` - Ext bool `json:"ext"` - KeyOps []string `json:"key_ops"` - PrivateBytes []byte `json:"privateBytes,omitempty"` + Kty string `json:"kty"` + Crv string `json:"crv"` + D string `json:"d"` + X string `json:"x"` + Y string `json:"y"` + Ext bool `json:"ext"` + KeyOps []string `json:"key_ops"` + PrivateBytes []byte `json:"privateBytes,omitempty"` } // Returns a byte slice containing the JWK and an error if the generation or export failed. @@ -26,13 +26,13 @@ func (t *JWK) Marshal() ([]byte, error) { JWKJSON, err := json.Marshal(t) if err != nil { fmt.Printf("Failed to marshal JWK: %v", err) - return nil,err + return nil, err } fmt.Printf("%s\n", JWKJSON) - return JWKJSON,err + return JWKJSON, err } -func (t *JWK) PrivKeyB64Bytes() ([]byte, error){ +func (t *JWK) PrivKeyB64Bytes() ([]byte, error) { decodedPrivateKey, err2 := Base64Decode(t.D) return decodedPrivateKey, err2 } @@ -97,7 +97,7 @@ func GenerateECDSA_P256_JWK() (*JWK, error) { privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { fmt.Printf("Failed to generate private key: %v", err) - return nil,err + return nil, err } JWK := &JWK{ @@ -109,5 +109,5 @@ func GenerateECDSA_P256_JWK() (*JWK, error) { Ext: true, KeyOps: []string{"sign"}, } - return JWK,nil -} \ No newline at end of file + return JWK, nil +} diff --git a/libgm/crypto/generate.go b/libgm/crypto/generate.go index 3c47de8..2dbb16a 100644 --- a/libgm/crypto/generate.go +++ b/libgm/crypto/generate.go @@ -24,4 +24,4 @@ func GenerateKeys() ([]byte, []byte) { log.Fatal(err2) } return key, key2 -} \ No newline at end of file +} diff --git a/libgm/crypto/imageCryptor.go b/libgm/crypto/imageCryptor.go index de48c37..427974a 100644 --- a/libgm/crypto/imageCryptor.go +++ b/libgm/crypto/imageCryptor.go @@ -75,7 +75,7 @@ func (ic *ImageCryptor) Decrypt(iv []byte, data []byte, aad []byte) ([]byte, err func (ic *ImageCryptor) EncryptData(data []byte) ([]byte, error) { rawChunkSize := 1 << 15 - chunkSize := rawChunkSize-28 + chunkSize := rawChunkSize - 28 var tasks []chan []byte chunkIndex := 0 @@ -191,4 +191,4 @@ func (ic *ImageCryptor) calculateAAD(index, end, total int) []byte { } return aad -} \ No newline at end of file +} diff --git a/libgm/debug/logger.go b/libgm/debug/logger.go index c45ce9a..aa15627 100644 --- a/libgm/debug/logger.go +++ b/libgm/debug/logger.go @@ -3,21 +3,22 @@ package debug import ( "fmt" "time" + "github.com/mattn/go-colorable" zerolog "github.com/rs/zerolog" ) var colors = map[string]string{ - "text": "\x1b[38;5;6m%s\x1b[0m", + "text": "\x1b[38;5;6m%s\x1b[0m", "debug": "\x1b[32mDEBUG\x1b[0m", - "gray": "\x1b[38;5;8m%s\x1b[0m", - "info": "\x1b[38;5;111mINFO\x1b[0m", + "gray": "\x1b[38;5;8m%s\x1b[0m", + "info": "\x1b[38;5;111mINFO\x1b[0m", "error": "\x1b[38;5;204mERROR\x1b[0m", "fatal": "\x1b[38;5;52mFATAL\x1b[0m", } var output = zerolog.ConsoleWriter{ - Out: colorable.NewColorableStdout(), + Out: colorable.NewColorableStdout(), TimeFormat: time.ANSIC, FormatLevel: func(i interface{}) string { name := fmt.Sprintf("%s", i) @@ -40,4 +41,4 @@ var output = zerolog.ConsoleWriter{ func NewLogger() zerolog.Logger { return zerolog.New(output).With().Timestamp().Logger() -} \ No newline at end of file +} diff --git a/libgm/events/qr.go b/libgm/events/qr.go index 066cb53..c0e1738 100644 --- a/libgm/events/qr.go +++ b/libgm/events/qr.go @@ -1,22 +1,22 @@ package events type QRCODE_UPDATED struct { - Image []byte + Image []byte Height int - Width int - + Width int + googleUrl string } func NewQrCodeUpdated(image []byte, height int, width int, googleUrl string) *QRCODE_UPDATED { return &QRCODE_UPDATED{ - Image: image, - Height: height, - Width: width, + Image: image, + Height: height, + Width: width, googleUrl: googleUrl, } } func (q *QRCODE_UPDATED) GetGoogleUrl() string { return q.googleUrl -} \ No newline at end of file +} diff --git a/libgm/events/useralerts.go b/libgm/events/useralerts.go index 14a24c3..19a1337 100644 --- a/libgm/events/useralerts.go +++ b/libgm/events/useralerts.go @@ -1,6 +1,5 @@ package events - type BROWSER_ACTIVE struct { SessionId string } @@ -11,14 +10,14 @@ func NewBrowserActive(sessionId string) *BROWSER_ACTIVE { } } -type BATTERY struct {} +type BATTERY struct{} func NewBattery() *BATTERY { return &BATTERY{} } -type DATA_CONNECTION struct {} +type DATA_CONNECTION struct{} func NewDataConnection() *DATA_CONNECTION { return &DATA_CONNECTION{} -} \ No newline at end of file +} diff --git a/libgm/json_proto/serialize.go b/libgm/json_proto/serialize.go index d39c550..72804da 100644 --- a/libgm/json_proto/serialize.go +++ b/libgm/json_proto/serialize.go @@ -57,44 +57,44 @@ import ( ) func Serialize(m protoreflect.Message) ([]interface{}, error) { - maxFieldNumber := 0 - for i := 0; i < m.Descriptor().Fields().Len(); i++ { - fieldNumber := int(m.Descriptor().Fields().Get(i).Number()) - if fieldNumber > maxFieldNumber { - maxFieldNumber = fieldNumber - } - } + maxFieldNumber := 0 + for i := 0; i < m.Descriptor().Fields().Len(); i++ { + fieldNumber := int(m.Descriptor().Fields().Get(i).Number()) + if fieldNumber > maxFieldNumber { + maxFieldNumber = fieldNumber + } + } - serialized := make([]interface{}, maxFieldNumber) - for i := 0; i < m.Descriptor().Fields().Len(); i++ { - fieldDescriptor := m.Descriptor().Fields().Get(i) - fieldValue := m.Get(fieldDescriptor) - fieldNumber := int(fieldDescriptor.Number()) - switch fieldDescriptor.Kind() { - case protoreflect.MessageKind: - if m.Has(fieldDescriptor) { - serializedMsg, err := Serialize(fieldValue.Message().Interface().ProtoReflect()) - if err != nil { - return nil, err - } - serialized[fieldNumber-1] = serializedMsg - } - case protoreflect.BytesKind: - if m.Has(fieldDescriptor) { - serialized[fieldNumber-1] = fieldValue.Bytes() - } - case protoreflect.Int32Kind, protoreflect.Int64Kind: - if m.Has(fieldDescriptor) { - serialized[fieldNumber-1] = fieldValue.Int() - } - case protoreflect.StringKind: - if m.Has(fieldDescriptor) { - serialized[fieldNumber-1] = fieldValue.String() - } - default: - // ignore fields of other types - } - } + serialized := make([]interface{}, maxFieldNumber) + for i := 0; i < m.Descriptor().Fields().Len(); i++ { + fieldDescriptor := m.Descriptor().Fields().Get(i) + fieldValue := m.Get(fieldDescriptor) + fieldNumber := int(fieldDescriptor.Number()) + switch fieldDescriptor.Kind() { + case protoreflect.MessageKind: + if m.Has(fieldDescriptor) { + serializedMsg, err := Serialize(fieldValue.Message().Interface().ProtoReflect()) + if err != nil { + return nil, err + } + serialized[fieldNumber-1] = serializedMsg + } + case protoreflect.BytesKind: + if m.Has(fieldDescriptor) { + serialized[fieldNumber-1] = fieldValue.Bytes() + } + case protoreflect.Int32Kind, protoreflect.Int64Kind: + if m.Has(fieldDescriptor) { + serialized[fieldNumber-1] = fieldValue.Int() + } + case protoreflect.StringKind: + if m.Has(fieldDescriptor) { + serialized[fieldNumber-1] = fieldValue.String() + } + default: + // ignore fields of other types + } + } - return serialized, nil -} \ No newline at end of file + return serialized, nil +} diff --git a/libgm/payload/conversations.go b/libgm/payload/conversations.go index 702bc0d..1e38816 100644 --- a/libgm/payload/conversations.go +++ b/libgm/payload/conversations.go @@ -1 +1 @@ -package payload \ No newline at end of file +package payload diff --git a/libgm/response_handler.go b/libgm/response_handler.go index 9eee576..671686e 100644 --- a/libgm/response_handler.go +++ b/libgm/response_handler.go @@ -7,10 +7,10 @@ import ( ) type ResponseChan struct { - responses []*Response + responses []*Response receivedResponses int64 - wg sync.WaitGroup - mu sync.Mutex + wg sync.WaitGroup + mu sync.Mutex } func (s *SessionHandler) addRequestToChannel(requestId string, opCode int64) { @@ -42,7 +42,6 @@ func (s *SessionHandler) addRequestToChannel(requestId string, opCode int64) { } } - func (s *SessionHandler) respondToRequestChannel(res *Response) { requestId := res.Data.RequestId reqChannel, ok := s.requests[requestId] @@ -99,4 +98,4 @@ func (s *SessionHandler) WaitForResponse(requestId string, opCode int64) ([]*Res responseChan.wg.Wait() return responseChan.responses, nil -} \ No newline at end of file +} diff --git a/libgm/util/constants.go b/libgm/util/constants.go index 392e174..bb99f5a 100644 --- a/libgm/util/constants.go +++ b/libgm/util/constants.go @@ -1,9 +1,8 @@ package util - var GOOG_API_KEY = "AIzaSyCA4RsOZUFrm9whhtGosPlJLmVPnfSHKz8" var USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" var OS = "Linux" var X_USER_AGENT = "grpc-web-javascript/0.1" var QR_CODE_URL = "https://support.google.com/messages/?p=web_computer#?c=" -var TENOR_API_KEY = "YR0F99AJ65AV" \ No newline at end of file +var TENOR_API_KEY = "YR0F99AJ65AV" diff --git a/libgm/util/errors.go b/libgm/util/errors.go index 6f81ff2..025eec4 100644 --- a/libgm/util/errors.go +++ b/libgm/util/errors.go @@ -2,11 +2,10 @@ package util import "fmt" - type InstructionNotFound struct { Opcode int64 } func (e *InstructionNotFound) Error() string { return fmt.Sprintf("Could not find instruction for opcode %d", e.Opcode) -} \ No newline at end of file +} diff --git a/libgm/util/func.go b/libgm/util/func.go index 8968d72..b798487 100644 --- a/libgm/util/func.go +++ b/libgm/util/func.go @@ -8,17 +8,17 @@ import ( "net/http" "time" - "github.com/nu7hatch/gouuid" + uuid "github.com/nu7hatch/gouuid" ) var Charset = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") func RandStr(length int) string { b := make([]rune, length) - for i := range b { - b[i] = Charset[rand.Intn(len(Charset))] - } - return string(b) + for i := range b { + b[i] = Charset[rand.Intn(len(Charset))] + } + return string(b) } func GenerateImageId() string { @@ -35,8 +35,8 @@ func GenerateTmpId() string { } func ParseTimestamp(unixTs int64) time.Time { - seconds := unixTs / int64(time.Second / time.Microsecond) - nanoseconds := (unixTs % int64(time.Second / time.Microsecond)) * int64(time.Microsecond / time.Nanosecond) + seconds := unixTs / int64(time.Second/time.Microsecond) + nanoseconds := (unixTs % int64(time.Second/time.Microsecond)) * int64(time.Microsecond/time.Nanosecond) return time.Unix(seconds, nanoseconds).UTC() } @@ -52,13 +52,13 @@ func RandomUUIDv4() string { } func RemoveFromSlice(s []string, v string) []string { - newS := []string{} - for _, i := range s { - if i != v { - newS = append(newS, i) - } - } - return newS + newS := []string{} + for _, i := range s { + if i != v { + newS = append(newS, i) + } + } + return newS } func BuildRelayHeaders(req *http.Request, contentType string, accept string) { @@ -132,4 +132,4 @@ func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string headers.Add("accept-encoding", "gzip, deflate, br") headers.Add("accept-language", "en-US,en;q=0.9") return headers -} \ No newline at end of file +} diff --git a/libgm/util/paths.go b/libgm/util/paths.go index 0fb942d..c8c8911 100644 --- a/libgm/util/paths.go +++ b/libgm/util/paths.go @@ -2,22 +2,22 @@ package util var MESSAGES_GOOGLE_BASE_URL = "https://messages.google.com" -var MESSAGES_GOOGLE_AUTHENTICATION = MESSAGES_GOOGLE_BASE_URL+"/web/authentication" -var MESSAGES_GOOGLE_TIMESOURCE = MESSAGES_GOOGLE_BASE_URL+"/web/timesource" +var MESSAGES_GOOGLE_AUTHENTICATION = MESSAGES_GOOGLE_BASE_URL + "/web/authentication" +var MESSAGES_GOOGLE_TIMESOURCE = MESSAGES_GOOGLE_BASE_URL + "/web/timesource" var INSTANT_MESSAGING = "https://instantmessaging-pa.googleapis.com" -var UPLOAD_MEDIA = INSTANT_MESSAGING+"/upload" +var UPLOAD_MEDIA = INSTANT_MESSAGING + "/upload" -var PAIRING = INSTANT_MESSAGING+"/$rpc/google.internal.communications.instantmessaging.v1.Pairing" -var REGISTER_PHONE_RELAY = PAIRING+"/RegisterPhoneRelay" -var REFRESH_PHONE_RELAY = PAIRING+"/RefreshPhoneRelay" -var GET_WEB_ENCRYPTION_KEY = PAIRING+"/GetWebEncryptionKey" +var PAIRING = INSTANT_MESSAGING + "/$rpc/google.internal.communications.instantmessaging.v1.Pairing" +var REGISTER_PHONE_RELAY = PAIRING + "/RegisterPhoneRelay" +var REFRESH_PHONE_RELAY = PAIRING + "/RefreshPhoneRelay" +var GET_WEB_ENCRYPTION_KEY = PAIRING + "/GetWebEncryptionKey" -var MESSAGING = INSTANT_MESSAGING+"/$rpc/google.internal.communications.instantmessaging.v1.Messaging" -var RECEIVE_MESSAGES = MESSAGING+"/ReceiveMessages" -var SEND_MESSAGE = MESSAGING+"/SendMessage" -var ACK_MESSAGES = MESSAGING+"/AckMessages" +var MESSAGING = INSTANT_MESSAGING + "/$rpc/google.internal.communications.instantmessaging.v1.Messaging" +var RECEIVE_MESSAGES = MESSAGING + "/ReceiveMessages" +var SEND_MESSAGE = MESSAGING + "/SendMessage" +var ACK_MESSAGES = MESSAGING + "/AckMessages" var TENOR_BASE_URL = "https://api.tenor.com/v1" -var TENOR_SEARCH_GIF = TENOR_BASE_URL+"/search" \ No newline at end of file +var TENOR_SEARCH_GIF = TENOR_BASE_URL + "/search"