@ikenxuan/amagi 1.5.3 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## 使用
8
8
  ```
9
- npm install @ikenxuan/amagi
9
+ pnpm add @ikenxuan/amagi
10
10
  ```
11
11
  ## 快速上手
12
12
  ```js
@@ -22,8 +22,8 @@ const client = await new amagi({
22
22
  await StartClient(client, { port: 4567 })
23
23
  ```
24
24
  ## 开发构建
25
- > Node.js版本约定:
26
- > v18.20.4 <= Node.js <= v22.x.x
25
+ > Node.js版本 <= v18.20.4
26
+
27
27
  * 克隆仓库
28
28
  ```
29
29
  git clone git@github.com:ikenxuan/amagi.git
@@ -37,6 +37,9 @@ pnpm install
37
37
  pnpm build
38
38
  ```
39
39
 
40
+ ## License
41
+ [GPL-3.0](https://github.com/ikenxuan/amagi/blob/main/LICENSE)
42
+
40
43
  ## 声明
41
44
  该项目代码从 [kkkkkk-10086](https://github.com/ikenxuan/kkkkkk-10086) 提取修改并发布
42
45
 
@@ -6,22 +6,10 @@ export default class DouyinData {
6
6
  URL;
7
7
  constructor(type, cookie) {
8
8
  this.type = type;
9
- this.headers = {
10
- Accept: 'application/json, text/plain, */*',
11
- 'Accept-Encoding': 'gzip, deflate, br, zstd',
12
- 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
13
- Priority: 'u=1, i',
14
- 'Sec-Ch-Ua': '"Not/A)Brand";v="8", "Chromium";v="125", "Microsoft Edge";v="125"',
15
- 'Sec-Ch-Ua-Mobile': '?0',
16
- 'Sec-Ch-Ua-Platform': '"Windows"',
17
- 'Sec-Fetch-Dest': 'empty',
18
- 'Sec-Fetch-Mode': 'cors',
19
- 'Sec-Fetch-Site': 'same-site',
20
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
21
- 'Content-Type': 'application/json',
22
- Referer: 'https://www.douyin.com/?recommend=1',
23
- Cookie: cookie
24
- };
9
+ this.headers = {};
10
+ this.headers.Referer = 'https://www.douyin.com/';
11
+ this.headers.Cookie = cookie,
12
+ this.headers['Content-Type'] = 'application/json';
25
13
  }
26
14
  async GetData(data = {}) {
27
15
  switch (this.type) {
@@ -29,28 +17,29 @@ export default class DouyinData {
29
17
  case 'NoteData':
30
18
  this.URL = DouyinAPI.视频或图集({ aweme_id: data.aweme_id });
31
19
  const VideoData = await this.GlobalGetData({
32
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
20
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
21
+ method: 'GET',
33
22
  headers: this.headers,
34
23
  });
35
24
  return VideoData;
36
25
  case 'CommentData':
37
26
  this.URL = DouyinAPI.评论({ aweme_id: data.aweme_id });
38
27
  const CommentsData = await this.GlobalGetData({
39
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
28
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
40
29
  headers: this.headers,
41
30
  });
42
31
  return CommentsData;
43
32
  case 'CommentReplyData':
44
33
  this.URL = DouyinAPI.二级评论({ aweme_id: data.aweme_id, comment_id: data.comment_id });
45
34
  const CommentReplyData = await this.GlobalGetData({
46
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
35
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
47
36
  headers: this.headers,
48
37
  });
49
38
  return CommentReplyData;
50
39
  case 'UserInfoData':
51
40
  this.URL = DouyinAPI.用户主页信息({ sec_uid: data.sec_uid });
52
41
  const UserInfoData = await this.GlobalGetData({
53
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
42
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
54
43
  headers: {
55
44
  ...this.headers,
56
45
  Referer: `https://www.douyin.com/user/${data.sec_uid}`,
@@ -67,7 +56,7 @@ export default class DouyinData {
67
56
  case 'UserVideosListData':
68
57
  this.URL = DouyinAPI.用户主页视频({ sec_uid: data.sec_uid });
69
58
  const UserVideoListData = await this.GlobalGetData({
70
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
59
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
71
60
  headers: {
72
61
  ...this.headers,
73
62
  Referer: `https://www.douyin.com/user/${data.sec_uid}`,
@@ -77,7 +66,7 @@ export default class DouyinData {
77
66
  case 'SuggestWordsData':
78
67
  this.URL = DouyinAPI.热点词({ query: data.query });
79
68
  const SuggestWordsData = await this.GlobalGetData({
80
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
69
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
81
70
  headers: {
82
71
  ...this.headers,
83
72
  Referer: `https://www.douyin.com/search/${encodeURIComponent(String(data.query))}`,
@@ -87,7 +76,7 @@ export default class DouyinData {
87
76
  case 'SearchData':
88
77
  this.URL = DouyinAPI.搜索({ query: data.query });
89
78
  const SearchData = await this.GlobalGetData({
90
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
79
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
91
80
  headers: {
92
81
  ...this.headers,
93
82
  Referer: `https://www.douyin.com/https://www.douyin.com/search/${encodeURIComponent(String(data.query))}`,
@@ -97,14 +86,14 @@ export default class DouyinData {
97
86
  case 'ExpressionPlusData':
98
87
  this.URL = DouyinAPI.互动表情();
99
88
  const ExpressionPlusData = await this.GlobalGetData({
100
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
89
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
101
90
  headers: this.headers,
102
91
  });
103
92
  return ExpressionPlusData;
104
93
  case 'MusicData':
105
94
  this.URL = DouyinAPI.背景音乐({ music_id: data.music_id });
106
95
  const MusicData = await this.GlobalGetData({
107
- url: `${this.URL}&a_bougs=${Sign.AB(this.URL)}`,
96
+ url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
108
97
  headers: this.headers,
109
98
  });
110
99
  return MusicData;
@@ -0,0 +1,50 @@
1
+ export declare class ABogus {
2
+ filter: RegExp;
3
+ arguments: number[];
4
+ ua_key: string;
5
+ end_string: string;
6
+ version: number[];
7
+ browser: string;
8
+ reg: number[];
9
+ str: any;
10
+ chunk: number[];
11
+ size: number;
12
+ ua_code: number[];
13
+ browser_len: number;
14
+ browser_code: number[];
15
+ constructor(platform?: string | null);
16
+ list_1(random_num?: number | null, a?: number, b?: number, c?: number): number[];
17
+ list_2(random_num?: number | null, a?: number, b?: number): number[];
18
+ list_3(random_num?: number | null, a?: number, b?: number): number[];
19
+ random_list(a?: number | null, b?: number, c?: number, d?: number, e?: number, f?: number, g?: number): number[];
20
+ from_char_code(...args: number[]): string;
21
+ generate_string_1(random_num_1?: number | null, random_num_2?: number | null, random_num_3?: number | null): string;
22
+ generate_string_2(url_params: string, method?: string, start_time?: number, end_time?: number): string;
23
+ generate_string_2_list(url_params: string, method?: string, start_time?: number, end_time?: number): number[];
24
+ reg_to_array(a: number[]): number[];
25
+ compress(a: number[]): void;
26
+ generate_f(e: number[]): number[];
27
+ generate_params_code(url_params: string): number[];
28
+ generate_method_code(method: string): number[];
29
+ sm3ToArray(data: string | number[]): number[];
30
+ generate_params(url_params: string): string;
31
+ generate_method(method: string): string;
32
+ char_code_at(str: string): number[];
33
+ de(a: number, b: number): number;
34
+ pe(a: number): number;
35
+ ve(a: number, b: number, c: number, d: number): number;
36
+ he(a: number, b: number, c: number, d: number): number;
37
+ end_check_num(a: number[]): number;
38
+ tobase(a: number): string;
39
+ rc4_encrypt(a: string, b: string): string;
40
+ rc4_key_schedule(b: string): number[];
41
+ list_4(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number): number[];
42
+ generate_browser_info(platform: string): string;
43
+ getABogus(url: string, method: string, start_time: number, end_time: number): string;
44
+ get_reg(): string;
45
+ get_value(url_params?: string, method?: string, start_time?: number, end_time?: number, random_num_1?: number | null, random_num_2?: number | null, random_num_3?: number | null): string;
46
+ generateString(url_params: any, method: string, start_time: number, end_time: number): string;
47
+ generate_result(s: string, e?: string): string;
48
+ }
49
+ declare const _default: (url: string, ua: string) => string;
50
+ export default _default;
@@ -0,0 +1,283 @@
1
+ import { parse, URLSearchParams } from 'url';
2
+ import { sm3 } from 'sm-crypto-v2';
3
+ export class ABogus {
4
+ filter = /%([0-9A-F]{2})/g;
5
+ arguments = [0, 1, 14];
6
+ ua_key = "\u0000\u0001\u000e";
7
+ end_string = "cus";
8
+ version = [1, 0, 1, 5];
9
+ browser = "1536|742|1536|864|0|0|0|0|1536|864|1536|864|1536|742|24|24|MacIntel";
10
+ reg = [
11
+ 1937774191,
12
+ 1226093241,
13
+ 388252375,
14
+ 3666478592,
15
+ 2842636476,
16
+ 372324522,
17
+ 3817729613,
18
+ 2969243214,
19
+ ];
20
+ str = {
21
+ "s0": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
22
+ "s1": "Dkdpgh4ZKsQB80/Mfvw36XI1R25+WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=",
23
+ "s2": "Dkdpgh4ZKsQB80/Mfvw36XI1R25-WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=",
24
+ "s3": "ckdp1h4ZKsUB80/Mfvw36XIgR25+WQAlEi7NLboqYTOPuzmFjJnryx9HVGDaStCe",
25
+ "s4": "Dkdpgh2ZmsQB80/MfvV36XI1R45-WUAlEixNLwoqYTOPuzKFjJnry79HbGcaStCe",
26
+ };
27
+ chunk = [];
28
+ size = 0;
29
+ ua_code = [
30
+ 76, 98, 15, 131, 97, 245, 224, 133, 122, 199, 241, 166, 79, 34, 90, 191,
31
+ 128, 126, 122, 98, 66, 11, 14, 40, 49, 110, 110, 173, 67, 96, 138, 252
32
+ ];
33
+ browser_len;
34
+ browser_code;
35
+ constructor(platform = null) {
36
+ this.browser = platform ? this.generate_browser_info(platform) : this.browser;
37
+ this.browser_len = this.browser.length;
38
+ this.browser_code = this.char_code_at(this.browser);
39
+ }
40
+ list_1(random_num = null, a = 170, b = 85, c = 45) {
41
+ return this.random_list(random_num, a, b, 1, 2, 5, c & a);
42
+ }
43
+ list_2(random_num = null, a = 170, b = 85) {
44
+ return this.random_list(random_num, a, b, 1, 0, 0, 0);
45
+ }
46
+ list_3(random_num = null, a = 170, b = 85) {
47
+ return this.random_list(random_num, a, b, 1, 0, 5, 0);
48
+ }
49
+ random_list(a = null, b = 170, c = 85, d = 0, e = 0, f = 0, g = 0) {
50
+ const r = a || (Math.random() * 10000);
51
+ const v = [
52
+ r,
53
+ r & 255,
54
+ r >> 8
55
+ ];
56
+ let s = v[1] & b | d;
57
+ v.push(s);
58
+ s = v[1] & c | e;
59
+ v.push(s);
60
+ s = v[2] & b | f;
61
+ v.push(s);
62
+ s = v[2] & c | g;
63
+ v.push(s);
64
+ return v.slice(-4);
65
+ }
66
+ from_char_code(...args) {
67
+ return String.fromCharCode(...args);
68
+ }
69
+ generate_string_1(random_num_1 = null, random_num_2 = null, random_num_3 = null) {
70
+ return this.from_char_code(...this.list_1(random_num_1)) +
71
+ this.from_char_code(...this.list_2(random_num_2)) +
72
+ this.from_char_code(...this.list_3(random_num_3));
73
+ }
74
+ generate_string_2(url_params, method = "GET", start_time = 0, end_time = 0) {
75
+ const a = this.generate_string_2_list(url_params, method, start_time, end_time);
76
+ const e = this.end_check_num(a);
77
+ a.push(...this.browser_code, e);
78
+ return this.rc4_encrypt(this.from_char_code(...a), "y");
79
+ }
80
+ generate_string_2_list(url_params, method = "GET", start_time = 0, end_time = 0) {
81
+ start_time = start_time || Math.floor(Date.now());
82
+ end_time = end_time || (start_time + Math.floor(Math.random() * (8 - 4 + 1)) + 4);
83
+ const params_array = this.generate_params_code(url_params);
84
+ const method_array = this.generate_method_code(method);
85
+ return this.list_4((end_time >> 24) & 255, params_array[21], this.ua_code[23], (end_time >> 16) & 255, params_array[22], this.ua_code[24], (end_time >> 8) & 255, (end_time >> 0) & 255, (start_time >> 24) & 255, (start_time >> 16) & 255, (start_time >> 8) & 255, (start_time >> 0) & 255, method_array[21], method_array[22], Math.floor(end_time / 256 / 256 / 256 / 256) >> 0, Math.floor(start_time / 256 / 256 / 256 / 256) >> 0, this.browser_len);
86
+ }
87
+ reg_to_array(a) {
88
+ const o = new Array(32).fill(0);
89
+ for (let i = 0; i < 8; i++) {
90
+ let c = a[i];
91
+ o[4 * i + 3] = (255 & c);
92
+ c >>= 8;
93
+ o[4 * i + 2] = (255 & c);
94
+ c >>= 8;
95
+ o[4 * i + 1] = (255 & c);
96
+ c >>= 8;
97
+ o[4 * i] = (255 & c);
98
+ }
99
+ return o;
100
+ }
101
+ compress(a) {
102
+ const f = this.generate_f(a);
103
+ const i = [...this.reg];
104
+ for (let o = 0; o < 64; o++) {
105
+ let c = this.de(i[0], 12) + i[4] + this.de(this.pe(o), o);
106
+ c = (c & 0xFFFFFFFF);
107
+ c = this.de(c, 7);
108
+ const s = (c ^ this.de(i[0], 12)) & 0xFFFFFFFF;
109
+ let u = this.he(o, i[0], i[1], i[2]);
110
+ u = (u + i[3] + s + f[o + 68]) & 0xFFFFFFFF;
111
+ let b = this.ve(o, i[4], i[5], i[6]);
112
+ b = (b + i[7] + c + f[o]) & 0xFFFFFFFF;
113
+ i[3] = i[2];
114
+ i[2] = this.de(i[1], 9);
115
+ i[1] = i[0];
116
+ i[0] = u;
117
+ i[7] = i[6];
118
+ i[6] = this.de(i[5], 19);
119
+ i[5] = i[4];
120
+ i[4] = (b ^ this.de(b, 9) ^ this.de(b, 17)) & 0xFFFFFFFF;
121
+ }
122
+ for (let l = 0; l < 8; l++) {
123
+ this.reg[l] = (this.reg[l] ^ i[l]) & 0xFFFFFFFF;
124
+ }
125
+ }
126
+ generate_f(e) {
127
+ const r = new Array(132).fill(0);
128
+ for (let t = 0; t < 16; t++) {
129
+ r[t] = (255 & e[4 * t]) | (e[4 * t + 1] << 8) | (e[4 * t + 2] << 16) | (e[4 * t + 3] << 24);
130
+ }
131
+ for (let n = 16; n < 68; n++) {
132
+ const u = r[n - 3] ^ r[n - 13] ^ this.de(r[n - 16], 15);
133
+ const c = this.de(u, 17) ^ this.de(u, 9) ^ u;
134
+ r[n] = c ^ r[n - 6];
135
+ }
136
+ for (let i = 0; i < 64; i++) {
137
+ r[68 + i] = r[i] ^ r[i + 4];
138
+ }
139
+ return r;
140
+ }
141
+ generate_params_code(url_params) {
142
+ // console.log('generate_params_code', this.sm3ToArray(this.sm3ToArray(url_params + this.end_string)))
143
+ return this.sm3ToArray(this.sm3ToArray(url_params + this.end_string));
144
+ }
145
+ generate_method_code(method) {
146
+ return this.sm3ToArray(this.sm3ToArray(method + this.end_string));
147
+ }
148
+ sm3ToArray(data) {
149
+ let byteArray;
150
+ if (typeof data === 'string') {
151
+ byteArray = new TextEncoder().encode(data);
152
+ }
153
+ else {
154
+ byteArray = new Uint8Array(data);
155
+ }
156
+ // console.log(byteArray)
157
+ const hashHex = sm3(byteArray);
158
+ // console.log('sm3:', hashHex)
159
+ const result = [];
160
+ for (let i = 0; i < hashHex.length; i += 2) {
161
+ result.push(parseInt(hashHex.substr(i, 2), 16));
162
+ }
163
+ return result;
164
+ }
165
+ generate_params(url_params) {
166
+ return url_params.split("").map(c => c.charCodeAt(0) % 255).map(this.tobase).join("");
167
+ }
168
+ generate_method(method) {
169
+ return method.split("").map(c => c.charCodeAt(0) % 255).map(this.tobase).join("");
170
+ }
171
+ char_code_at(str) {
172
+ return str.split("").map(c => c.charCodeAt(0));
173
+ }
174
+ de(a, b) {
175
+ return (a << b) | (a >>> (32 - b));
176
+ }
177
+ pe(a) {
178
+ const t = this.arguments[a & 3];
179
+ return (t << 5) | t;
180
+ }
181
+ ve(a, b, c, d) {
182
+ return (a & b) | (~a & c);
183
+ }
184
+ he(a, b, c, d) {
185
+ return b ^ c ^ d;
186
+ }
187
+ end_check_num(a) {
188
+ const r = (this.chunk.length << 3) & 255;
189
+ const n = ((this.size >> 29) & 255) | ((this.size & 255) << 8);
190
+ return (a[0] ^ a[1] ^ a[2] ^ a[3] ^ a[4] ^ a[5] ^ a[6] ^ a[7] ^ r ^ n) & 255;
191
+ }
192
+ tobase(a) {
193
+ return ABogus.prototype.from_char_code.call(this, 0, 0, 0, a);
194
+ }
195
+ rc4_encrypt(a, b) {
196
+ let c = this.rc4_key_schedule(b);
197
+ let e = "";
198
+ for (let f = 0; f < a.length; f++) {
199
+ const g = a.charCodeAt(f);
200
+ e += String.fromCharCode(g ^ c[f & 255]);
201
+ }
202
+ return e;
203
+ }
204
+ rc4_key_schedule(b) {
205
+ const c = new Array(256);
206
+ const d = new Array(256);
207
+ for (let i = 0; i < 256; i++) {
208
+ c[i] = b.charCodeAt(i % b.length);
209
+ d[i] = i;
210
+ }
211
+ let j = 0;
212
+ for (let i = 0; i < 256; i++) {
213
+ j = (j + d[i] + c[i]) % 256;
214
+ [d[i], d[j]] = [d[j], d[i]];
215
+ }
216
+ return d;
217
+ }
218
+ list_4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) {
219
+ return [
220
+ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q,
221
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
222
+ ];
223
+ }
224
+ generate_browser_info(platform) {
225
+ const ua = platform || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0";
226
+ const browser_info = ua.split("").map(c => (c.charCodeAt(0) % 255)).map(this.tobase).join("");
227
+ return browser_info;
228
+ }
229
+ getABogus(url, method, start_time, end_time) {
230
+ const url_params = parse(url, true).search || "";
231
+ return this.generate_string_2(url_params, method, start_time, end_time);
232
+ }
233
+ get_reg() {
234
+ return this.rc4_encrypt(this.from_char_code(...this.reg_to_array(this.reg)), "x");
235
+ }
236
+ get_value(url_params = '', method = "GET", start_time = 0, end_time = 0, random_num_1, random_num_2, random_num_3) {
237
+ const string_1 = this.generate_string_1(random_num_1, random_num_2, random_num_3);
238
+ // console.log(string_1)
239
+ const string_2 = this.generateString((new URLSearchParams((new URL(url_params)).search)).toString(), method, start_time, end_time);
240
+ const string = string_1 + string_2;
241
+ // console.log(string)
242
+ return this.generate_result(string, 's4');
243
+ }
244
+ generateString(url_params, method, start_time, end_time) {
245
+ let string_2;
246
+ // console.log(new URLSearchParams(url_params).toString())
247
+ if (typeof url_params === 'object' && !Array.isArray(url_params) && url_params !== null) {
248
+ // 如果url_params是一个对象(字典),则使用URLSearchParams来编码它
249
+ string_2 = this.generate_string_2((new URLSearchParams((new URL(url_params)).search)).toString(), method, start_time, end_time);
250
+ }
251
+ else {
252
+ // 否则,假设url_params已经是编码后的字符串或可以直接使用的值
253
+ string_2 = this.generate_string_2(url_params.toString(), method, start_time, end_time);
254
+ }
255
+ return string_2;
256
+ }
257
+ generate_result(s, e = "s4") {
258
+ const r = [];
259
+ for (let i = 0; i < s.length; i += 3) {
260
+ let n;
261
+ if (i + 2 < s.length) {
262
+ n = (s.charCodeAt(i) << 16) | (s.charCodeAt(i + 1) << 8) | s.charCodeAt(i + 2);
263
+ }
264
+ else if (i + 1 < s.length) {
265
+ n = (s.charCodeAt(i) << 16) | (s.charCodeAt(i + 1) << 8);
266
+ }
267
+ else {
268
+ n = s.charCodeAt(i) << 16;
269
+ }
270
+ for (let j = 18, k = [0xFC0000, 0x03F000, 0x0FC0, 0x3F]; j >= 0; j -= 6) {
271
+ if ((j === 6 && i + 1 >= s.length) || (j === 0 && i + 2 >= s.length)) {
272
+ break;
273
+ }
274
+ r.push(this.str[e][(n & k[(18 - j) / 6]) >> j]);
275
+ }
276
+ }
277
+ r.push("=".repeat((4 - (r.length % 4)) % 4));
278
+ return r.join("");
279
+ }
280
+ }
281
+ export default (url, ua) => {
282
+ return encodeURIComponent(new ABogus(ua).get_value(url));
283
+ };
@@ -1,7 +1,7 @@
1
1
  export default class sign {
2
2
  /** 生成一个指定长度的随机字符串 */
3
3
  static Mstoken(length: number): string;
4
- /** a_bougs 签名算法 */
4
+ /** a_bogus 签名算法 */
5
5
  static AB(url: string): string;
6
6
  /** 生成一个唯一的验证字符串 */
7
7
  static VerifyFpManager(): string;
@@ -1,5 +1,4 @@
1
- // @ts-ignore
2
- import { signature } from './a_bougs.js';
1
+ import a_bogus from './a_bogus.js';
3
2
  import crypto from 'crypto';
4
3
  const headers = {
5
4
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
@@ -11,9 +10,9 @@ export default class sign {
11
10
  const randomBytes = crypto.randomBytes(length);
12
11
  return Array.from(randomBytes, (byte) => characters[byte % characters.length]).join('');
13
12
  }
14
- /** a_bougs 签名算法 */
13
+ /** a_bogus 签名算法 */
15
14
  static AB(url) {
16
- return signature(new URLSearchParams(new URL(url).search).toString(), headers['User-Agent']);
15
+ return a_bogus(url, headers['User-Agent']);
17
16
  }
18
17
  /** 生成一个唯一的验证字符串 */
19
18
  static VerifyFpManager() {
@@ -44,7 +44,7 @@ type QrcodeParams = {
44
44
  /** 扫码登录秘钥 */
45
45
  qrcode_key: string;
46
46
  };
47
- /** 抖音API接口参数类型 */
47
+ /** B站API接口参数类型 */
48
48
  export type BilibiliAPIParams = {
49
49
  VideoInfoParams: VideoInfoParams;
50
50
  VideoStreamParams: VideoStreamParams;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ikenxuan/amagi",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "homepage": "https://github.com/ikenxuan/amagi",
8
8
  "scripts": {
9
9
  "dev": "tsx lib/dev.js",
10
- "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && node src/cp.js"
10
+ "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json"
11
11
  },
12
12
  "files": [
13
13
  "/lib/**/*.js",
@@ -38,7 +38,8 @@
38
38
  "loglevel": "^1.9.1",
39
39
  "loglevel-plugin-prefix": "^0.8.4",
40
40
  "md5": "^2.3.0",
41
- "node-fetch": "^3.3.2"
41
+ "node-fetch": "^3.3.2",
42
+ "sm-crypto-v2": "^1.9.1"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@types/lodash": "latest",
@@ -1,3 +0,0 @@
1
- declare module 'a_bougs' {
2
- function signature(): void;
3
- }
@@ -1,487 +0,0 @@
1
- // All the content in this article is only for learning and communication use, not for any other purpose, strictly prohibited for commercial use and illegal use, otherwise all the consequences are irrelevant to the author!
2
- function rc4_encrypt (plaintext, key) {
3
- const s = []
4
- for (var i = 0; i < 256; i++) {
5
- s[i] = i
6
- }
7
- var j = 0
8
- for (var i = 0; i < 256; i++) {
9
- j = (j + s[i] + key.charCodeAt(i % key.length)) % 256
10
- var temp = s[i]
11
- s[i] = s[j]
12
- s[j] = temp
13
- }
14
-
15
- var i = 0
16
- var j = 0
17
- const cipher = []
18
- for (let k = 0; k < plaintext.length; k++) {
19
- i = (i + 1) % 256
20
- j = (j + s[i]) % 256
21
- var temp = s[i]
22
- s[i] = s[j]
23
- s[j] = temp
24
- const t = (s[i] + s[j]) % 256
25
- cipher.push(String.fromCharCode(s[t] ^ plaintext.charCodeAt(k)))
26
- }
27
- return cipher.join('')
28
- }
29
-
30
- function le (e, r) {
31
- return ((e << (r %= 32)) | (e >>> (32 - r))) >>> 0
32
- }
33
-
34
- function de (e) {
35
- return e >= 0 && e < 16 ? 2043430169 : e >= 16 && e < 64 ? 2055708042 : void console.error('invalid j for constant Tj')
36
- }
37
-
38
- function pe (e, r, t, n) {
39
- return e >= 0 && e < 16
40
- ? (r ^ t ^ n) >>> 0
41
- : e >= 16 && e < 64
42
- ? ((r & t) | (r & n) | (t & n)) >>> 0
43
- : (console.error('invalid j for bool function FF'), 0)
44
- }
45
-
46
- function he (e, r, t, n) {
47
- return e >= 0 && e < 16 ? (r ^ t ^ n) >>> 0 : e >= 16 && e < 64 ? ((r & t) | (~r & n)) >>> 0 : (console.error('invalid j for bool function GG'), 0)
48
- }
49
-
50
- function reset () {
51
- (this.reg[0] = 1937774191),
52
- (this.reg[1] = 1226093241),
53
- (this.reg[2] = 388252375),
54
- (this.reg[3] = 3666478592),
55
- (this.reg[4] = 2842636476),
56
- (this.reg[5] = 372324522),
57
- (this.reg[6] = 3817729613),
58
- (this.reg[7] = 2969243214),
59
- (this.chunk = []),
60
- (this.size = 0)
61
- }
62
-
63
- function write (e) {
64
- let n
65
- var a =
66
- typeof e == 'string'
67
- ? (function (e) {
68
- ; (n = encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, function (e, r) {
69
- return String.fromCharCode('0x' + r)
70
- })),
71
- (a = new Array(n.length))
72
- return (
73
- Array.prototype.forEach.call(n, function (e, r) {
74
- a[r] = e.charCodeAt(0)
75
- }),
76
- a
77
- )
78
- })(e)
79
- : e
80
- this.size += a.length
81
- let f = 64 - this.chunk.length
82
- if (a.length < f) this.chunk = this.chunk.concat(a)
83
- else {
84
- for (this.chunk = this.chunk.concat(a.slice(0, f)); this.chunk.length >= 64;) { this._compress(this.chunk), f < a.length ? (this.chunk = a.slice(f, Math.min(f + 64, a.length))) : (this.chunk = []), (f += 64) }
85
- }
86
- }
87
-
88
- function sum (e, t) {
89
- e && (this.reset(), this.write(e)), this._fill()
90
- for (var f = 0; f < this.chunk.length; f += 64) this._compress(this.chunk.slice(f, f + 64))
91
- let i = null
92
- if (t == 'hex') {
93
- i = ''
94
- for (f = 0; f < 8; f++) i += se(this.reg[f].toString(16), 8, '0')
95
- } else {
96
- for (i = new Array(32), f = 0; f < 8; f++) {
97
- let c = this.reg[f]
98
- ; (i[4 * f + 3] = (255 & c) >>> 0),
99
- (c >>>= 8),
100
- (i[4 * f + 2] = (255 & c) >>> 0),
101
- (c >>>= 8),
102
- (i[4 * f + 1] = (255 & c) >>> 0),
103
- (c >>>= 8),
104
- (i[4 * f] = (255 & c) >>> 0)
105
- }
106
- }
107
- return this.reset(), i
108
- }
109
-
110
- function _compress (t) {
111
- if (t < 64) console.error('compress error: not enough data')
112
- else {
113
- for (
114
- var f = (function (e) {
115
- for (var r = new Array(132), t = 0; t < 16; t++) { (r[t] = e[4 * t] << 24), (r[t] |= e[4 * t + 1] << 16), (r[t] |= e[4 * t + 2] << 8), (r[t] |= e[4 * t + 3]), (r[t] >>>= 0) }
116
- for (var n = 16; n < 68; n++) {
117
- let a = r[n - 16] ^ r[n - 9] ^ le(r[n - 3], 15)
118
- ; (a = a ^ le(a, 15) ^ le(a, 23)), (r[n] = (a ^ le(r[n - 13], 7) ^ r[n - 6]) >>> 0)
119
- }
120
- for (n = 0; n < 64; n++) r[n + 68] = (r[n] ^ r[n + 4]) >>> 0
121
- return r
122
- })(t),
123
- i = this.reg.slice(0),
124
- c = 0;
125
- c < 64;
126
- c++
127
- ) {
128
- let o = le(i[0], 12) + i[4] + le(de(c), c)
129
- const s = ((o = le((o = (4294967295 & o) >>> 0), 7)) ^ le(i[0], 12)) >>> 0
130
- let u = pe(c, i[0], i[1], i[2])
131
- u = (4294967295 & (u = u + i[3] + s + f[c + 68])) >>> 0
132
- let b = he(c, i[4], i[5], i[6])
133
- ; (b = (4294967295 & (b = b + i[7] + o + f[c])) >>> 0),
134
- (i[3] = i[2]),
135
- (i[2] = le(i[1], 9)),
136
- (i[1] = i[0]),
137
- (i[0] = u),
138
- (i[7] = i[6]),
139
- (i[6] = le(i[5], 19)),
140
- (i[5] = i[4]),
141
- (i[4] = (b ^ le(b, 9) ^ le(b, 17)) >>> 0)
142
- }
143
- for (let l = 0; l < 8; l++) this.reg[l] = (this.reg[l] ^ i[l]) >>> 0
144
- }
145
- }
146
-
147
- function _fill () {
148
- const a = 8 * this.size
149
- let f = this.chunk.push(128) % 64
150
- for (64 - f < 8 && (f -= 64); f < 56; f++) this.chunk.push(0)
151
- for (var i = 0; i < 4; i++) {
152
- const c = Math.floor(a / 4294967296)
153
- this.chunk.push((c >>> (8 * (3 - i))) & 255)
154
- }
155
- for (i = 0; i < 4; i++) this.chunk.push((a >>> (8 * (3 - i))) & 255)
156
- }
157
-
158
- function SM3 () {
159
- this.reg = []
160
- this.chunk = []
161
- this.size = 0
162
- this.reset()
163
- }
164
- SM3.prototype.reset = reset
165
- SM3.prototype.write = write
166
- SM3.prototype.sum = sum
167
- SM3.prototype._compress = _compress
168
- SM3.prototype._fill = _fill
169
-
170
- function result_encrypt (long_str, num = null) {
171
- const s_obj = {
172
- s0: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
173
- s1: 'Dkdpgh4ZKsQB80/Mfvw36XI1R25+WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=',
174
- s2: 'Dkdpgh4ZKsQB80/Mfvw36XI1R25-WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=',
175
- s3: 'ckdp1h4ZKsUB80/Mfvw36XIgR25+WQAlEi7NLboqYTOPuzmFjJnryx9HVGDaStCe',
176
- s4: 'Dkdpgh2ZmsQB80/MfvV36XI1R45-WUAlEixNLwoqYTOPuzKFjJnry79HbGcaStCe'
177
- }
178
- const constant = {
179
- 0: 16515072,
180
- 1: 258048,
181
- 2: 4032,
182
- str: s_obj[num]
183
- }
184
-
185
- let result = ''
186
- let lound = 0
187
- let long_int = get_long_int(lound, long_str)
188
- for (let i = 0; i < (long_str.length / 3) * 4; i++) {
189
- if (Math.floor(i / 4) !== lound) {
190
- lound += 1
191
- long_int = get_long_int(lound, long_str)
192
- }
193
- const key = i % 4
194
- let temp_int
195
- switch (key) {
196
- case 0:
197
- temp_int = (long_int & constant['0']) >> 18
198
- result += constant.str.charAt(temp_int)
199
- break
200
- case 1:
201
- temp_int = (long_int & constant['1']) >> 12
202
- result += constant.str.charAt(temp_int)
203
- break
204
- case 2:
205
- temp_int = (long_int & constant['2']) >> 6
206
- result += constant.str.charAt(temp_int)
207
- break
208
- case 3:
209
- temp_int = long_int & 63
210
- result += constant.str.charAt(temp_int)
211
- break
212
- default:
213
- break
214
- }
215
- }
216
- return result
217
- }
218
-
219
- function get_long_int (round, long_str) {
220
- round = round * 3
221
- return (long_str.charCodeAt(round) << 16) | (long_str.charCodeAt(round + 1) << 8) | long_str.charCodeAt(round + 2)
222
- }
223
-
224
- function gener_random (random, option) {
225
- return [
226
- (random & 255 & 170) | (option[0] & 85), // 163
227
- (random & 255 & 85) | (option[0] & 170), // 87
228
- ((random >> 8) & 255 & 170) | (option[1] & 85), // 37
229
- ((random >> 8) & 255 & 85) | (option[1] & 170) // 41
230
- ]
231
- }
232
-
233
- /// ///////////////////////////////////////////
234
- function generate_rc4_bb_str (url_search_params, user_agent, window_env_str, suffix = 'cus', Arguments = [0, 1, 14]) {
235
- const sm3 = new SM3()
236
- const start_time = Date.now()
237
- /**
238
- * 进行3次加密处理
239
- * 1: url_search_params两次sm3之的结果
240
- * 2: 对后缀两次sm3之的结果
241
- * 3: 对ua处理之后的结果
242
- */
243
- // url_search_params两次sm3之的结果
244
- const url_search_params_list = sm3.sum(sm3.sum(url_search_params + suffix))
245
- // 对后缀两次sm3之的结果
246
- const cus = sm3.sum(sm3.sum(suffix))
247
- // 对ua处理之后的结果
248
- const ua = sm3.sum(result_encrypt(rc4_encrypt(user_agent, String.fromCharCode.apply(null, [0.00390625, 1, 14])), 's3'))
249
- //
250
- const end_time = Date.now()
251
- // b
252
- const b = {
253
- 8: 3, // 固定
254
- 10: end_time, // 3次加密结束时间
255
- 15: {
256
- aid: 6383,
257
- pageId: 6241,
258
- boe: false,
259
- ddrt: 7,
260
- paths: {
261
- include: [{}, {}, {}, {}, {}, {}, {}],
262
- exclude: []
263
- },
264
- track: {
265
- mode: 0,
266
- delay: 300,
267
- paths: []
268
- },
269
- dump: true,
270
- rpU: ''
271
- },
272
- 16: start_time, // 3次加密开始时间
273
- 18: 44, // 固定
274
- 19: [1, 0, 1, 5]
275
- }
276
-
277
- // 3次加密开始时间
278
- b[20] = (b[16] >> 24) & 255
279
- b[21] = (b[16] >> 16) & 255
280
- b[22] = (b[16] >> 8) & 255
281
- b[23] = b[16] & 255
282
- b[24] = (b[16] / 256 / 256 / 256 / 256) >> 0
283
- b[25] = (b[16] / 256 / 256 / 256 / 256 / 256) >> 0
284
-
285
- // 参数Arguments [0, 1, 14, ...]
286
- // let Arguments = [0, 1, 14]
287
- b[26] = (Arguments[0] >> 24) & 255
288
- b[27] = (Arguments[0] >> 16) & 255
289
- b[28] = (Arguments[0] >> 8) & 255
290
- b[29] = Arguments[0] & 255
291
-
292
- b[30] = (Arguments[1] / 256) & 255
293
- b[31] = Arguments[1] % 256 & 255
294
- b[32] = (Arguments[1] >> 24) & 255
295
- b[33] = (Arguments[1] >> 16) & 255
296
-
297
- b[34] = (Arguments[2] >> 24) & 255
298
- b[35] = (Arguments[2] >> 16) & 255
299
- b[36] = (Arguments[2] >> 8) & 255
300
- b[37] = Arguments[2] & 255
301
-
302
- // (url_search_params + "cus") 两次sm3之的结果
303
- /** let url_search_params_list = [
304
- 91, 186, 35, 86, 143, 253, 6, 76,
305
- 34, 21, 167, 148, 7, 42, 192, 219,
306
- 188, 20, 182, 85, 213, 74, 213, 147,
307
- 37, 155, 93, 139, 85, 118, 228, 213
308
- ] */
309
- b[38] = url_search_params_list[21]
310
- b[39] = url_search_params_list[22]
311
-
312
- // ("cus") 对后缀两次sm3之的结果
313
- /**
314
- * let cus = [
315
- 136, 101, 114, 147, 58, 77, 207, 201,
316
- 215, 162, 154, 93, 248, 13, 142, 160,
317
- 105, 73, 215, 241, 83, 58, 51, 43,
318
- 255, 38, 168, 141, 216, 194, 35, 236
319
- ] */
320
- b[40] = cus[21]
321
- b[41] = cus[22]
322
-
323
- // 对ua处理之后的结果
324
- /**
325
- * let ua = [
326
- 129, 190, 70, 186, 86, 196, 199, 53,
327
- 99, 38, 29, 209, 243, 17, 157, 69,
328
- 147, 104, 53, 23, 114, 126, 66, 228,
329
- 135, 30, 168, 185, 109, 156, 251, 88
330
- ] */
331
- b[42] = ua[23]
332
- b[43] = ua[24]
333
-
334
- // 3次加密结束时间
335
- b[44] = (b[10] >> 24) & 255
336
- b[45] = (b[10] >> 16) & 255
337
- b[46] = (b[10] >> 8) & 255
338
- b[47] = b[10] & 255
339
- b[48] = b[8]
340
- b[49] = (b[10] / 256 / 256 / 256 / 256) >> 0
341
- b[50] = (b[10] / 256 / 256 / 256 / 256 / 256) >> 0
342
-
343
- // object配置项
344
- b[51] = b[15].pageId
345
- b[52] = (b[15].pageId >> 24) & 255
346
- b[53] = (b[15].pageId >> 16) & 255
347
- b[54] = (b[15].pageId >> 8) & 255
348
- b[55] = b[15].pageId & 255
349
-
350
- b[56] = b[15].aid
351
- b[57] = b[15].aid & 255
352
- b[58] = (b[15].aid >> 8) & 255
353
- b[59] = (b[15].aid >> 16) & 255
354
- b[60] = (b[15].aid >> 24) & 255
355
-
356
- // 中间进行了环境检测
357
- // 代码索引: 2496 索引值: 17 (索引64关键条件)
358
- // '1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32'.charCodeAt()得到65位数组
359
- /**
360
- * let window_env_list = [49, 53, 51, 54, 124, 55, 52, 55, 124, 49, 53, 51, 54, 124, 56, 51, 52, 124, 48, 124, 51,
361
- * 48, 124, 48, 124, 48, 124, 49, 53, 51, 54, 124, 56, 51, 52, 124, 49, 53, 51, 54, 124, 56,
362
- * 54, 52, 124, 49, 53, 50, 53, 124, 55, 52, 55, 124, 50, 52, 124, 50, 52, 124, 87, 105, 110,
363
- * 51, 50]
364
- */
365
- const window_env_list = []
366
- for (let index = 0; index < window_env_str.length; index++) {
367
- window_env_list.push(window_env_str.charCodeAt(index))
368
- }
369
- b[64] = window_env_list.length
370
- b[65] = b[64] & 255
371
- b[66] = (b[64] >> 8) & 255
372
-
373
- b[69] = [].length
374
- b[70] = b[69] & 255
375
- b[71] = (b[69] >> 8) & 255
376
-
377
- b[72] =
378
- b[18] ^
379
- b[20] ^
380
- b[26] ^
381
- b[30] ^
382
- b[38] ^
383
- b[40] ^
384
- b[42] ^
385
- b[21] ^
386
- b[27] ^
387
- b[31] ^
388
- b[35] ^
389
- b[39] ^
390
- b[41] ^
391
- b[43] ^
392
- b[22] ^
393
- b[28] ^
394
- b[32] ^
395
- b[36] ^
396
- b[23] ^
397
- b[29] ^
398
- b[33] ^
399
- b[37] ^
400
- b[44] ^
401
- b[45] ^
402
- b[46] ^
403
- b[47] ^
404
- b[48] ^
405
- b[49] ^
406
- b[50] ^
407
- b[24] ^
408
- b[25] ^
409
- b[52] ^
410
- b[53] ^
411
- b[54] ^
412
- b[55] ^
413
- b[57] ^
414
- b[58] ^
415
- b[59] ^
416
- b[60] ^
417
- b[65] ^
418
- b[66] ^
419
- b[70] ^
420
- b[71]
421
- let bb = [
422
- b[18],
423
- b[20],
424
- b[52],
425
- b[26],
426
- b[30],
427
- b[34],
428
- b[58],
429
- b[38],
430
- b[40],
431
- b[53],
432
- b[42],
433
- b[21],
434
- b[27],
435
- b[54],
436
- b[55],
437
- b[31],
438
- b[35],
439
- b[57],
440
- b[39],
441
- b[41],
442
- b[43],
443
- b[22],
444
- b[28],
445
- b[32],
446
- b[60],
447
- b[36],
448
- b[23],
449
- b[29],
450
- b[33],
451
- b[37],
452
- b[44],
453
- b[45],
454
- b[59],
455
- b[46],
456
- b[47],
457
- b[48],
458
- b[49],
459
- b[50],
460
- b[24],
461
- b[25],
462
- b[65],
463
- b[66],
464
- b[70],
465
- b[71]
466
- ]
467
- bb = bb.concat(window_env_list).concat(b[72])
468
- return rc4_encrypt(String.fromCharCode.apply(null, bb), String.fromCharCode.apply(null, [121]))
469
- }
470
-
471
- function generate_random_str () {
472
- let random_str_list = []
473
- random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [3, 45]))
474
- random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [1, 0]))
475
- random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [1, 5]))
476
- return String.fromCharCode.apply(null, random_str_list)
477
- }
478
-
479
- export function signature (url_search_params, user_agent) {
480
- /**
481
- * url_search_params:"device_platform=webapp&aid=6383&channel=channel_pc_web&update_version_code=170400&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=123.0.0.0&browser_online=true&engine_name=Blink&engine_version=123.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7362810250930783783&msToken=VkDUvz1y24CppXSl80iFPr6ez-3FiizcwD7fI1OqBt6IICq9RWG7nCvxKb8IVi55mFd-wnqoNkXGnxHrikQb4PuKob5Q-YhDp5Um215JzlBszkUyiEvR"
482
- * user_agent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
483
- */
484
- const result_str =
485
- generate_random_str() + generate_rc4_bb_str(url_search_params, user_agent, '1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32')
486
- return result_encrypt(result_str, 's4') + '='
487
- }