mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 04:45:46 +00:00
refactor: guid fk tx
This commit is contained in:
parent
5f73d6a913
commit
cdda5f45ee
@ -1,12 +1,8 @@
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { networkInterfaces } from 'os';
|
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
|
|
||||||
// 缓解Win7设备兼容性问题
|
// 缓解Win7设备兼容性问题
|
||||||
let osName: string;
|
let osName: string;
|
||||||
// 设备ID
|
|
||||||
let machineId: Promise<string>;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
osName = os.hostname();
|
osName = os.hostname();
|
||||||
@ -14,54 +10,6 @@ try {
|
|||||||
osName = 'NapCat'; // + crypto.randomUUID().substring(0, 4);
|
osName = 'NapCat'; // + crypto.randomUUID().substring(0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
const invalidMacAddresses = new Set([
|
|
||||||
'00:00:00:00:00:00',
|
|
||||||
'ff:ff:ff:ff:ff:ff',
|
|
||||||
'ac:de:48:00:11:22',
|
|
||||||
]);
|
|
||||||
|
|
||||||
function validateMacAddress(candidate: string): boolean {
|
|
||||||
// eslint-disable-next-line no-useless-escape
|
|
||||||
const tempCandidate = candidate.replace(/\-/g, ':').toLowerCase();
|
|
||||||
return !invalidMacAddresses.has(tempCandidate);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getMachineId(): Promise<string> {
|
|
||||||
if (!machineId) {
|
|
||||||
machineId = (async () => {
|
|
||||||
const id = await getMacMachineId();
|
|
||||||
return id ?? randomUUID(); // fallback, generate a UUID
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
return machineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMac(): string {
|
|
||||||
const ifaces = networkInterfaces();
|
|
||||||
for (const name in ifaces) {
|
|
||||||
const networkInterface = ifaces[name];
|
|
||||||
if (networkInterface) {
|
|
||||||
for (const { mac } of networkInterface) {
|
|
||||||
if (validateMacAddress(mac)) {
|
|
||||||
return mac;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('Unable to retrieve mac address (unexpected format)');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getMacMachineId(): Promise<string | undefined> {
|
|
||||||
try {
|
|
||||||
const crypto = await import('crypto');
|
|
||||||
const macAddress = getMac();
|
|
||||||
return crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
|
|
||||||
} catch (err) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const homeDir = os.homedir();
|
const homeDir = os.homedir();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import { QQBasicInfoWrapper } from '@/common/qq-basic-info';
|
|||||||
import { NapCatPathWrapper } from '@/common/path';
|
import { NapCatPathWrapper } from '@/common/path';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { getMachineId, hostname, systemName, systemVersion } from '@/common/system';
|
import { hostname, systemName, systemVersion } from '@/common/system';
|
||||||
import { NTEventWrapper } from '@/common/event';
|
import { NTEventWrapper } from '@/common/event';
|
||||||
import { DataSource, GroupMember, KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/entities';
|
import { DataSource, GroupMember, KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/entities';
|
||||||
import { NapCatConfigLoader } from '@/core/helper/config';
|
import { NapCatConfigLoader } from '@/core/helper/config';
|
||||||
@ -247,10 +247,16 @@ export class NapCatCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function genSessionConfig(QQVersionAppid: string, QQVersion: string, selfUin: string, selfUid: string, account_path: string): Promise<WrapperSessionInitConfig> {
|
export async function genSessionConfig(
|
||||||
|
guid:string,
|
||||||
|
QQVersionAppid: string,
|
||||||
|
QQVersion: string,
|
||||||
|
selfUin: string,
|
||||||
|
selfUid: string,
|
||||||
|
account_path: string
|
||||||
|
): Promise<WrapperSessionInitConfig> {
|
||||||
const downloadPath = path.join(account_path, 'NapCat', 'temp');
|
const downloadPath = path.join(account_path, 'NapCat', 'temp');
|
||||||
fs.mkdirSync(downloadPath, { recursive: true });
|
fs.mkdirSync(downloadPath, { recursive: true });
|
||||||
const guid: string = await getMachineId();//26702 支持JS获取guid值 在LoginService中获取 TODO mlikiow a
|
|
||||||
//os.platform()
|
//os.platform()
|
||||||
let systemPlatform = PlatformType.KWINDOWS;
|
let systemPlatform = PlatformType.KWINDOWS;
|
||||||
switch (os.platform()) {
|
switch (os.platform()) {
|
||||||
|
@ -59,6 +59,8 @@ export interface QuickLoginResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeIKernelLoginService {
|
export interface NodeIKernelLoginService {
|
||||||
|
getMachineGuid(): string;
|
||||||
|
|
||||||
get(): NodeIKernelLoginService;
|
get(): NodeIKernelLoginService;
|
||||||
|
|
||||||
connect(): boolean;
|
connect(): boolean;
|
||||||
|
@ -52,6 +52,7 @@ export async function NCoreInitShell() {
|
|||||||
const engine = wrapper.NodeIQQNTWrapperEngine.get();
|
const engine = wrapper.NodeIQQNTWrapperEngine.get();
|
||||||
//const util = wrapper.NodeQQNTWrapperUtil.get();
|
//const util = wrapper.NodeQQNTWrapperUtil.get();
|
||||||
const loginService = wrapper.NodeIKernelLoginService.get();
|
const loginService = wrapper.NodeIKernelLoginService.get();
|
||||||
|
|
||||||
const session = wrapper.NodeIQQNTWrapperSession.create();
|
const session = wrapper.NodeIQQNTWrapperSession.create();
|
||||||
|
|
||||||
// from get dataPath
|
// from get dataPath
|
||||||
@ -237,10 +238,16 @@ export async function NCoreInitShell() {
|
|||||||
let amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
let amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
||||||
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
||||||
// AFTER LOGGING IN
|
// AFTER LOGGING IN
|
||||||
|
//99b15bdb4c984fc69d5aa1feb9aa16xx --> 99b15bdb-4c98-4fc6-9d5a-a1feb9aa16xx
|
||||||
|
//把guid从左向右转换为guid格式 loginService.getMachineGuid()
|
||||||
|
|
||||||
|
let guid = loginService.getMachineGuid();
|
||||||
|
guid = guid.slice(0, 8) + '-' + guid.slice(8, 12) + '-' + guid.slice(12, 16) + '-' + guid.slice(16, 20) + '-' + guid.slice(20);
|
||||||
|
console.log('guid:', guid);
|
||||||
// from initSession
|
// from initSession
|
||||||
await new Promise<void>(async (resolve, reject) => {
|
await new Promise<void>(async (resolve, reject) => {
|
||||||
const sessionConfig = await genSessionConfig(
|
const sessionConfig = await genSessionConfig(
|
||||||
|
guid,
|
||||||
basicInfoWrapper.QQVersionAppid!,
|
basicInfoWrapper.QQVersionAppid!,
|
||||||
basicInfoWrapper.getFullQQVesion(),
|
basicInfoWrapper.getFullQQVesion(),
|
||||||
selfInfo.uin,
|
selfInfo.uin,
|
||||||
|
Loading…
Reference in New Issue
Block a user