fix: code logging optimization,upload to npm

This commit is contained in:
rnet 2024-01-02 04:49:13 +08:00
parent fda003f6b1
commit 45588d148f
15 changed files with 216 additions and 174 deletions

View File

@ -1,4 +1,4 @@
这个项目是瑞数加密的逆向研究,代码开发基于网站链接:`http://wcjs.sbj.cnipa.gov.cn/sgtmi`
这个项目是瑞数加密的逆向研究,代码开发基于网站链接:`https://wcjs.sbj.cnipa.gov.cn/sgtmi`
研究包括动态代码生成原理及动态cookie生成原理。
@ -16,23 +16,28 @@
## 1. 博客文章
1. [瑞数vmp-动态代码生成原理](https://howduudu.tech/#/blog/article/1701276778000)
2. [补环境-document.all的c++方案](https://howduudu.tech/#/blog/article/1702313578000)
1. [瑞数vmp-代码格式化后无法正常运行原因分析](https://howduudu.tech/#/blog/article/1699807978000)
2. [瑞数vmp-动态代码生成原理](https://howduudu.tech/#/blog/article/1701276778000)
3. [补环境-document.all的c++方案](https://howduudu.tech/#/blog/article/1702313578000)
## 2. 瑞数算法还原
**`npx rs-reverse *`与在当前目录下运行`node main.js *`相对应**
### 2.1. makecode子命令
> 体验命令:`npx rs-reverse makecode`
执行子命令`makecode`生成动态代码, 可以传入包含`$_ts.nsd``$_ts.cd`的文本文件或者直接给url让程序自己去拿。
如运行:`node main.js makecode -u http://wcjs.sbj.cnipa.gov.cn/sgtmi`,后生成三个文件:
如运行:`npx rs-reverse makecode -u http://wcjs.sbj.cnipa.gov.cn/sgtmi`,后生成三个文件:
1. 动态代码文件`output/dynamic-code.js`
2. `$_ts`文件`output/input_ts.json``output/output_ts.json`
```console
$ node main.js makecode -h
main.js makecode
$ npx rs-reverse makecode -h
rs-reverse makecode
生成动态代码
@ -43,30 +48,35 @@ Options:
-v, --version 显示版本号 [boolean]
Examples:
main.js makecode -f example/codes/1-$_ts.json
main.js makecode -u http://url/path
rs-reverse makecode -f example/codes/1-$_ts.json
rs-reverse makecode -u http://url/path
```
调用示例:
```bash
$ node main.js makecode -u http://wcjs.sbj.cnipa.gov.cn/sgtmi
文件写入成功:./rsvmp/output/dynamic-code.js
文件写入成功:./rsvmp/output/output_ts.json
文件写入成功:./rsvmp/output/input_ts.json
$ npx rs-reverse makecode
输入ts./output/output_ts.js
输出ts./output/output_ts.js
动态代码:./output/dynamic_code.js/input_ts.json
```
### 2.2. makecookie子命令
执行子命令`makecookie`生成动态代码, 可以传入包含`$_ts.nsd``$_ts.cd`的文本文件或者直接给url让程序自己去拿。
执行子命令`makecookie`生成动态代码, 可以传入包含`$_ts.nsd``$_ts.cd`的文本文件或者直接给url让程序自己去拿, 命令示例:
1. npx方式`npx rs-reverse makecookie`
2. 文件方式:`node main.js makecookie`
该命令首先会执行`makecode`子命令拿到完整的`$_ts`再运行makecookie算法生成cookie。
`makecookie`命令与`makecode`使用方式类似:
```console
$ node main.js makecode -h
main.js makecode
$ npx rs-reverse makecookie -h
rs-reverse makecookie
生成动态代码
@ -77,17 +87,51 @@ Options:
-v, --version 显示版本号 [boolean]
Examples:
main.js makecode -f example/codes/1-$_ts.json
main.js makecode -u http://url/path
rs-reverse makecookie -f example/codes/1-$_ts.json
rs-reverse makecookie -u http://url/path
```
调用示例:
```bash
$ node main.js makecookie -f example/codes/1-\$_ts.json
生成cookie成功!
length: 235
cookie: Ma8ZARIJYUhRLQrrW7Tn51DkRxBo87ofVj83ovbQLwChJdyC8LdJ69FkMO4HO.aUp9i4Qhanlv6MKa6bjuXiEvYZPLR89msKwqOJJtiL.yLk7aqwx_H2fNcMVG2zGif089rVFrdWA8dvO3Rh5iSH3sCcDuw2YHI18DvuiXTCGKrvtGXReJEYPh6pGFiZ9sONokiTCNkyqSjZIk6izfi2cg5Rba2Orfg0JCEuwWMTiBL
$ npx rs-reverse makecookie
Cookie值: 06F5jRMo1hoEoEPOKmB6eAcYaJeWGRuYthzufuuJ4tkmcCMZLbouHGcYIm462aiARAwGlJIvr6M_vbi1K3kaer3n0ZE459rr3eKe8U.xTOaCdVxik6TW2XIle7cmudenUkPfU4UaEGoqOl8nAv38f_Qb_g6kZMpHn51J2qsIdscBqGgjQvcwWPFWk2r9SHbAJbRganpjSeTH1PksisGcKwHCFbHsXqYX1jAW672tcssl
Cookie长: 236
```
### 2.3. exec子命令
runcode子命令用于开发中或者演示时使用。命令示例
1. npx方式`npx rs-reverse exec -c 'gv.cp2'`
2. 文件方式:`node main.js exec -c 'gv.cp2'`
```console
$ npx rs-reverse exec -h
rs-reverse exec
直接运行代码,用于开发及演示时使用
Options:
-h 显示帮助信息 [boolean]
-l, --level 日志打印等级参考log4js默认为info [string]
-c, --code 要运行的代码gv.cp2即打印cp2的值 [string] [required]
-v, --version 显示版本号 [boolean]
Examples:
rs-reverse exec -c 'code string'
```
调用示例:
```bash
$ npm rs-reverse exec -c '+ascii2string(gv.keys[21])'
输入:+ascii2string(gv.keys[21])
输出1718026159
```
## 3. 手动获取动态代码和$_ts的方法

152
main.js Normal file → Executable file
View File

@ -1,22 +1,72 @@
#!/usr/bin/env node
require('module-alias/register');
const paths = require('./utils/paths');
require('module-alias')(paths.package);
const yargs = require('yargs');
const fs = require('fs');
const makeCode = require('@src/makeCode');
const makeCookie = require('@src/makeCookie');
const utils = require('@utils/');
const { logger, paths, isValidUrl } = utils;
const { logger, isValidUrl } = utils;
const pkg = require(paths.package);
const request = require('request-promise');
const cheerio = require('cheerio');
const log4js = require('log4js');
function debugLog() {
if (pkg.logLevel === 'debug') {
logger.log('execPath:', __dirname);
logger.log('filePath:', __filename);
logger.log('processCwd:', process.cwd());
logger.log('paths:\n', JSON.stringify(paths, null, 2));
function debugLog(level) {
if (level) {
if (!log4js.levels.levels.map(it => it.levelStr).includes(level.toUpperCase())) {
throw new Error('日志等级输入错误,请检查!');
}
logger.level = level;
}
logger.trace('execPath:', __dirname);
logger.trace('filePath:', __filename);
logger.trace('processCwd:', process.cwd());
logger.trace('paths:\n', JSON.stringify(paths, null, 2));
}
const commandBuilder = {
f: {
alias: 'file',
describe: '含有nsd, cd值的json文件',
type: 'string',
coerce: (input) => {
if (['1', '2'].includes(input)) input = paths.exampleResolve(`codes/${input}-\$_ts.json`);
if (!fs.existsSync(input)) throw new Error(`输入文件不存在: ${input}`);
return JSON.parse(fs.readFileSync(paths.resolve(input), 'utf8'));
}
},
l: {
alias: 'level',
describe: '日志打印等级参考log4js默认为info',
type: 'string',
},
u: {
alias: 'url',
describe: '瑞数返回204状态码的请求地址',
type: 'string',
coerce: async (input) => {
if (!isValidUrl(input)) throw new Error('输入链接不正确');
try {
const res = await request(input)
const $ = cheerio.load(res);
const scripts = [...$('script')].map(ele => $(ele).text())
.filter(text => text.includes('$_ts.nsd') && text.includes('$_ts.cd'));
if (!scripts.length) throw new Error('链接返回结果未找到cd或nsd');
return Function('window', scripts[0] + 'return $_ts')({});
} catch(err) {
throw new Error('输入链接无效');
}
}
}
}
const commandHandler = (command, argv) => {
debugLog(argv.level);
const ts = argv.file || argv.url || require(paths.exampleResolve('codes/1-\$_ts.json'));
logger.trace(`传入的$_ts.nsd: ${ts.nsd}`);
logger.trace(`传入的$_ts.cd: ${ts.cd}`);
command(ts);
}
module.exports = yargs
@ -27,76 +77,40 @@ module.exports = yargs
.command({
command: 'makecode',
describe: '生成动态代码',
builder: {
f: {
alias: 'file',
describe: '含有nsd, cd值的json文件',
type: 'string',
coerce: (input) => {
if (!fs.existsSync(input)) throw new Error('输入文件不存在');
return JSON.parse(fs.readFileSync(paths.resolve(input), 'utf8'));
}
},
u: {
alias: 'url',
describe: '瑞数返回204状态码的请求地址',
type: 'string',
coerce: async (input) => {
if (!isValidUrl(input)) throw new Error('输入链接不正确');
try {
const res = await request(input)
const $ = cheerio.load(res);
const scripts = [...$('script')].map(ele => $(ele).text())
.filter(text => text.includes('$_ts.nsd') && text.includes('$_ts.cd'));
if (!scripts.length) throw new Error('链接返回结果未找到cd或nsd');
return Function('window', scripts[0] + 'return $_ts')({});
} catch(err) {
throw new Error('输入链接无效');
}
}
}
},
handler: (argv) => {
debugLog();
makeCode(argv.file || argv.url);
},
builder: commandBuilder,
handler: commandHandler.bind(null, makeCode),
})
.command({
command: 'makecookie',
describe: '生成动态cookie',
builder: commandBuilder,
handler: commandHandler.bind(null, makeCookie),
})
.command({
command: 'exec',
describe: '直接运行代码用于开发及演示时使用Math.random方法固定返回值为0.1253744220839037',
builder: {
f: {
alias: 'file',
describe: '含有nsd, cd值的json文件',
l: {
alias: 'level',
describe: '日志打印等级参考log4js默认为info',
type: 'string',
coerce: (input) => {
if (!fs.existsSync(input)) throw new Error('输入文件不存在');
return JSON.parse(fs.readFileSync(paths.resolve(input), 'utf8'));
}
},
u: {
alias: 'url',
describe: '瑞数返回204状态码的请求地址',
c: {
alias: 'code',
describe: '要运行的代码gv.cp2即打印cp2的值',
type: 'string',
coerce: async (input) => {
if (!isValidUrl(input)) throw new Error('输入链接不正确');
try {
const res = await request(input)
const $ = cheerio.load(res);
const scripts = [...$('script')].map(ele => $(ele).text())
.filter(text => text.includes('$_ts.nsd') && text.includes('$_ts.cd'));
if (!scripts.length) throw new Error('链接返回结果未找到cd或nsd');
return Function('window', scripts[0] + 'return $_ts')({});
} catch(err) {
throw new Error('输入链接无效');
}
}
}
demandOption: true,
},
},
handler: commandHandler.bind(null, makeCookie),
handler: (argv) => {
debugLog();
makeCookie(argv.file || argv.url);
},
debugLog(argv.level);
Math.random = () => 0.1253744220839037;
const gv = require('@utils/initGv');
Object.assign(global, gv.utils);
const output = JSON.stringify(eval(argv.code));
console.log([`\n 输入:${argv.code}`, `输出:${output}\n`].join('\n '));
}
})
.updateStrings({
'Show version number': '显示版本号',
@ -104,6 +118,8 @@ module.exports = yargs
})
.example('$0 makecode -f example/codes/1-\$_ts.json')
.example('$0 makecode -u http://url/path')
.example('$0 makecookie -f example/codes/1-\$_ts.json')
.example('$0 makecookie -u http://url/path')
.epilog('')
.argv;

View File

@ -1,17 +1,33 @@
{
"name": "rs-reverse",
"version": "1.0.0",
"version": "1.1.0",
"description": "瑞数算法逆向,website reverse engineering",
"main": "main.js",
"directories": {
"test": "test"
},
"bin": {
"rs-reverse": "./main.js"
},
"scripts": {
"test": "jest ./test/",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand ./test/"
},
"logLevel": "warn",
"author": "rnet",
"logLevel": "info",
"repository": {
"type": "git",
"url": "https://github.com/pysunday/rs-reverse"
},
"keywords": [
"rs",
"瑞数",
"瑞数算法逆向"
],
"files": ["package.json", "README.md", "utils", "main.js", "test", "src", "example"],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"author": "pysunday",
"license": "ISC",
"tsfile": "1-$_ts-full.json",
"dependencies": {
@ -22,9 +38,7 @@
"module-alias": "^2.2.3",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"yargs": "^17.7.2",
"canvas": "^2.11.2",
"jsdom": "^22.1.0"
"yargs": "^17.7.2"
},
"jest": {
"moduleNameMapper": {

View File

@ -1,5 +0,0 @@
require('module-alias/register');
Math.random = () => 0.1253744220839037;
const gv = require('../utils/initGv');
Object.assign(global, gv.utils);
process.argv.slice(2).forEach(text => console.log(JSON.stringify(eval(text))));

View File

@ -1,49 +0,0 @@
# 有些不方便作为测试用例的命令在这里记录,为啥作为.sh文件是因为有代码高亮
# [202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158]
node script/runcode.js 'gv.keys[gv.cp2[56]]'
# [176,246,225,18,58,227,9,73,39,226,58,47,31,68,217,1]
node script/runcode.js 'gv.keys[gv.cp2[2]]'
# [62,189,79,239,168,99,174,140,1,153,3,3,4,2,6,4]
node script/runcode.js 'gv.keys[gv.cp2[24]]'
# [101,53,210,175,101,140,3,205,0]
node script/runcode.js '[...numToNumarr4([1698026159, 1703674829]), 0, ...[string2ascii(gv.cp0[399])]]'
# [187,66,92,105,131,179,51,206,252,173,159,211,177,222,248,117,75,251,157,125,174,124,246,155,107,141,181,140,117,197,167,115,216,146,214,73,26,16,173,174,110,12,196,85,83,107,110,246,86,247,27,109,182,130,183,128,228,107,141,117,139,184,219,108,59,249,239,248,187,93,251,141,174,215,55,126,187,99,125,181,133,205,158,180,184,215]
node script/runcode.js 'numarrEncrypt([3,29,1,0,33,128,136,133,100,46,8,77,97,99,73,110,116,101,108,0,0,2,60,13,0,0,0,1,0,0,0,10,19,1,13,101,53,210,176,125,22,145,235,0,2,1,136,170,238,214,246,4,7,12,1,0,0,0,0,0,0,0,23,12,25,81,0,1,0,6,16,1,0,0,0,0,0,166,66,100,55,95,100,1,0,0,3,2,4,108,181,180,11,9,2,8,0,13,1,0])'
# [2,9,101,53,210,175,101,140,3,205,0,32,202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158]
node script/runcode.js '[gv.r2mka("0>one>32-126").taskarr[73], 9, ...[101,53,210,175,101,140,3,205,0], 32, ...[202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158]]'
# 86 [113,144,156,223,101,83,195,174,4,185,91,225,184,252,93,153,75,251,157,125,174,124,246,155,107,141,181,140,117,197,167,115,216,146,214,73,26,16,173,174,110,12,196,85,83,107,110,246,86,247,27,109,182,130,183,128,228,107,141,117,139,184,219,108,59,249,239,248,187,93,251,141,174,215,55,126,187,99,125,181,133,205,158,180,184,215]
node script/runcode.js 'xor([187,66,92,105,131,179,51,206,252,173,159,211,177,222,248,117,75,251,157,125,174,124,246,155,107,141,181,140,117,197,167,115,216,146,214,73,26,16,173,174,110,12,196,85,83,107,110,246,86,247,27,109,182,130,183,128,228,107,141,117,139,184,219,108,59,249,239,248,187,93,251,141,174,215,55,126,187,99,125,181,133,205,158,180,184,215], [202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158], gv.cp2[2])'
# [[62,189,79,239,168,99,174,140,1,153,3,3,4,2,6,4],1703674830]
node script/runcode.js 'numarrAddTime.reverse([31,156,110,206,137,66,143,173,32,184,34,34,37,35,39,37,68,173,34,239,33])'
# 96 [49,133,64,158,96,127,5,33,106,136,44,242,183,213,197,62,158,189,89,223,200,226,78,84,74,72,252,254,140,105,252,253,242,39,70,127,15,173,8,222,242,29,97,41,54,247,178,156,23,133,73,165,182,177,107,169,35,235,170,20,230,138,121,171,59,55,195,194,74,5,250,50,240,188,110,172,224,148,29,7,168,196,247,179,20,238,249,171,17,103,6,61,92,211,11,158]
node script/runcode.js 'encryptMode1([113,144,156,223,101,83,195,174,4,185,91,225,184,252,93,153,75,251,157,125,174,124,246,155,107,141,181,140,117,197,167,115,216,146,214,73,26,16,173,174,110,12,196,85,83,107,110,246,86,247,27,109,182,130,183,128,228,107,141,117,139,184,219,108,59,249,239,248,187,93,251,141,174,215,55,126,187,99,125,181,133,205,158,180,184,215], [31,156,110,206,137,66,143,173,32,184,34,34,37,35,39,37,68,173,34,239,33], 0)'
# 145 [96,251,49,122,2,9,101,53,210,175,101,140,3,205,0,32,202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158,96,49,133,64,158,96,127,5,33,106,136,44,242,183,213,197,62,158,189,89,223,200,226,78,84,74,72,252,254,140,105,252,253,242,39,70,127,15,173,8,222,242,29,97,41,54,247,178,156,23,133,73,165,182,177,107,169,35,235,170,20,230,138,121,171,59,55,195,194,74,5,250,50,240,188,110,172,224,148,29,7,168,196,247,179,20,238,249,171,17,103,6,61,92,211,11,158]
node script/runcode.js '[...numToNumarr4(1627074938), ...[2,9,101,53,210,175,101,140,3,205,0,32,202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158], 96, ...[49,133,64,158,96,127,5,33,106,136,44,242,183,213,197,62,158,189,89,223,200,226,78,84,74,72,252,254,140,105,252,253,242,39,70,127,15,173,8,222,242,29,97,41,54,247,178,156,23,133,73,165,182,177,107,169,35,235,170,20,230,138,121,171,59,55,195,194,74,5,250,50,240,188,110,172,224,148,29,7,168,196,247,179,20,238,249,171,17,103,6,61,92,211,11,158]]'
# [[176,246,225,18,58,227,9,73,39,226,58,47,31,68,217,1],1703674830]
node script/runcode.js 'numarrAddTime.reverse([145,215,192,51,27,194,40,104,6,195,27,14,62,101,248,32,68,173,34,239,33])'
# 176 [32,24,137,194,32,24,137,194,32,24,137,194,32,24,137,194,203,113,84,138,218,62,66,145,42,74,91,15,88,0,157,58,183,233,27,209,182,47,141,237,153,109,152,156,127,54,178,63,227,135,201,140,173,89,102,100,185,179,42,16,219,116,3,245,84,228,2,77,132,114,212,117,236,62,71,161,33,196,48,127,222,114,174,153,124,92,123,19,198,251,113,220,216,55,127,220,23,136,87,124,52,64,6,161,189,28,255,101,176,2,26,109,72,145,59,112,250,239,89,199,237,6,251,61,41,225,99,122,178,71,18,171,10,160,233,29,178,146,253,203,209,114,111,172,107,67,166,119,2,234,158,14,0,239,7,185,164,83,172,26,244,99,135,75,68,87,117,56,233,121,88,219,210,196,143,144]
node script/runcode.js 'encryptMode1([96,251,49,122,2,9,101,53,210,175,101,140,3,205,0,32,202,210,192,182,230,224,240,96,248,20,196,50,9,34,165,236,188,203,177,111,18,17,72,251,180,153,48,13,248,52,8,158,96,49,133,64,158,96,127,5,33,106,136,44,242,183,213,197,62,158,189,89,223,200,226,78,84,74,72,252,254,140,105,252,253,242,39,70,127,15,173,8,222,242,29,97,41,54,247,178,156,23,133,73,165,182,177,107,169,35,235,170,20,230,138,121,171,59,55,195,194,74,5,250,50,240,188,110,172,224,148,29,7,168,196,247,179,20,238,249,171,17,103,6,61,92,211,11,158], [145,215,192,51,27,194,40,104,6,195,27,14,62,101,248,32,68,173,34,239,33])'
# ErPxaPq3PQEGDEvcErPxa7zSYE.FH9tpt9NMkTGqvsj6_pBpzP5J4R2zbxSdJ.EdggIxOtTRRb1y7nLAC6AkeYs9q9ClQzpT4kyoL1olWod8Qj_RImS4lZM4Qwu3J6dQmgfUIkpqrjDeoHe27qEFMVPpi6k_4Tvo4AM4H1vf36jnpSt.cjkNoMt1dQBpQb57F0ibwahjvGgq4a8yNmi7DBpOf0zlY6Vg_U23CehlOxq
node ./script/runcode.js 'numarr2string([32,24,137,194,32,24,137,194,32,24,137,194,32,24,137,194,203,113,84,138,218,62,66,145,42,74,91,15,88,0,157,58,183,233,27,209,182,47,141,237,153,109,152,156,127,54,178,63,227,135,201,140,173,89,102,100,185,179,42,16,219,116,3,245,84,228,2,77,132,114,212,117,236,62,71,161,33,196,48,127,222,114,174,153,124,92,123,19,198,251,113,220,216,55,127,220,23,136,87,124,52,64,6,161,189,28,255,101,176,2,26,109,72,145,59,112,250,239,89,199,237,6,251,61,41,225,99,122,178,71,18,171,10,160,233,29,178,146,253,203,209,114,111,172,107,67,166,119,2,234,158,14,0,239,7,185,164,83,172,26,244,99,135,75,68,87,117,56,233,121,88,219,210,196,143,144])'
# [[176,246,225,18,58,227,9,73,39,226,58,47,31,68,217,1],1703674830]
node script/runcode.js 'numarrAddTime.reverse([244,178,165,86,126,167,77,13,99,166,126,107,91,0,157,69,33,200,71,138,68])'
# [16,114,228,100]
node script/runcode.js 'numToNumarr4(275965028)'
# [[62,189,79,239,168,99,174,140,1,153,3,3,4,2,6,4],1703674830]
node script/runcode.js 'numarrAddTime.reverse([125,254,12,172,235,32,237,207,66,218,64,64,71,65,69,71,38,207,64,141,67])'
# 96 [49,133,64,158,96,127,5,33,106,136,44,242,183,213,197,62,31,170,45,194,194,125,249,87,51,164,108,146,5,146,137,108,70,30,218,188,69,108,141,12,214,140,96,64,182,180,171,131,189,181,34,208,24,101,165,239,166,216,223,53,136,74,173,5,1,158,1,150,67,24,215,238,39,120,209,194,106,135,97,1,144,129,238,138,89,140,251,207,45,18,133,163,40,124,189,158]#
node script/runcode.js 'encryptMode1([113,144,156,223,101,83,195,174,4,185,91,225,184,252,93,153,75,251,157,125,174,124,254,219,45,174,54,214,49,215,22,157,207,98,75,89,36,104,66,182,182,135,10,17,85,77,173,187,217,91,220,109,182,218,10,222,3,145,174,53,214,46,227,109,176,239,231,191,226,237,119,238,54,187,92,221,250,237,141,246,214,23,54,122,210,227,92], [125,254,12,172,235,32,237,207,66,218,64,64,71,65,69,71,38,207,64,141,67])'

View File

@ -61,7 +61,7 @@ module.exports = class {
gv.cp2[39],
[gtn('0>one>55>one>3-189', 6)],
)
const cookie = '0' + numarr2string(
return '0' + numarr2string(
encryptMode1([
...numToNumarr4(this.r2mkaTime),
...numarrJoin(
@ -86,7 +86,6 @@ module.exports = class {
numarrAddTime(gv.keys[gv.cp2[2]], this.runTime)[0]
)
);
console.log(`生成cookie成功! \nlength: ${cookie.length}\ncookie: ${cookie}`)
}
getSubOne() {

View File

@ -1,13 +1,16 @@
const gv = require('../globalVarible');
const common = require('./common');
const logger = require('@utils/logger');
function init(ts) {
const startTime = new Date().getTime();
gv.setAttr('utils', common);
gv.setAttr('ts', ts);
require('./r2mka').init();
require('./tscp').init();
require('./tscd').init();
require('./bignum').init();
logger.debug(`globalVarible完成初始化用时${new Date().getTime() - startTime}ms`);
}
module.exports = {

View File

@ -1,5 +1,6 @@
const gv = require('../globalVarible');
const gt3 = require('@src/immutext/').globalText3;
const logger = require('@utils/logger');
function gtHandler(str, curr) {
return {
@ -85,4 +86,5 @@ exports.parse = function(str = gt3) {
exports.init = function() {
gv.setAttr('r2mka', exports.parse(gt3));
logger.debug('头r2mka标识字符串完成解析!')
}

View File

@ -1,6 +1,7 @@
// 生成密钥
const gv = require('../globalVarible');
const decrypt = require('./common/decrypt');
const logger = require('@utils/logger');
exports.init = function() {
const cdArr = decrypt(gv.ts.cd);
@ -18,4 +19,5 @@ exports.init = function() {
op += gap;
}
gv.setAttr('keys', keys);
logger.debug('$_ts.cd完成解析!')
};

View File

@ -1,9 +1,11 @@
// 将加密的字符串解密并切割成数组
const gv = require('../globalVarible');
const parse = require('./common/main');
const logger = require('@utils/logger');
exports.init = function() {
gv.setAttr('cp0', parse(gv.ts.cp[0]));
gv.setAttr('cp2', parse(gv.ts.cp[2]).map(Number));
gv.setAttr('cp6', parse(gv.ts.cp[6]));
logger.debug('$_ts.cp完成解析!')
}

View File

@ -3,18 +3,34 @@ const paths = require('@utils/paths');
const logger = require('@utils/logger');
const fs = require('fs');
function writeFile(filepath, text) {
fs.writeFileSync(filepath, text);
console.info(`文件写入成功:${filepath}`)
}
module.exports = function (ts) {
logger.info(`传入的$_ts.nsd: ${ts.nsd}`);
logger.info(`传入的$_ts.cd: ${ts.cd}`);
const startTime = new Date().getTime();
const coder = new Coder(ts);
const { code, $_ts } = coder.run();
writeFile(paths.outputResolve('dynamic-code.js'), code);
writeFile(paths.outputResolve('output_ts.json'), JSON.stringify($_ts));
writeFile(paths.outputResolve('input_ts.json'), JSON.stringify(ts));
const files = [
{
name: 'input_ts',
desc: '输入ts',
text: JSON.stringify(ts),
},
{
name: 'output_ts',
desc: '输出ts',
text: JSON.stringify($_ts),
},
{
name: 'dynamic_code',
desc: '动态代码:',
text: code,
},
].map(it => ({ ...it, filepath: paths.outputResolve(it.name) + '.js' }))
if (!fs.existsSync(paths.outputPath)) fs.mkdirSync(paths.outputPath);
files.forEach(({ filepath, text }) => fs.writeFileSync(filepath, text))
logger.info([
`生成动态代码成功!用时:${new Date().getTime() - startTime}ms\n`,
`${files[0].desc}${files[1].filepath}`,
`${files[1].desc}${files[1].filepath}`,
`${files[2].desc}${files[2].filepath}\n`,
].join('\n '));
}

View File

@ -3,11 +3,10 @@ const Coder = require('./handler/Coder');
const Cookie = require('./handler/Cookie');
module.exports = function (ts) {
logger.info(`传入的$_ts.nsd: ${ts.nsd}`);
logger.info(`传入的$_ts.cd: ${ts.cd}`);
const startTime = new Date().getTime();
const coder = new Coder(ts);
const { code, $_ts } = coder.run();
const cookie = new Cookie($_ts);
cookie.run();
const cookie = new Cookie($_ts).run();
logger.info([`生成动态cookie成功用时${new Date().getTime() - startTime}ms\n`, `Cookie值: ${cookie}`, `Cookie长: ${cookie.length}\n`].join('\n '))
}

View File

@ -2,11 +2,11 @@ const paths = require('@utils/paths');
const fs = require('fs');
const { init } = require('@src/handler/parser/');
const pkg = require(paths.package);
const logger = require('./logger');
module.exports = (function() {
const filename = pkg.tsfile;
console.log(`初始化GlobalVarible变量配置文件${filename}`)
const tsFullPath = paths.exampleResolve('codes', filename);
const tsFullPath = paths.exampleResolve('codes', pkg.tsfile);
logger.debug(`初始化GlobalVarible变量$_ts配置文件${tsFullPath}`);
init(JSON.parse(fs.readFileSync(tsFullPath, 'utf8')));
return require('@src/handler/globalVarible');
})();

View File

@ -2,6 +2,6 @@ const paths = require('./paths');
const pkg = require(paths.package);
const logger = require('log4js').getLogger(pkg.name);
logger.level = pkg.logLevel;
logger.level = process.env.loglevel || pkg.logLevel;
module.exports = logger;

View File

@ -3,7 +3,7 @@ const fs = require('fs');
const appDirectory = (() => {
// 返回项目根目录
const plist = fs.realpathSync(process.cwd()).split('/');
const plist = path.resolve(__dirname).split('/');
while (!fs.existsSync(path.resolve(plist.join('/'), 'package.json'))) {
plist.pop();
if (plist.length === 0) return false;
@ -14,14 +14,13 @@ const resolveApp = (...relativePath) => path.resolve(appDirectory, ...relativePa
module.exports = {
basePath: resolveApp(''),
homePath: __dirname,
modulePath: resolveApp('node_modules'),
binPath: resolveApp('node_modules/.bin/'),
package: path.resolve('package.json'),
package: resolveApp('package.json'),
resolve: resolveApp,
srcPath: resolveApp('src'),
outputPath: resolveApp('output'),
outputResolve: (...p) => resolveApp('output', ...p),
outputPath: path.resolve('output'),
outputResolve: (...p) => path.resolve('output', ...p),
examplePath: resolveApp('example'),
exampleResolve: (...p) => resolveApp('example', ...p),
};