mirror of
https://github.com/lan-tianxiang/clone_scripts.git
synced 2025-07-19 02:13:45 +08:00
更新于 07-14 11:38
This commit is contained in:
213
MovementFaker.js
213
MovementFaker.js
@@ -2,139 +2,138 @@ const https = require('https');
|
|||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const { R_OK } = require('fs').constants;
|
const { R_OK } = require('fs').constants;
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
const UA = require('./USER_AGENTS.js').USER_AGENT;
|
||||||
|
|
||||||
const URL = 'https://wbbny.m.jd.com/babelDiy/Zeus/2rtpffK8wqNyPBH6wyUDuBKoAbCt/index.html';
|
const URL = 'https://wbbny.m.jd.com/babelDiy/Zeus/2rtpffK8wqNyPBH6wyUDuBKoAbCt/index.html';
|
||||||
// const REG_MODULE = /(\d+)\:function\(.*(?=smashUtils\.get_risk_result)/gm;
|
// const REG_MODULE = /(\d+)\:function\(.*(?=smashUtils\.get_risk_result)/gm;
|
||||||
const SYNTAX_MODULE = '!function(n){var r={};function o(e){if(r[e])';
|
const SYNTAX_MODULE = '!function(n){var r={};function o(e){if(r[e])';
|
||||||
const REG_SCRIPT = /<script type="text\/javascript" src="([^><]+\/(app\.\w+\.js))\">/gm;
|
const REG_SCRIPT = /<script type="text\/javascript" src="([^><]+\/(app\.\w+\.js))\">/gm;
|
||||||
const REG_ENTRY = /(__webpack_require__\(__webpack_require__.s=)(\d+)(?=\)})/;
|
const REG_ENTRY = /(__webpack_require__\(__webpack_require__\.s=)(\d+)(?=\)})/;
|
||||||
const needModuleId = 355
|
const needModuleId = 356
|
||||||
const DATA = {appid:'50085',sceneid:'OY217hPageh5'};
|
const DATA = {appid:'50085',sceneid:'OY217hPageh5'};
|
||||||
let smashUtils;
|
let smashUtils;
|
||||||
|
|
||||||
class MovementFaker {
|
class MoveMentFaker {
|
||||||
constructor(cookie) {
|
constructor(cookie) {
|
||||||
// this.secretp = secretp;
|
// this.secretp = secretp;
|
||||||
this.cookie = cookie;
|
this.cookie = cookie;
|
||||||
this.ua = require('./USER_AGENTS.js').USER_AGENT;
|
}
|
||||||
|
|
||||||
|
async run() {
|
||||||
|
if (!smashUtils) {
|
||||||
|
await this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
var t = Math.floor(1e7 + 9e7 * Math.random()).toString();
|
||||||
if (!smashUtils) {
|
var e = smashUtils.get_risk_result({
|
||||||
await this.init();
|
id: t,
|
||||||
}
|
data: {
|
||||||
|
random: t
|
||||||
|
}
|
||||||
|
}).log;
|
||||||
|
var o = JSON.stringify({
|
||||||
|
extraData: {
|
||||||
|
log: e || -1,
|
||||||
|
// log: encodeURIComponent(e),
|
||||||
|
sceneid: DATA.sceneid,
|
||||||
|
},
|
||||||
|
// secretp: this.secretp,
|
||||||
|
random: t
|
||||||
|
})
|
||||||
|
|
||||||
var t = Math.floor(1e7 + 9e7 * Math.random()).toString();
|
// console.log(o);
|
||||||
var e = smashUtils.get_risk_result({
|
return o;
|
||||||
id: t,
|
}
|
||||||
data: {
|
|
||||||
random: t
|
|
||||||
}
|
|
||||||
}).log;
|
|
||||||
var o = JSON.stringify({
|
|
||||||
extraData: {
|
|
||||||
log: e || -1,
|
|
||||||
// log: encodeURIComponent(e),
|
|
||||||
sceneid: DATA.sceneid,
|
|
||||||
},
|
|
||||||
// secretp: this.secretp,
|
|
||||||
random: t
|
|
||||||
})
|
|
||||||
|
|
||||||
// console.log(o);
|
async init() {
|
||||||
return o;
|
try {
|
||||||
}
|
// console.time('MoveMentFaker');
|
||||||
|
process.chdir(__dirname);
|
||||||
|
const html = await MoveMentFaker.httpGet(URL);
|
||||||
|
const script = REG_SCRIPT.exec(html);
|
||||||
|
|
||||||
async init() {
|
if (script) {
|
||||||
try {
|
const [, scriptUrl, filename] = script;
|
||||||
console.time('MovementFaker');
|
const jsContent = await this.getJSContent(filename, scriptUrl);
|
||||||
process.chdir(__dirname);
|
const fnMock = new Function;
|
||||||
const html = await MovementFaker.httpGet(URL);
|
const ctx = {
|
||||||
const script = REG_SCRIPT.exec(html);
|
window: { addEventListener: fnMock },
|
||||||
|
document: {
|
||||||
|
addEventListener: fnMock,
|
||||||
|
removeEventListener: fnMock,
|
||||||
|
cookie: this.cookie
|
||||||
|
},
|
||||||
|
navigator: { userAgent: UA }
|
||||||
|
};
|
||||||
|
|
||||||
if (script) {
|
vm.createContext(ctx);
|
||||||
const [, scriptUrl, filename] = script;
|
vm.runInContext(jsContent, ctx);
|
||||||
const jsContent = await this.getJSContent(filename, scriptUrl);
|
smashUtils = ctx.window.smashUtils;
|
||||||
const fnMock = new Function;
|
smashUtils.init(DATA);
|
||||||
const ctx = {
|
|
||||||
window: { addEventListener: fnMock },
|
|
||||||
document: {
|
|
||||||
addEventListener: fnMock,
|
|
||||||
removeEventListener: fnMock,
|
|
||||||
cookie: this.cookie,
|
|
||||||
},
|
|
||||||
navigator: { userAgent: this.ua },
|
|
||||||
};
|
|
||||||
|
|
||||||
vm.createContext(ctx);
|
// console.log(ctx);
|
||||||
vm.runInContext(jsContent, ctx);
|
}
|
||||||
smashUtils = ctx.window.smashUtils;
|
|
||||||
smashUtils.init(DATA);
|
|
||||||
|
|
||||||
// console.log(ctx);
|
// console.log(html);
|
||||||
}
|
// console.log(script[1],script[2]);
|
||||||
|
// console.timeEnd('MoveMentFaker');
|
||||||
// console.log(html);
|
|
||||||
// console.log(script[1],script[2]);
|
|
||||||
console.timeEnd('MovementFaker');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getJSContent(cacheKey, url) {
|
||||||
|
try {
|
||||||
|
await fs.access(cacheKey, R_OK);
|
||||||
|
const rawFile = await fs.readFile(cacheKey, { encoding: 'utf8' });
|
||||||
|
|
||||||
|
return rawFile;
|
||||||
|
} catch (e) {
|
||||||
|
let jsContent = await MoveMentFaker.httpGet(url);
|
||||||
|
const moduleIndex = jsContent.indexOf(SYNTAX_MODULE, 1);
|
||||||
|
const findEntry = REG_ENTRY.test(jsContent);
|
||||||
|
if (!(moduleIndex && findEntry)) {
|
||||||
|
throw new Error('Module not found.');
|
||||||
|
}
|
||||||
|
// const needModuleId = jsContent.substring(moduleIndex-20, moduleIndex).match(/(\d+):function/)[1]
|
||||||
|
jsContent = jsContent.replace(REG_ENTRY, `$1${needModuleId}`);
|
||||||
|
fs.writeFile(cacheKey, jsContent);
|
||||||
|
return jsContent;
|
||||||
|
|
||||||
|
REG_ENTRY.lastIndex = 0;
|
||||||
|
const entry = REG_ENTRY.exec(jsContent);
|
||||||
|
|
||||||
|
console.log(moduleIndex, needModuleId);
|
||||||
|
console.log(entry[1], entry[2]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getJSContent(cacheKey, url) {
|
static httpGet(url) {
|
||||||
try {
|
return new Promise((resolve, reject) => {
|
||||||
await fs.access(cacheKey, R_OK);
|
const protocol = url.indexOf('http') !== 0 ? 'https:' : '';
|
||||||
const rawFile = await fs.readFile(cacheKey, { encoding: 'utf8' });
|
const req = https.get(protocol + url, (res) => {
|
||||||
|
res.setEncoding('utf-8');
|
||||||
|
|
||||||
return rawFile;
|
let rawData = '';
|
||||||
} catch (e) {
|
|
||||||
let jsContent = await MovementFaker.httpGet(url);
|
|
||||||
const moduleIndex = jsContent.indexOf(SYNTAX_MODULE, 1);
|
|
||||||
const findEntry = REG_ENTRY.test(jsContent);
|
|
||||||
console.log(jsContent)
|
|
||||||
if (!(moduleIndex && findEntry)) {
|
|
||||||
throw new Error('Module not found.');
|
|
||||||
}
|
|
||||||
// const needModuleId = jsContent.substring(moduleIndex-20, moduleIndex).match(/(\d+):function/)[1]
|
|
||||||
jsContent = jsContent.replace(REG_ENTRY, `$1${needModuleId}`);
|
|
||||||
fs.writeFile(cacheKey, jsContent);
|
|
||||||
return jsContent;
|
|
||||||
|
|
||||||
REG_ENTRY.lastIndex = 0;
|
res.on('error', reject);
|
||||||
const entry = REG_ENTRY.exec(jsContent);
|
res.on('data', chunk => rawData += chunk);
|
||||||
|
res.on('end', () => resolve(rawData));
|
||||||
|
});
|
||||||
|
|
||||||
console.log(moduleIndex, needModuleId);
|
req.on('error', reject);
|
||||||
console.log(entry[1], entry[2]);
|
req.end();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static httpGet(url) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const protocol = url.indexOf('http') !== 0 ? 'https:' : '';
|
|
||||||
const req = https.get(protocol + url, (res) => {
|
|
||||||
res.setEncoding('utf-8');
|
|
||||||
|
|
||||||
let rawData = '';
|
|
||||||
|
|
||||||
res.on('error', reject);
|
|
||||||
res.on('data', chunk => rawData += chunk);
|
|
||||||
res.on('end', () => resolve(rawData));
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', reject);
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBody($) {
|
async function getBody($) {
|
||||||
const zf = new MovementFaker($.cookie);
|
const zf = new MoveMentFaker($.cookie);
|
||||||
// const zf = new MovementFaker($.secretp, $.cookie);
|
// const zf = new MoveMentFaker($.secretp, $.cookie);
|
||||||
const ss = await zf.run();
|
const ss = await zf.run();
|
||||||
|
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
MovementFaker.getBody = getBody;
|
MoveMentFaker.getBody = getBody;
|
||||||
module.exports = MovementFaker;
|
module.exports = MoveMentFaker;
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user