-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
71 lines (61 loc) · 1.55 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package instabot
import (
"bufio"
"crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"strings"
"time"
"github.com/winterssy/sreq"
)
const (
volatileSeed = "12345"
igSigKey = "5f3e50f435583c9ae626302a71f7340044087a7e2c60adacfc254205a993e305"
igSigKeyVersion = 4
)
func readUserInput(prompt string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(prompt)
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
if input == "" {
return readUserInput(prompt)
}
return input
}
func timeOffset() int {
_, offset := time.Now().Zone()
return offset
}
func GenerateUUID() string {
uuid := make([]byte, 16)
_, _ = rand.Read(uuid)
uuid[6] = (uuid[6] & 0x0f) | 0x40
uuid[8] = (uuid[8] & 0x3f) | 0x80
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
}
func generateMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func generateDeviceId(seed string) string {
hash := generateMD5Hash(seed + volatileSeed)
return "android-" + hash[:16]
}
func generateHMAC(text string, key string) string {
hasher := hmac.New(sha256.New, []byte(key))
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GenerateSignedForm(form sreq.Form) sreq.Form {
signedForm := make(sreq.Form, 2)
signedForm.Set("ig_sig_key_version", igSigKeyVersion)
body := form.Marshal()
signedForm.Set("signed_body", fmt.Sprintf("%s.%s", generateHMAC(body, igSigKey), body))
return signedForm
}