bake vk api versions
This commit is contained in:
1 parent
b27ad09138
commit
573771541a
5 files changed
+15
-264
No files matched your search
Binary file not shown.
Binary file not shown.
+9
-123
@@ -1,11 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "log"
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type VKConfig struct {
|
type VKConfig struct {
|
||||||
AppID string
|
AppID string
|
||||||
@@ -16,123 +11,14 @@ type VKConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchConfig() (VKConfig, error) {
|
func fetchConfig() (VKConfig, error) {
|
||||||
var cfg VKConfig
|
cfg := VKConfig{
|
||||||
|
AppID: "6287487",
|
||||||
// Discover current bundle URL
|
APIVersion: "5.276",
|
||||||
page, err := httpGet("https://vk.com")
|
SDKVersion: "2.8.10-beta.10",
|
||||||
if err != nil {
|
AppVersion: "1.1",
|
||||||
return cfg, fmt.Errorf("failed to fetch vk.com: %w", err)
|
ProtocolVersion: "6",
|
||||||
}
|
}
|
||||||
|
log.Printf("[config] app_id=%s api=%s sdk=%s app=%s proto=%s",
|
||||||
bundleRe := regexp.MustCompile(`https://[a-z0-9.-]+/dist/core_spa/core_spa_vk\.[a-f0-9]+\.js`)
|
cfg.AppID, cfg.APIVersion, cfg.SDKVersion, cfg.AppVersion, cfg.ProtocolVersion)
|
||||||
bundleURL := bundleRe.FindString(string(page))
|
|
||||||
if bundleURL == "" {
|
|
||||||
snippet := string(page)
|
|
||||||
if len(snippet) > 500 {
|
|
||||||
snippet = snippet[:500]
|
|
||||||
}
|
|
||||||
return cfg, fmt.Errorf("bundle URL not found in page (length: %d): %s", len(page), snippet)
|
|
||||||
}
|
|
||||||
log.Printf("[config] Found bundle: %s", bundleURL)
|
|
||||||
|
|
||||||
bundle, err := httpGet(bundleURL)
|
|
||||||
if err != nil {
|
|
||||||
return cfg, fmt.Errorf("failed to fetch bundle: %w", err)
|
|
||||||
}
|
|
||||||
bundleStr := string(bundle)
|
|
||||||
chunksBase := bundleURL[:strings.LastIndex(bundleURL, "core_spa_vk.")] + "chunks/"
|
|
||||||
|
|
||||||
// Extract app_id and API version from the main bundle
|
|
||||||
if m := regexp.MustCompile(`[,;]u=(\d{7,8}),[a-z]=\d{7,9}`).FindStringSubmatch(bundleStr); m != nil {
|
|
||||||
cfg.AppID = m[1]
|
|
||||||
} else {
|
|
||||||
return cfg, fmt.Errorf("app_id not found in bundle")
|
|
||||||
}
|
|
||||||
if m := regexp.MustCompile(`\d+:\(e,t,n\)=>\{"use strict";n\.d\(t,\{m:\(\)=>r\}\);const r="(5\.\d+)"\}`).FindStringSubmatch(bundleStr); m != nil {
|
|
||||||
cfg.APIVersion = m[1]
|
|
||||||
} else {
|
|
||||||
return cfg, fmt.Errorf("apiVersion not found in bundle")
|
|
||||||
}
|
|
||||||
log.Printf("[config] app_id=%s api=%s", cfg.AppID, cfg.APIVersion)
|
|
||||||
|
|
||||||
// Find webCallsBridge chunk
|
|
||||||
bridgeRef := regexp.MustCompile(`core_spa/chunks/webCallsBridge\.([a-f0-9]+)\.js`).FindStringSubmatch(bundleStr)
|
|
||||||
if bridgeRef == nil {
|
|
||||||
return cfg, fmt.Errorf("webCallsBridge chunk not found in bundle")
|
|
||||||
}
|
|
||||||
bridgeURL := chunksBase + "webCallsBridge." + bridgeRef[1] + ".js"
|
|
||||||
bridgeData, err := httpGet(bridgeURL)
|
|
||||||
if err != nil {
|
|
||||||
return cfg, fmt.Errorf("failed to fetch bridge chunk: %w", err)
|
|
||||||
}
|
|
||||||
bridgeStr := string(bridgeData)
|
|
||||||
|
|
||||||
// Extract module IDs imported by the bridge
|
|
||||||
requireRe := regexp.MustCompile(`i\((\d{4,6})\)`)
|
|
||||||
matches := requireRe.FindAllStringSubmatch(bridgeStr, -1)
|
|
||||||
seen := map[string]bool{}
|
|
||||||
var moduleIds []string
|
|
||||||
for _, m := range matches {
|
|
||||||
if !seen[m[1]] {
|
|
||||||
seen[m[1]] = true
|
|
||||||
moduleIds = append(moduleIds, m[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build chunk ID -> hash map from the bundle
|
|
||||||
chunkMap := map[string]string{}
|
|
||||||
chunkRe := regexp.MustCompile(`(\d+)===e\)return"core_spa/chunks/"\+e\+"\.([a-f0-9]+)\.js"`)
|
|
||||||
for _, m := range chunkRe.FindAllStringSubmatch(bundleStr, -1) {
|
|
||||||
chunkMap[m[1]] = m[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match module IDs to chunk IDs, fetch until sdkVersion found
|
|
||||||
sdkVerRe := regexp.MustCompile(`sdkVersion.{0,40}return\s*"([^"]+)"`)
|
|
||||||
appVerRe := regexp.MustCompile(`appVersion.{0,40}return\s+([0-9.]+)`)
|
|
||||||
protoVerRe := regexp.MustCompile(`protocolVersion.{0,40}return.*?(\d+)`)
|
|
||||||
|
|
||||||
for _, modId := range moduleIds {
|
|
||||||
// try exact match, then with first digit dropped
|
|
||||||
chunkId := modId
|
|
||||||
hash, ok := chunkMap[chunkId]
|
|
||||||
if !ok {
|
|
||||||
chunkId = modId[1:]
|
|
||||||
hash, ok = chunkMap[chunkId]
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
chunkURL := fmt.Sprintf("%s%s.%s.js", chunksBase, chunkId, hash)
|
|
||||||
chunkData, err := httpGet(chunkURL)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
chunkStr := string(chunkData)
|
|
||||||
|
|
||||||
sv := sdkVerRe.FindStringSubmatch(chunkStr)
|
|
||||||
if sv == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[config] Found SDK in chunk %s", chunkId)
|
|
||||||
cfg.SDKVersion = sv[1]
|
|
||||||
if av := appVerRe.FindStringSubmatch(chunkStr); av != nil {
|
|
||||||
cfg.AppVersion = av[1]
|
|
||||||
} else {
|
|
||||||
log.Printf("[config] WARNING: appVersion not found in SDK chunk")
|
|
||||||
}
|
|
||||||
if pv := protoVerRe.FindStringSubmatch(chunkStr); pv != nil {
|
|
||||||
cfg.ProtocolVersion = pv[1]
|
|
||||||
} else {
|
|
||||||
log.Printf("[config] WARNING: protocolVersion not found in SDK chunk")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.SDKVersion == "" {
|
|
||||||
return cfg, fmt.Errorf("sdkVersion not found in any chunk")
|
|
||||||
}
|
|
||||||
log.Printf("[config] sdk=%s app=%s proto=%s", cfg.SDKVersion, cfg.AppVersion, cfg.ProtocolVersion)
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
BIN
Binary file not shown.
@@ -9,7 +9,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,28 +16,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const vkConfigCacheKey = "vk_config"
|
|
||||||
|
|
||||||
func loadCachedConfig(cache CacheStore) *vkConfig {
|
|
||||||
data := cache.Load(vkConfigCacheKey)
|
|
||||||
if data == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var cfg vkConfig
|
|
||||||
if json.Unmarshal([]byte(data), &cfg) != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
func saveCachedConfig(cache CacheStore, cfg *vkConfig) {
|
|
||||||
data, err := json.Marshal(cfg)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cache.Save(vkConfigCacheKey, string(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
type vkConfig struct {
|
type vkConfig struct {
|
||||||
AppID string `json:"appID"`
|
AppID string `json:"appID"`
|
||||||
ApiVersion string `json:"apiVersion"`
|
ApiVersion string `json:"apiVersion"`
|
||||||
@@ -69,16 +46,6 @@ func RunVKAuth(joinLink string, displayName string, logFn func(string, ...any),
|
|||||||
}
|
}
|
||||||
client := &http.Client{Timeout: 60 * time.Second, Transport: transport}
|
client := &http.Client{Timeout: 60 * time.Second, Transport: transport}
|
||||||
|
|
||||||
httpGet := func(targetURL string) ([]byte, error) {
|
|
||||||
req, _ := http.NewRequest("GET", targetURL, nil)
|
|
||||||
req.Header.Set("User-Agent", common.UserAgent)
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
return io.ReadAll(resp.Body)
|
|
||||||
}
|
|
||||||
|
|
||||||
httpPost := func(targetURL string, form url.Values, extraHeaders map[string]string) (map[string]interface{}, error) {
|
httpPost := func(targetURL string, form url.Values, extraHeaders map[string]string) (map[string]interface{}, error) {
|
||||||
req, _ := http.NewRequest("POST", targetURL, strings.NewReader(form.Encode()))
|
req, _ := http.NewRequest("POST", targetURL, strings.NewReader(form.Encode()))
|
||||||
@@ -105,20 +72,13 @@ func RunVKAuth(joinLink string, displayName string, logFn func(string, ...any),
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use cached config if available, fetch only if missing
|
cfg := &vkConfig{
|
||||||
cfg := loadCachedConfig(cache)
|
AppID: "6287487",
|
||||||
if cfg != nil {
|
ApiVersion: "5.276",
|
||||||
logFn("vk-auth: using cached config appID=%s api=%s", cfg.AppID, cfg.ApiVersion)
|
AppVersion: "1.1",
|
||||||
} else {
|
ProtocolVersion: "6",
|
||||||
statusFn("Fetching config...")
|
|
||||||
logFn("vk-auth: fetching config")
|
|
||||||
var err error
|
|
||||||
cfg, err = fetchVKConfig(httpGet, logFn)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("fetchConfig: %w", err)
|
|
||||||
}
|
|
||||||
saveCachedConfig(cache, cfg)
|
|
||||||
}
|
}
|
||||||
|
logFn("vk-auth: appID=%s api=%s appVersion=%s proto=%s", cfg.AppID, cfg.ApiVersion, cfg.AppVersion, cfg.ProtocolVersion)
|
||||||
|
|
||||||
// Get anonymous token
|
// Get anonymous token
|
||||||
statusFn("Getting anonymous token...")
|
statusFn("Getting anonymous token...")
|
||||||
@@ -312,101 +272,6 @@ func RunVKAuth(joinLink string, displayName string, logFn func(string, ...any),
|
|||||||
return string(jsonBytes), nil
|
return string(jsonBytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchVKConfig(httpGet func(string) ([]byte, error), logFn func(string, ...any)) (*vkConfig, error) {
|
|
||||||
page, err := httpGet("https://vk.com")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("fetch vk.com: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bundleRe := regexp.MustCompile(`https://[a-z0-9.-]+/dist/core_spa/core_spa_vk\.[a-f0-9]+\.js`)
|
|
||||||
bundleURL := bundleRe.FindString(string(page))
|
|
||||||
if bundleURL == "" {
|
|
||||||
return nil, fmt.Errorf("bundle URL not found")
|
|
||||||
}
|
|
||||||
logFn("vk-auth: bundle=%s", bundleURL[strings.LastIndex(bundleURL, "/")+1:])
|
|
||||||
|
|
||||||
bundle, err := httpGet(bundleURL)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("fetch bundle: %w", err)
|
|
||||||
}
|
|
||||||
bundleStr := string(bundle)
|
|
||||||
chunksBase := bundleURL[:strings.LastIndex(bundleURL, "core_spa_vk.")] + "chunks/"
|
|
||||||
|
|
||||||
cfg := &vkConfig{}
|
|
||||||
if m := regexp.MustCompile(`[,;]u=(\d{7,8}),[a-z]=\d{7,9}`).FindStringSubmatch(bundleStr); m != nil {
|
|
||||||
cfg.AppID = m[1]
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("appID not found")
|
|
||||||
}
|
|
||||||
if m := regexp.MustCompile(`\d+:\(e,t,n\)=>\{"use strict";n\.d\(t,\{m:\(\)=>r\}\);const r="(5\.\d+)"\}`).FindStringSubmatch(bundleStr); m != nil {
|
|
||||||
cfg.ApiVersion = m[1]
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("apiVersion not found")
|
|
||||||
}
|
|
||||||
logFn("vk-auth: appID=%s api=%s", cfg.AppID, cfg.ApiVersion)
|
|
||||||
|
|
||||||
bridgeRef := regexp.MustCompile(`core_spa/chunks/webCallsBridge\.([a-f0-9]+)\.js`).FindStringSubmatch(bundleStr)
|
|
||||||
if bridgeRef == nil {
|
|
||||||
return nil, fmt.Errorf("webCallsBridge not found")
|
|
||||||
}
|
|
||||||
bridgeURL := chunksBase + "webCallsBridge." + bridgeRef[1] + ".js"
|
|
||||||
bridgeData, err := httpGet(bridgeURL)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("fetch bridge: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
requireRe := regexp.MustCompile(`i\((\d{4,6})\)`)
|
|
||||||
matches := requireRe.FindAllStringSubmatch(string(bridgeData), -1)
|
|
||||||
seen := map[string]bool{}
|
|
||||||
var moduleIds []string
|
|
||||||
for _, m := range matches {
|
|
||||||
if !seen[m[1]] {
|
|
||||||
seen[m[1]] = true
|
|
||||||
moduleIds = append(moduleIds, m[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chunkMap := map[string]string{}
|
|
||||||
chunkRe := regexp.MustCompile(`(\d+)===e\)return"core_spa/chunks/"\+e\+"\.([a-f0-9]+)\.js"`)
|
|
||||||
for _, m := range chunkRe.FindAllStringSubmatch(bundleStr, -1) {
|
|
||||||
chunkMap[m[1]] = m[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
appVerRe := regexp.MustCompile(`appVersion.{0,40}return\s+([0-9.]+)`)
|
|
||||||
protoVerRe := regexp.MustCompile(`protocolVersion.{0,40}return.*?(\d+)`)
|
|
||||||
|
|
||||||
for _, modId := range moduleIds {
|
|
||||||
chunkId := modId
|
|
||||||
hash, ok := chunkMap[chunkId]
|
|
||||||
if !ok {
|
|
||||||
chunkId = modId[1:]
|
|
||||||
hash, ok = chunkMap[chunkId]
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
chunkURL := fmt.Sprintf("%s%s.%s.js", chunksBase, chunkId, hash)
|
|
||||||
chunkData, err := httpGet(chunkURL)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
chunkStr := string(chunkData)
|
|
||||||
if av := appVerRe.FindStringSubmatch(chunkStr); av != nil {
|
|
||||||
cfg.AppVersion = av[1]
|
|
||||||
if pv := protoVerRe.FindStringSubmatch(chunkStr); pv != nil {
|
|
||||||
cfg.ProtocolVersion = pv[1]
|
|
||||||
}
|
|
||||||
logFn("vk-auth: appVersion=%s proto=%s", cfg.AppVersion, cfg.ProtocolVersion)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.AppVersion == "" {
|
|
||||||
return nil, fmt.Errorf("appVersion not found")
|
|
||||||
}
|
|
||||||
return cfg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseVKCaptchaError(errObj map[string]interface{}) *vkCaptchaError {
|
func parseVKCaptchaError(errObj map[string]interface{}) *vkCaptchaError {
|
||||||
redirectURI, _ := errObj["redirect_uri"].(string)
|
redirectURI, _ := errObj["redirect_uri"].(string)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
|
|||||||
Reference in new issue
Block a user