This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
taikari.js
851 lines (698 loc) · 27 KB
/
taikari.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/**
* Taikari frida tool
* (C) TheSnowfield
*
* Usage: frida -U -f "moe.low.arc" --no-pause -l taikari.js
*/
const config = {
// hacktools
hackTools: [
{ name: 'captureSSL', enabled: false, func: hackCaptureSSL },
{ name: 'dumpCertficate', enabled: false, func: hackDumpCertificate },
{ name: 'hookOnlineManagerCtor', enabled: true, func: hackOnlineManagerCtor },
{ name: 'challengeHookTest', enabled: false, func: hackChallengeHookTest },
{ name: 'challengeServer', enabled: true, func: hackChallengeServer },
{ name: 'pretendArcVersion', enabled: false, func: hackPretendArcVersion },
{ name: 'pretendDeviceId', enabled: false, func: hackPretendDeviceId },
],
// folders
resFolder: {
'htdoc': '/system/usr/taikari/htdoc',
'library': '/system/usr/taikari/library'
},
// libraries
useNative: true,
useJLHttp: true,
// challenge server
challengeHttpPort: 23333,
// specific arcaea version
arcVersion: 'init',
// pretend
pretendDeviceId: 'ffffffffffffffff',
pretendArcVersion: '6.1.6c (Taikari)',
// pre-defined symbols
libSymbols: {
'3.11.2c_1019305_arm64-v8a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x111caf4 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x122996c }, // curl_easy_perform also calling this
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x11f273c },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x1537c18 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x125226c }
],
'3.11.2c_1019305_armeabi-v7a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xc19fbc },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xe5a664 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x9e2cbd },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0xc43af1 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0xd3beb1 }
],
'3.12.0c_1020007_armeabi-v7a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x41c264 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x3bca58 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x364971 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x3584c1 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x7b0009 }
],
'3.12.0c_1020007_arm64-v8a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xe112e4 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x6ff1e0 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0xbf1234 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x567064 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0xd463fc }
],
'3.12.1c_1020010_armeabi-v7a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x6a946c },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x6e3fa8 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x38a0c1 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x6fcf05 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x5F4CA9 }
],
'3.12.1c_1020010_arm64-v8a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xbc7dc4 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xe711b0 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0xc583dc },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x8080cc },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0xde3cc0 }
],
'3.12.2c_1020517_armeabi-v7a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x7e0bb8 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x5ee218 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x4153c5 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x60c9d5 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x5d9d9d }
],
'3.12.2c_1020517_arm64-v8a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x6e4564 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x765350 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x69a380 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x8ba05c },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0xbd898c }
],
'3.12.6c_1032000_arm64-v8a': [ // not working
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xa43f64 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xbf22a4 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0xd7a2b0 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0xcb1088 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0xacc900 }
],
'4.0.0c_1050010_armeabi-v7a' : [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x3f9008 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x411a60 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x4301c5 },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x31b7a1 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x786a8d }
],
'4.0.1c_1050014_armeabi-v7a': [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x80d24c },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x8263f4 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x3b7b6d },
{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x6234b1 },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x8853b9 }
],
'4.0.0c_1050010_arm64-v8a' : [//wip
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x788fbc },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xcb2768 },
//{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
],
'4.0.1c_1050014_arm64-v8a': [//wip
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xa15c48 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xcda784 },
//{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
],
'4.0.255c_1060002_armeabi-v7a' : [ // wip
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x3700b4 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x7c5e88 },
// { name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x4bd7e9 },
// { name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x75ffdd }
],
'4.0.255c_1060002_arm64-v8a': [//wip
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xb4f734 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x91166c },//
//{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
],
'4.0.256c_1070001_armeabi-v7a' : [ //untested
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x3b9ee4 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x623928 },
// { name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x86e601 }
],
'4.0.256c_1070001_arm64-v8a' : [ //wip
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0xc81d44 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0xb30a88 },
// { name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
],
'4.1.4c_1092003_armeabi-v7a' : [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc: 0x69af78 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x62caa4 },
// { name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
// { name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
], // idk just test lmao
'4.1.9c_1095000_armeabi-v7a' : [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc:0x962390 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x6f2094 },
{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: 0x79e198 },
// { name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: 0x64a170 },
// { name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: 0x79e198}
],
'4.3.2c_1098002_arm64-v8a' : [
{ name: 'libcocos2dcpp.so!curl_easy_setopt', proc:0x638ff8 },
{ name: 'libcocos2dcpp.so!easy_perform', proc: 0x83ee6c },
//{ name: 'libcocos2dcpp.so!OnlineManager::OnlineManager', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::sendHttpRequest', proc: },
//{ name: 'libcocos2dcpp.so!OnlineManager::setFavoriteCharacter', proc: }
],
}
};
// save original functions
const __console_log = console.log;
const __console_error = console.error;
console.log = (...msg) => __console_log(new Date().toLocaleString(), '[*]', msg);
console.error = (...msg) => __console_error(new Date().toLocaleString(), '[!]', msg);
console.info = (...msg) => __console_log(new Date().toLocaleString(), '[i]', msg);
console.raw = (...msg) => __console_log(msg);
// start when cocos_android_app_init reached
Interceptor.attach(Module.findExportByName('liblog.so', '__android_log_print'), {
onEnter: (args) => {
let _logstr = args[2].readUtf8String();
if (_logstr != 'cocos_android_app_init') return;
console.raw('');
// get version
config.arcVersion = getArcaeaVersion();
console.log(`current version is [${config.arcVersion}]`);
// is supported
if (!taiSupported()) {
console.log('sorry, taikari currently not supported this device or arcaea.');
return;
}
// load native helper
if (config.useNative) {
Module.load(`${resFolder('library')}/${Process.arch}/libtaikari.so`);
console.info('library \'libtaikari.so\' scuessfully loaded.');
}
// load compiled dex library
if (config.useJLHttp) {
Java.openClassFile(`${resFolder('library')}/jlhttp.dex`).load();
console.info('dex file \'jlhttp.dex\' scuessfully loaded.');
}
// apply hack tools where enabled
config.hackTools.forEach(tool => {
if (tool.enabled) {
tool.func();
console.info(`tool \'${tool.name}\' enabled.`);
}
});
}
});
////// Hack Tools
/////////////////////////////////////////////////////////
/**
* dump certificate
*/
function hackDumpCertificate() {
// hook curl_easy_setopt
console.log('attaching [libcocos2dcpp.so!curl_easy_setopt]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!curl_easy_setopt'), {
onEnter: (args) => {
// CURLOPT_SSLCERT_BLOB
if (args[1] == 0x9d63) {
let blob = args[2];
// Calc pointers
let cert = blob.readPointer();
let length = blob.add(Process.pointerSize).readULong();
let bytes = cert.readByteArray(length);
console.log('Certificate');
console.raw(hexdump(bytes));
}
// CURLOPT_KEYPASSWD
if (args[1] == 0x272a) {
console.log('Certificate Pwd');
console.log(args[2].readUtf8String());
return;
}
}
});
}
/**
* ssl traffic capturing
*/
function hackCaptureSSL() {
let _sslWrite = libSymbol('libcocos2dcpp.so!SSL_write');
let _sslWriteOld = new NativeFunction(_sslWrite, 'int', ['pointer', 'pointer', 'int']);
let counter = 1;
// traffic out
console.log('raplacing [libcocos2dcpp.so!SSL_write]');
Interceptor.replace(_sslWrite, new NativeCallback((ctx, buffer, length) => {
counter++;
// remove gzip compress feature
let replace = buffer.readUtf8String(length).replace('Accept-Encoding: deflate, gzip\r\n', '');
let newBuffer = Memory.allocUtf8String(replace);
// filter multiple calls
if (counter % 2 == 0) {
console.raw('\n====', new Date().toLocaleString(), '====');
console.raw(replace, '\n');
}
// write data to
return _sslWriteOld(ctx, newBuffer, replace.length);
}, 'int', ['pointer', 'pointer', 'int']));
// traffic in
console.log('attaching [libcocos2dcpp.so!SSL_read]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!SSL_read'), {
onEnter: (args) => {
this.buffer = ptr(args[1]);
},
onLeave: (ret) => {
let data = this.buffer.readUtf8String(ret.toInt32());
console.raw(data, '\n=================================');
}
});
}
/**
* pretend arcara version
*/
function hackPretendArcVersion() {
console.log('attaching [libcocos2dcpp.so!Java_low_moe_AppActivity_setAppVersion]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!Java_low_moe_AppActivity_setAppVersion'), {
onEnter: (args) => {
// replacing the argument
args[2] = jniNewStringUTF(args[0],
Memory.allocUtf8String(config.pretendArcVersion));
}
});
}
/**
* pretend arcaea device id
*/
function hackPretendDeviceId() {
console.log('attaching [libcocos2dcpp.so!Java_low_moe_AppActivity_setDeviceId]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!Java_low_moe_AppActivity_setDeviceId'), {
onEnter: (args) => {
// replacing the argument
args[2] = jniNewStringUTF(args[0],
Memory.allocUtf8String(config.pretendDeviceId));
}
});
}
/**
* hook online manager constructor
*/
function hackOnlineManagerCtor() {
console.log('attaching [libcocos2dcpp.so!OnlineManager::OnlineManager]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!OnlineManager::OnlineManager'), {
// save the pointer
onEnter: (args) => {
global.lpOnlineManager = args[0];
console.info(`lpOnlineManager = ${args[0]}`);
}
});
}
/**
* challenge hook test
*/
function hackChallengeHookTest() {
// assert native helper loaded
if (!config.useNative) {
console.error('challenge hook test requires libtaikari.so!');
console.error('please enable the \'useNative\'');
return;
}
// assert hookOnlineManagerCtor is enabled
if (!checkIfEnabled('hookOnlineManagerCtor')) {
console.error('please enable the \'hookOnlineManagerCtor\'!');
return;
}
// hook set favorite character
console.log('attaching [libcocos2dcpp.so!OnlineManager::setFavoriteCharacter]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!OnlineManager::setFavoriteCharacter'), {
onEnter: (args) => {
let _result = onlineManagerSendHttp(global.lpOnlineManager,
'https://arcapi-v2.lowiro.com/merikuri/17/lxnsnb');
console.log('test result:', _result);
}
});
}
/**
* challenge server
*/
function hackChallengeServer() {
// assert native helper loaded
if (!config.useNative) {
console.error('challenge server requires libtaikari.so!');
console.error('please enable the \'useNative\'');
return;
}
// assert http dex loaded
if (!config.useJLHttp) {
console.error('challenge server requires jlhttp.dex!');
console.error('please enable the \'useJLHttp\'');
return;
}
// assert challengeHook is not enabled
if (checkIfEnabled('challengeHook')) {
console.error('please disable the \'challengeHook\'!');
return;
}
// assert dumpCertficate is not enabled
if (checkIfEnabled('dumpCertficate')) {
console.error('please disable the \'dumpCertficate\'!');
return;
}
// assert hookOnlineManagerCtor is enabled
if (!checkIfEnabled('hookOnlineManagerCtor')) {
console.error('please enable the \'hookOnlineManagerCtor\'!');
return;
}
let _taskTable = {};
let _taskIndex = 0;
let _apiPrefix = ""; // https://arcapi-v2.lowiro.com/merikuri/17/
// replace easy_perform
console.log('replacing [libcocos2dcpp.so!easy_perform]');
Interceptor.replace(libSymbol('libcocos2dcpp.so!easy_perform'),
new NativeCallback((ctx, events) => {
// block the request
return 2; // CURLE_FAILED_INIT
}, 'int', ['pointer', 'int']));
// attach libcocos2dcpp.so!curl_easy_setopt
console.log('attach [libcocos2dcpp.so!curl_easy_setopt]');
Interceptor.attach(libSymbol('libcocos2dcpp.so!curl_easy_setopt'), {
onEnter: (args) => {
// CURLOPT_HTTPHEADER
if (args[1] == 0x2727) {
let _header = curlParseSlist(args[2]);
let _taskIndex = _header.find((header) => {
if (header.startsWith('Task'))
return true;
});
// task index
if (!_taskIndex) return;
_taskIndex = _taskIndex.substr(6).replace(/\s/, '');
let _challenge = _header.find((header) => {
if (header.startsWith('X-Random-Challenge'))
return true;
});
// challenge string
_challenge = _challenge.substr(20).replace(/\s/, '');
// return challenge
_taskTable[_taskIndex].resolve(_challenge);
return;
}
// CURLOPT_URL
if (args[1] == 0x2712) {
if (!_apiPrefix) {
let _urlstr = args[2].readUtf8String();
// match the result
let _match = _urlstr.match(/https:\/\/(\S.*?\/){3}/);
if (_match.length != 2) {
console.error(`error while detecting, preberly an invalid url. ${_urlstr}`);
return;
}
// set the result
_apiPrefix = _match[0];
console.log(`arcapi detected. ${_apiPrefix}`);
}
return;
}
}
});
// the online manager has not been
// constructed now, thus wait for 2s.
setTimeout(() => {
// arcapi prefix automatic detection
console.info('auto detecting arcapi...');
onlineManagerSetFavChar(global.lpOnlineManager, 1);
}, 2000);
// start the server
Java.perform(() => {
function createHttpServer(port, routes) {
let _httpServer = Java.use('net.freeutils.httpserver.HTTPServer');
let _contextHandler = Java.use('net.freeutils.httpserver.HTTPServer$ContextHandler');
// create instance
let _server = _httpServer.$new(port);
let _vhost = _server.getVirtualHost(null);
// disable index generation
_vhost.setAllowGeneratedIndex(false);
// add routes
routes.forEach(route => {
// make class name
let _clasName = route.path.split('/').join('.');
if (_clasName == '.') _clasName = '.index';
// implements the interface
let _myHandler = Java.registerClass({
name: `moe.awa.taikari.handler${_clasName}`,
implements: [_contextHandler],
methods: {
serve: (request, response) => {
console.log(request.getURI());
try {
// replace header
response.getHeaders()
.replace('Arcaea', `${config.arcVersion}`);
// custom handler
route.handler(request, response);
}
catch (e) {
console.error(e.stack);
response.send(500, 'Internal Server Error. _(:3) z)_');
}
return 0;
}
}
});
// add context handler
_vhost.addContext(route.path, _myHandler.$new(),
Java.array('java.lang.String', route.methods));
});
// destroy while reload the script
Script.bindWeak(_server, _ => _server.stop());
return _server;
}
// create a http server
console.log(`http server listening on :${config.challengeHttpPort}. (= w =)Zzz`);
let http = createHttpServer(config.challengeHttpPort, [
{
path: '/',
methods: ['GET'],
handler: (request, response) => {
let _fileStream = Java.use("java.io.FileInputStream");
let _fileCls = Java.use('java.io.File');
let _index = `${resFolder('htdoc')}/index.html`;
let _bodyLength = _fileCls.$new(_index).length();
let _fs = _fileStream.$new(_index);
response.getHeaders().add('Content-Length', _bodyLength.toString());
response.sendHeaders(200);
response.sendBody(_fs, _bodyLength, null);
response.close();
_fs.close();
}
},
{
path: '/v1/generate',
methods: ['GET'],
handler: (request, response) => {
// append header
response.getHeaders().add('Content-Type', 'application/json; charset=utf-8');
// increase the index
++_taskIndex;
if (_taskIndex > 10000) _taskIndex = 0;
// create a new task
let _resolve;
let _promise = new Promise(r => _resolve = r);
let _taskname = _taskIndex.toString();
_taskTable[_taskname] = {
task: _promise,
resolve: _resolve,
response: Java.retain(response) // must retain this object
};
// check the arguments
let _params = parseJavaMap(request.getParams());
_params['method'] = _params['method'].toUpperCase();
if (!_params['method'] || !_params['path']) {
response.send(200, JSON.stringify({ status: -1, message: 'lack arguments.' }));
return;
}
// check the post body
if (_params['method'] == 'POST' && !_params['body']) {
response.send(200, JSON.stringify({ status: -2, message: 'lack argument \'body\'.' }));
return;
}
// send http request
onlineManagerSendHttp(global.lpOnlineManager,
`${_apiPrefix}${decodeURIComponent(_params['path'])}`,
`Task: ${_taskname}`, _params['method'],
_params['method'] == 'POST' ? decodeURIComponent(_params['body']) : '');
// wait for promise
_promise.then((data) => {
try {
Java.perform(_ => {
let _response = _taskTable[_taskname].response;
_response.send(200, JSON.stringify({ status: 0, content: { challenge: data } }));
_response.close();
})
} catch (e) {
console.log(e.stack);
}
});
}
}
]);
http.start();
});
}
////// Utils
/////////////////////////////////////////////////////////
function taiSupported() {
return !(config.libSymbols[getArcaeaVersion()]) == false;
}
/**
* Send a http request
* @param {*} lpthis instance of OnlineManager
* @param {string} url url to access
* @param {string} method http method GET or POST
* @param {string} body POST body
* @returns
*/
function onlineManagerSendHttp(lpthis, url, headers = '', method = 'GET', body = '') {
// native help function
let _helpfunc = libSymbol('libtaikari.so!sendHttpRequest');
_helpfunc = new NativeFunction(_helpfunc, 'int64', ['pointer', 'pointer', 'pointer', 'int', 'pointer', 'pointer']);
// send function
let _callfunc = libSymbol('libcocos2dcpp.so!OnlineManager::sendHttpRequest');
// prepare resources
let _url = Memory.allocUtf8String(url);
let _method = method.toUpperCase() == 'GET' ? 0x00 : 0x01;
let _headers = Memory.allocUtf8String(headers);
let _postbody = Memory.allocUtf8String(body);
// call send http request
return _helpfunc(lpthis, _callfunc, _url, _method, _headers, _postbody);
}
/**
* Set favirate character
*/
function onlineManagerSetFavChar(lpthis, cid) {
// native help function
let _helpfunc = libSymbol('libtaikari.so!setFavoriteCharacter');
_helpfunc = new NativeFunction(_helpfunc, 'int64', ['pointer', 'pointer', 'int']);
// calling function
let _callfunc = libSymbol('libcocos2dcpp.so!OnlineManager::setFavoriteCharacter');
// call set favorite character
return _helpfunc(lpthis, _callfunc, cid);
}
/**
* Check if a hack tool enabled
* @param {string} name name of a hack tool
*/
function checkIfEnabled(name) {
let enabled = false;
config.hackTools.forEach((tool) => {
if (tool.name == name) enabled = tool.enabled;
});
return enabled;
}
/**
* Find symbol
* @param {string} name function name
* @returns NativePointer
*/
function libSymbol(name) {
let _split = name.split('!');
if (_split.length != 2) return null;
let _procName = _split[1];
let _moduleName = _split[0];
let _procAddress;
// proc address from frida
_procAddress = Module.findExportByName(_moduleName, _procName);
if (_procAddress instanceof NativePointer) return _procAddress;
// module base
let _moduleBase = Module.getBaseAddress(_moduleName);
if (!_moduleBase) return null;
// proc address from config
config.libSymbols[config.arcVersion].forEach((def) => {
if (def.name == name) _procAddress = def.proc;
});
if (_procAddress != 0) return _moduleBase.add(_procAddress);
return null;
}
/**
* Get resource folder
* @param {string} name
*/
function resFolder(name) {
return config.resFolder[name];
}
function getArcaeaVersion() {
let _arcver = '';
let _arcbuild = '';
let _architecture = '';
// arcaea version
Java.perform(() => {
let _buildConf = Java.use('moe.low.arcdev.BuildConfig');
_arcver = _buildConf.class.getDeclaredField('VERSION_NAME').get(null);
_arcbuild = _buildConf.class.getDeclaredField('VERSION_CODE').get(null);
});
// android architecture
Java.perform(() => {
let _osBuild = Java.use('android.os.Build');
_architecture = _osBuild.class.getDeclaredField('CPU_ABI').get(null);
});
return `${_arcver}_${_arcbuild}_${_architecture}`;
}
/**
* parse curl slist
* @param {NativePointer} lpslist
*/
function curlParseSlist(lpslist) {
// struct curl_slist {
// char* data;
// curl_slist* next;
// }
let _slist = lpslist;
let _data = _slist.readPointer();
let _next = _slist.add(Process.pointerSize).readPointer();
let _result = [];
// enumerate the linked table
while (!_next.isNull()) {
_result.push(_data.readUtf8String());
// next
_slist = _next;
_data = _slist.readPointer();
_next = _slist.add(Process.pointerSize).readPointer();
}
// dont forget the last one
return _result.concat(_data.readUtf8String());
}
/**
* parse java map
* @param map
*/
function parseJavaMap(map) {
var _keys = map.keySet();
var _itor = _keys.iterator();
var _array = {};
while (_itor.hasNext()) {
var _key = _itor.next();
_array[_key.toString()] = map.get(_key).toString();
}
return _array;
}
/**
* New string utf
* @param env JNI env
* @param str string
* @returns
*/
function jniNewStringUTF(env, str) {
const _jniIndex = 167;
const _funcAddress = env.readPointer().add(_jniIndex * Process.pointerSize).readPointer();
let newStringUTF = new NativeFunction(_funcAddress, 'pointer', ['pointer', 'pointer']);
return newStringUTF(env, str);
}