From beccc40522da9e841a69626e5981b279d7b16cb8 Mon Sep 17 00:00:00 2001
From: kulikov0 <19497634+kulikov0@users.noreply.github.com>
Date: Sat, 16 May 2026 08:32:36 +0200
Subject: [PATCH] single export cookies button
---
creator-app/index.html | 5 +-
creator-app/src/constants.ts | 2 +-
creator-app/src/main/ipc.ts | 26 ++-------
creator-app/src/main/tab-manager.ts | 61 +++++++--------------
creator-app/src/main/util/log-tags.ts | 28 ++++++++++
creator-app/src/main/util/paths.ts | 13 +++++
creator-app/src/main/util/zip.ts | 78 +++++++++++++++++++++++++++
creator-app/src/main/window.ts | 31 ++---------
creator-app/src/preload/index.ts | 4 +-
creator-app/src/renderer/dom.ts | 13 ++---
creator-app/src/renderer/index.ts | 27 +---------
creator-app/src/types.ts | 2 +-
12 files changed, 158 insertions(+), 132 deletions(-)
create mode 100644 creator-app/src/main/util/log-tags.ts
create mode 100644 creator-app/src/main/util/paths.ts
create mode 100644 creator-app/src/main/util/zip.ts
diff --git a/creator-app/index.html b/creator-app/index.html
index 0924937..3a2054a 100644
--- a/creator-app/index.html
+++ b/creator-app/index.html
@@ -9,10 +9,7 @@
+
-
VK Cookies
-
Yandex Cookies
-
DION Cookies
-
WB Cookies
+
Export Cookies
Settings
Bot: Off
diff --git a/creator-app/src/constants.ts b/creator-app/src/constants.ts
index fcea3a0..2953d46 100644
--- a/creator-app/src/constants.ts
+++ b/creator-app/src/constants.ts
@@ -58,7 +58,7 @@ export enum IPC {
CLOSE_TAB = 'close-tab',
START_BOT = 'start-bot',
STOP_BOT = 'stop-bot',
- GET_COOKIES = 'get-cookies',
+ EXPORT_COOKIES_ZIP = 'export-cookies-zip',
RELAY_LOG = 'relay-log',
CREATE_BOT_TAB = 'create-bot-tab',
CLOSE_BOT_TAB = 'close-bot-tab',
diff --git a/creator-app/src/main/ipc.ts b/creator-app/src/main/ipc.ts
index c8ea687..66f02a3 100644
--- a/creator-app/src/main/ipc.ts
+++ b/creator-app/src/main/ipc.ts
@@ -1,16 +1,9 @@
-import { ipcMain, session } from 'electron';
+import { ipcMain } from 'electron';
import * as path from 'path';
import * as fs from 'fs/promises';
import { TabManager } from './tab-manager';
import { BotManager } from '../bot/bot-manager';
-import {
- IPC,
- SESSION_PARTITION,
- VK_COOKIE_DOMAINS,
- YANDEX_COOKIE_DOMAINS,
- DION_COOKIE_DOMAINS,
- WBSTREAM_COOKIE_DOMAINS,
-} from '../constants';
+import { IPC } from '../constants';
import { TunnelMode, Platform, BotSettings, HeadlessStartArgs } from '../types';
export function registerIpcHandlers(tabManager: TabManager): void {
@@ -96,18 +89,7 @@ export function registerIpcHandlers(tabManager: TabManager): void {
tabManager.sendBotCallLink(tabId, link);
});
- ipcMain.handle(IPC.GET_COOKIES, async (_e, domain: string) => {
- const ses = session.fromPartition(SESSION_PARTITION);
- const all = await ses.cookies.get({});
- let domains: string[];
- if (domain === 'yandex') domains = YANDEX_COOKIE_DOMAINS;
- else if (domain === 'dion') domains = DION_COOKIE_DOMAINS;
- else if (domain === 'wbstream') domains = WBSTREAM_COOKIE_DOMAINS;
- else domains = VK_COOKIE_DOMAINS;
- const filtered = all.filter((cookie) => {
- return cookie.domain != null && domains.some((d) => cookie.domain!.includes(d));
- });
- console.log(`[COOKIES] total: ${all.length} ${domain}: ${filtered.length}`);
- return filtered;
+ ipcMain.handle(IPC.EXPORT_COOKIES_ZIP, async () => {
+ return tabManager.buildCookiesZip();
});
}
diff --git a/creator-app/src/main/tab-manager.ts b/creator-app/src/main/tab-manager.ts
index d948491..b7b1bed 100644
--- a/creator-app/src/main/tab-manager.ts
+++ b/creator-app/src/main/tab-manager.ts
@@ -35,17 +35,8 @@ import {
LOG_CAPTURE_SNIPPET,
} from '../constants';
import { BotManager } from '../bot/bot-manager';
-
-function resolveResourcePath(devRelative: string, packedName: string): string {
- if (app.isPackaged) {
- return path.join(process.resourcesPath!, packedName);
- }
- return path.join(__dirname, '..', '..', '..', devRelative);
-}
-
-function binaryName(base: string): string {
- return process.platform === 'win32' ? base + '.exe' : base;
-}
+import { buildStoredZip } from './util/zip';
+import { resolveResourcePath, binaryName } from './util/paths';
export class TabManager {
private tabs = new Map();
@@ -248,7 +239,6 @@ export class TabManager {
cookieDomains: string[];
platformName: string;
binaryPath: string;
- getCookies: () => Promise<{ name: string; value: string }[]>;
} | null {
switch (platform) {
case Platform.Telemost:
@@ -259,7 +249,6 @@ export class TabManager {
cookieDomains: YANDEX_COOKIE_DOMAINS,
platformName: 'Yandex',
binaryPath: this.headlessTelemostPath,
- getCookies: () => this.getYandexCookies(),
};
case Platform.Dion:
return {
@@ -269,7 +258,6 @@ export class TabManager {
cookieDomains: DION_COOKIE_DOMAINS,
platformName: 'DION',
binaryPath: this.headlessDionPath,
- getCookies: () => this.getDionCookies(),
};
case Platform.VK:
return {
@@ -279,7 +267,6 @@ export class TabManager {
cookieDomains: VK_COOKIE_DOMAINS,
platformName: 'VK',
binaryPath: this.headlessVKPath,
- getCookies: () => this.getVKCookies(),
};
case Platform.WBStream:
return {
@@ -289,7 +276,6 @@ export class TabManager {
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
platformName: 'WB Stream',
binaryPath: this.headlessWBStreamPath,
- getCookies: () => this.getWBStreamCookies(),
};
default:
return null;
@@ -325,7 +311,7 @@ export class TabManager {
return;
}
tab.tunnelMode = config.tunnelMode;
- let cookies = await config.getCookies();
+ let cookies = await this.getCookiesForDomains(config.cookieDomains);
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
const needsLogin = !cookies.some((c) => c.name === refreshCookie);
if (needsLogin) {
@@ -343,7 +329,7 @@ export class TabManager {
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
}
this.sendLog(tabId, `${config.platformName} login captured.`);
- cookies = await config.getCookies();
+ cookies = await this.getCookiesForDomains(config.cookieDomains);
}
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
this.killRelay(tabId, tab);
@@ -460,27 +446,11 @@ export class TabManager {
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
}
- async getVKCookies(): Promise<{ name: string; value: string }[]> {
+ private async getCookiesForDomains(domains: string[]): Promise<{ name: string; value: string }[]> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
return all
- .filter((c) => c.domain != null && VK_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
- .map((c) => ({ name: c.name, value: c.value }));
- }
-
- async getYandexCookies(): Promise<{ name: string; value: string }[]> {
- const ses = session.fromPartition(SESSION_PARTITION);
- const all = await ses.cookies.get({});
- return all
- .filter((c) => c.domain != null && YANDEX_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
- .map((c) => ({ name: c.name, value: c.value }));
- }
-
- async getDionCookies(): Promise<{ name: string; value: string }[]> {
- const ses = session.fromPartition(SESSION_PARTITION);
- const all = await ses.cookies.get({});
- return all
- .filter((c) => c.domain != null && DION_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
+ .filter((c) => c.domain != null && domains.some((d) => c.domain!.includes(d)))
.map((c) => ({ name: c.name, value: c.value }));
}
@@ -513,12 +483,19 @@ export class TabManager {
});
}
- async getWBStreamCookies(): Promise<{ name: string; value: string }[]> {
- const ses = session.fromPartition(SESSION_PARTITION);
- const all = await ses.cookies.get({});
- return all
- .filter((c) => c.domain != null && WBSTREAM_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
- .map((c) => ({ name: c.name, value: c.value }));
+ async buildCookiesZip(): Promise {
+ const platforms: { filename: string; domains: string[] }[] = [
+ { filename: 'vk-cookies.json', domains: VK_COOKIE_DOMAINS },
+ { filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS },
+ { filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS },
+ { filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS },
+ ];
+ const cookies = await Promise.all(platforms.map((p) => this.getCookiesForDomains(p.domains)));
+ const entries = platforms.map((p, i) => ({
+ name: p.filename,
+ data: Buffer.from(JSON.stringify(cookies[i], null, 2), 'utf8'),
+ }));
+ return buildStoredZip(entries);
}
async setWBStreamDeviceId(id: string): Promise {
diff --git a/creator-app/src/main/util/log-tags.ts b/creator-app/src/main/util/log-tags.ts
new file mode 100644
index 0000000..b6c8aa5
--- /dev/null
+++ b/creator-app/src/main/util/log-tags.ts
@@ -0,0 +1,28 @@
+import { CallStatus, Platform } from '../../types';
+
+export function parseCallStatus(msg: string): { tabId: string; status: CallStatus } | null {
+ const prefix = '[CALL_STATUS] ';
+ const idx = msg.indexOf(prefix);
+ if (idx === -1) return null;
+ const parts = msg.substring(idx + prefix.length);
+ const colonIdx = parts.indexOf(':');
+ if (colonIdx === -1) return null;
+ const status = parts.substring(colonIdx + 1);
+ return {
+ tabId: parts.substring(0, colonIdx),
+ status: status === CallStatus.Active ? CallStatus.Active : CallStatus.Inactive,
+ };
+}
+
+export function extractTaggedCallLink(msg: string, platform: Platform): { tabId: string; link: string } | null {
+ const tag = platform === Platform.Telemost ? 'Telemost' : 'VKCalls';
+ const re = new RegExp('\\[BOT\\] ' + tag + '\\[([^\\]]*)\\]: call link:\\s*(.+)$');
+ const match = msg.match(re);
+ if (!match) return null;
+ return { tabId: match[1].trim(), link: match[2].trim() };
+}
+
+export function parseWBDeviceId(msg: string): string | null {
+ const match = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
+ return match ? match[1] : null;
+}
diff --git a/creator-app/src/main/util/paths.ts b/creator-app/src/main/util/paths.ts
new file mode 100644
index 0000000..5b29a7e
--- /dev/null
+++ b/creator-app/src/main/util/paths.ts
@@ -0,0 +1,13 @@
+import { app } from 'electron';
+import * as path from 'path';
+
+export function resolveResourcePath(devRelative: string, packedName: string): string {
+ if (app.isPackaged) {
+ return path.join(process.resourcesPath!, packedName);
+ }
+ return path.join(__dirname, '..', '..', '..', '..', devRelative);
+}
+
+export function binaryName(base: string): string {
+ return process.platform === 'win32' ? base + '.exe' : base;
+}
diff --git a/creator-app/src/main/util/zip.ts b/creator-app/src/main/util/zip.ts
new file mode 100644
index 0000000..76ca1c5
--- /dev/null
+++ b/creator-app/src/main/util/zip.ts
@@ -0,0 +1,78 @@
+export interface ZipEntry {
+ name: string;
+ data: Buffer;
+}
+
+const crc32Table = (() => {
+ const table = new Uint32Array(256);
+ for (let i = 0; i < 256; i++) {
+ let c = i;
+ for (let j = 0; j < 8; j++) c = (c & 1) ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
+ table[i] = c >>> 0;
+ }
+ return table;
+})();
+
+function crc32(buf: Buffer): number {
+ let c = 0xffffffff;
+ for (let i = 0; i < buf.length; i++) c = crc32Table[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
+ return (c ^ 0xffffffff) >>> 0;
+}
+
+export function buildStoredZip(entries: ZipEntry[]): Buffer {
+ const localChunks: Buffer[] = [];
+ const centralChunks: Buffer[] = [];
+ let offset = 0;
+ const dosTime = 0;
+ const dosDate = (1 << 5) | 1;
+ for (const entry of entries) {
+ const nameBytes = Buffer.from(entry.name, 'utf8');
+ const crc = crc32(entry.data);
+ const size = entry.data.length;
+ const lfh = Buffer.alloc(30);
+ lfh.writeUInt32LE(0x04034b50, 0);
+ lfh.writeUInt16LE(20, 4);
+ lfh.writeUInt16LE(0, 6);
+ lfh.writeUInt16LE(0, 8);
+ lfh.writeUInt16LE(dosTime, 10);
+ lfh.writeUInt16LE(dosDate, 12);
+ lfh.writeUInt32LE(crc, 14);
+ lfh.writeUInt32LE(size, 18);
+ lfh.writeUInt32LE(size, 22);
+ lfh.writeUInt16LE(nameBytes.length, 26);
+ lfh.writeUInt16LE(0, 28);
+ localChunks.push(lfh, nameBytes, entry.data);
+ const cdh = Buffer.alloc(46);
+ cdh.writeUInt32LE(0x02014b50, 0);
+ cdh.writeUInt16LE(20, 4);
+ cdh.writeUInt16LE(20, 6);
+ cdh.writeUInt16LE(0, 8);
+ cdh.writeUInt16LE(0, 10);
+ cdh.writeUInt16LE(dosTime, 12);
+ cdh.writeUInt16LE(dosDate, 14);
+ cdh.writeUInt32LE(crc, 16);
+ cdh.writeUInt32LE(size, 20);
+ cdh.writeUInt32LE(size, 24);
+ cdh.writeUInt16LE(nameBytes.length, 28);
+ cdh.writeUInt16LE(0, 30);
+ cdh.writeUInt16LE(0, 32);
+ cdh.writeUInt16LE(0, 34);
+ cdh.writeUInt16LE(0, 36);
+ cdh.writeUInt32LE(0, 38);
+ cdh.writeUInt32LE(offset, 42);
+ centralChunks.push(cdh, nameBytes);
+ offset += lfh.length + nameBytes.length + size;
+ }
+ const local = Buffer.concat(localChunks);
+ const central = Buffer.concat(centralChunks);
+ const eocd = Buffer.alloc(22);
+ eocd.writeUInt32LE(0x06054b50, 0);
+ eocd.writeUInt16LE(0, 4);
+ eocd.writeUInt16LE(0, 6);
+ eocd.writeUInt16LE(entries.length, 8);
+ eocd.writeUInt16LE(entries.length, 10);
+ eocd.writeUInt32LE(central.length, 12);
+ eocd.writeUInt32LE(local.length, 16);
+ eocd.writeUInt16LE(0, 20);
+ return Buffer.concat([local, central, eocd]);
+}
diff --git a/creator-app/src/main/window.ts b/creator-app/src/main/window.ts
index fe3f2fa..8768425 100644
--- a/creator-app/src/main/window.ts
+++ b/creator-app/src/main/window.ts
@@ -4,7 +4,8 @@ import { TabManager } from './tab-manager';
import { VkAutoclick } from '../autoclick/vk';
import { TelemostAutoclick } from '../autoclick/telemost';
import { SESSION_PARTITION, USER_AGENT, WINDOW_WIDTH, WINDOW_HEIGHT } from '../constants';
-import { Platform, CallStatus } from '../types';
+import { Platform } from '../types';
+import { parseCallStatus, extractTaggedCallLink, parseWBDeviceId } from './util/log-tags';
function stripCSP(ses: Session): void {
ses.webRequest.onHeadersReceived((details, callback) => {
@@ -17,28 +18,6 @@ function stripCSP(ses: Session): void {
});
}
-function parseCallStatus(msg: string): { tabId: string; status: CallStatus } | null {
- const prefix = '[CALL_STATUS] ';
- const idx = msg.indexOf(prefix);
- if (idx === -1) return null;
- const parts = msg.substring(idx + prefix.length);
- const colonIdx = parts.indexOf(':');
- if (colonIdx === -1) return null;
- const status = parts.substring(colonIdx + 1);
- return {
- tabId: parts.substring(0, colonIdx),
- status: status === CallStatus.Active ? CallStatus.Active : CallStatus.Inactive,
- };
-}
-
-function extractTaggedCallLink(msg: string, platform: Platform): { tabId: string; link: string } | null {
- const tag = platform === Platform.Telemost ? 'Telemost' : 'VKCalls';
- const re = new RegExp('\\[BOT\\] ' + tag + '\\[([^\\]]*)\\]: call link:\\s*(.+)$');
- const match = msg.match(re);
- if (!match) return null;
- return { tabId: match[1].trim(), link: match[2].trim() };
-}
-
export function createWindow(tabManager: TabManager): BrowserWindow {
const ses = session.fromPartition(SESSION_PARTITION);
stripCSP(ses);
@@ -130,9 +109,9 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
handleBotCallLink(tabManager, msg, Platform.VK);
handleBotCallLink(tabManager, msg, Platform.Telemost);
- const deviceIdMatch = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
- if (deviceIdMatch) {
- tabManager.setWBStreamDeviceId(deviceIdMatch[1]).catch(() => {});
+ const deviceId = parseWBDeviceId(msg);
+ if (deviceId) {
+ tabManager.setWBStreamDeviceId(deviceId).catch(() => {});
}
const callStatus = parseCallStatus(msg);
diff --git a/creator-app/src/preload/index.ts b/creator-app/src/preload/index.ts
index 61391b6..a2d0c5e 100644
--- a/creator-app/src/preload/index.ts
+++ b/creator-app/src/preload/index.ts
@@ -32,8 +32,8 @@ import { IPC } from '../constants';
onBotError(cb: (msg: string) => void) {
ipcRenderer.on(IPC.BOT_ERROR, (_e, msg) => cb(msg));
},
- getCookies(domain: string) {
- return ipcRenderer.invoke(IPC.GET_COOKIES, domain);
+ exportCookiesZip() {
+ return ipcRenderer.invoke(IPC.EXPORT_COOKIES_ZIP);
},
startHeadless(tabId: string, platform: string, args: any) {
return ipcRenderer.invoke(IPC.START_HEADLESS, tabId, platform, args);
diff --git a/creator-app/src/renderer/dom.ts b/creator-app/src/renderer/dom.ts
index 0845679..e51359b 100644
--- a/creator-app/src/renderer/dom.ts
+++ b/creator-app/src/renderer/dom.ts
@@ -285,17 +285,12 @@ export function saveLogs(): void {
URL.revokeObjectURL(anchor.href);
}
-export function exportCookies(domain: string, filename: string, errorMsg: string): void {
- window.bridge.getCookies(domain).then((cookies) => {
- if (!cookies.length) {
- showError(errorMsg);
- return;
- }
- const simple = cookies.map((cookie) => ({ name: cookie.name, value: cookie.value }));
- const blob = new Blob([JSON.stringify(simple, null, 2)], { type: 'application/json' });
+export function exportCookiesZip(): void {
+ window.bridge.exportCookiesZip().then((bytes) => {
+ const blob = new Blob([new Uint8Array(bytes)], { type: 'application/zip' });
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(blob);
- anchor.download = filename;
+ anchor.download = 'cookies.zip';
anchor.click();
URL.revokeObjectURL(anchor.href);
});
diff --git a/creator-app/src/renderer/index.ts b/creator-app/src/renderer/index.ts
index 7ba8022..af87502 100644
--- a/creator-app/src/renderer/index.ts
+++ b/creator-app/src/renderer/index.ts
@@ -9,7 +9,7 @@ import {
closeError,
clearLog,
saveLogs,
- exportCookies,
+ exportCookiesZip,
copyToClipboard,
renameTab,
attachLoginWebview,
@@ -66,30 +66,7 @@ function bindToolbarEvents(): void {
}
function bindActionBarEvents(): void {
- document.getElementById('btnVkCookies')!.addEventListener('click', () => {
- exportCookies('.vk.com', 'vk-cookies.json', 'No VK cookies found.\nPlease log into VK first.');
- });
- document.getElementById('btnYandexCookies')!.addEventListener('click', () => {
- exportCookies(
- 'yandex',
- 'cookies-yandex.json',
- 'No Yandex cookies found.\nPlease log into Yandex (telemost.yandex.ru) first.',
- );
- });
- document.getElementById('btnDionCookies')!.addEventListener('click', () => {
- exportCookies(
- 'dion',
- 'cookies-dion.json',
- 'No DION cookies found.\nPlease log into DION (dion.vc) first.',
- );
- });
- document.getElementById('btnWBStreamCookies')!.addEventListener('click', () => {
- exportCookies(
- 'wbstream',
- 'cookies-wbstream.json',
- 'No WB Stream cookies found.\nPlease log into stream.wb.ru first.',
- );
- });
+ document.getElementById('btnExportCookies')!.addEventListener('click', exportCookiesZip);
document.getElementById('btnSettings')!.addEventListener('click', openSettings);
document.getElementById('tabBot')!.addEventListener('click', () => {
if (!tm.botSettings.token || !tm.botSettings.groupId) {
diff --git a/creator-app/src/types.ts b/creator-app/src/types.ts
index 347215d..667911c 100644
--- a/creator-app/src/types.ts
+++ b/creator-app/src/types.ts
@@ -141,7 +141,7 @@ export interface Bridge {
onCreateBotTab(cb: (data: BotTabData) => void): void;
getCallCreatorCode(scriptFile: string): Promise;
onBotError(cb: (msg: string) => void): void;
- getCookies(domain: string): Promise;
+ exportCookiesZip(): Promise;
startHeadless(tabId: string, platform: string, args: HeadlessStartArgs): Promise;
sendBotCallLink(tabId: string, link: string): Promise;
onCloseBotTab(cb: (data: { tabId: string }) => void): void;