Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
d2 refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed Oct 9, 2021
1 parent 4f39e50 commit a19f949
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/oicq.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ Client.prototype._register = async function () {
};

Client.prototype._var4 = 0;
Client.prototype._runCircleTask = function () {
Client.prototype._runCircleTask = async function () {
if (this._var4++ > 10) {
this._wt.exchangeEmp();
await this._wt.refreshD2();
if (this.config.platform != 2 && this.config.platform != 3)
this.setOnlineStatus(this.online_status);
this._var4 = 0;
Expand All @@ -222,7 +222,7 @@ Client.prototype._startHeartbeat = function () {
if (this._heartbeat)
return;
this._heartbeat = setInterval(async () => {
this._runCircleTask();
await this._runCircleTask();
if (!await this.pbGetMsg() && this.isOnline()) {
this.logger.warn("GetMsg timeout!");
if (!await this.pbGetMsg() && this.isOnline())
Expand Down
49 changes: 47 additions & 2 deletions lib/wtlogin/login-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
const fs = require("fs");
const path = require("path");
const { randomBytes } = require("crypto");
const { WtLogin } = require("./wt");
const { WtLogin, readTlv } = require("./wt");
const Writer = require("./writer");
const { md5 } = require("../common");
const { md5, NOOP, timestamp } = require("../common");
const tea = require("../algo/tea");
const Readable = require("stream").Readable;

WtLogin.prototype.passwordLogin = async function () {
this.session_id = randomBytes(4);
Expand Down Expand Up @@ -166,3 +168,46 @@ WtLogin.prototype.tokenLogin = function (d2) {
.read();
this.sendLogin("wtlogin.exchange_emp", body);
}

WtLogin.prototype.refreshD2 = async function () {
if (!this.c.isOnline() || timestamp() - this.sig.emp_time < 14000)
return
this.device.tgtgt = md5(this.sig.d2key);
const t = this.tlvPacker;
const body = new Writer()
.writeU16(11)
.writeU16(16)
.writeBytes(t(0x100))
.writeBytes(t(0x10a))
.writeBytes(t(0x116))
.writeBytes(t(0x144))
.writeBytes(t(0x143, this.sig.d2))
.writeBytes(t(0x142))
.writeBytes(t(0x154))
.writeBytes(t(0x18))
.writeBytes(t(0x141))
.writeBytes(t(0x8))
.writeBytes(t(0x147))
.writeBytes(t(0x177))
.writeBytes(t(0x187))
.writeBytes(t(0x188))
.writeBytes(t(0x202))
.writeBytes(t(0x511))
.read();
const pkt = this._buildLoginPacket("wtlogin.exchange_emp", this._buildOICQPacket(body), 2);
try {
let payload = await this.c.send(pkt);
payload = tea.decrypt(payload.slice(16, payload.length - 1), this.ecdh.share_key);
const stream = Readable.from(payload, { objectMode: false });
stream.read(2);
const type = stream.read(1).readUInt8();
stream.read(2);
const t = readTlv(stream);
if (type === 0)
this.decodeT119(t[0x119], true);
const success = await this.register();
if (!success)
return this.c.emit("internal.network", "服务器繁忙(register)");
await this.exchangeEmp();
} catch { }
}
11 changes: 3 additions & 8 deletions lib/wtlogin/wt.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WtLogin {
sig_key: t[0x133] ? t[0x133] : this.sig.sig_key,
ticket_key: t[0x134] ? t[0x134] : this.sig.ticket_key,
device_token: t[0x322] ? t[0x322] : this.sig.device_token,
emp_time: token ? 0 : timestamp(),
emp_time: timestamp(),
};
fs.writeFile(
path.join(this.dir, "token"),
Expand Down Expand Up @@ -352,7 +352,7 @@ class WtLogin {
}

async exchangeEmp() {
if (!this.password_md5 || !this.c.isOnline() || timestamp() - this.sig.emp_time < 14400)
if (!this.password_md5 || !this.c.isOnline())
return;
const t = this.tlvPacker;
const body = new Writer()
Expand Down Expand Up @@ -392,13 +392,8 @@ class WtLogin {
const stream = Readable.from(payload, { objectMode: false });
stream.read(5);
const t = readTlv(stream);
if (t[0x119]) {
if (t[0x119])
this.decodeT119(t[0x119]);
} else {
this.deleteToken()
this.sig.emp_time = 0xffffffff;
this.logger.warn("刷新cookies失败,可能是由于你切换过登录协议或其他原因所导致。如果你需要使用依赖cookies的功能建议立即重新登录。");
}
} catch (e) {
this.logger.warn("刷新cookies失败。");
this.logger.warn(e);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "oicq",
"app_name": "oicq",
"version": "1.21.1",
"app_version": "1.21.1",
"upday": "2021/10/03",
"version": "1.21.2",
"app_version": "1.21.2",
"upday": "2021/10/10",
"protocol_version": "v11",
"description": "QQ protocol!",
"main": "index.js",
Expand Down

0 comments on commit a19f949

Please sign in to comment.