Files
whitelist-bypass/headless/vk/config.go
T
029b536250 V0.2.0 (#37)
* refactor go files, add headless telemost support

* js crap -> ts crap

* docker-build (#32)

Co-authored-by: Mimocro <suzumagefag@gmail.com>

* add headless telemost for creator app

* UX improvements (#39)

* Add search in split tunneling app list

* Add captcha detection

* Add autoclick settings

* headless vk joiner

* add headless telemost joiner

* refactor go modules

* redesign settings dialog

* headless option in settings

* headless joiner support in MainActivity

* display headless vk status in statusBar

* update ux for headless in creator app

* fix double log render for headless mode in creator

* unicode for cyrillic

* add socks auth

* put socksPort inf prefs, verify that port is free on start

* proxy only mode

* mask addresses in go network errors

* update docker build, add file write logic for headless

* increment release version, add make-release script

---------

Co-authored-by: kulikov <user@Mac.lan>
Co-authored-by: Mimocro <67226986+Mimocro@users.noreply.github.com>
Co-authored-by: Mimocro <suzumagefag@gmail.com>
Co-authored-by: senya <76913432+senya-sh@users.noreply.github.com>
2026-04-12 17:14:51 +02:00

139 lines
4.0 KiB
Go

package main
import (
"fmt"
"log"
"regexp"
"strings"
)
type VKConfig struct {
AppID string
APIVersion string
SDKVersion string
AppVersion string
ProtocolVersion string
}
func fetchConfig() (VKConfig, error) {
var cfg VKConfig
// Discover current bundle URL
page, err := httpGet("https://vk.com")
if err != nil {
return cfg, fmt.Errorf("failed to 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 == "" {
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}),_=\d{7,8},p=\d{8,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
}