Rules-For-Quantumult-X/Scripts/AdBlock/Other/BaiduMap.min.js

89 lines
79 KiB
JavaScript
Raw Normal View History

let protobuf;!function(g){"use strict";!function(r,e,t){var i=function t(i){var n=e[i];return n||r[i][0].call(n=e[i]={exports:{}},t,n,n.exports),n.exports}(t[0]);protobuf=i.util.global.protobuf=i,"function"==typeof define&&define.amd&&define(["long"],function(t){return t&&t.isLong&&(i.util.Long=t,i.configure()),i}),"object"==typeof module&&module&&module.exports&&(module.exports=i)}({1:[function(t,i,n){i.exports=function(t,i){var n=Array(arguments.length-1),s=0,r=2,u=!0;for(;r<arguments.length;)n[s++]=arguments[r++];return new Promise(function(r,e){n[s]=function(t){if(u)if(u=!1,t)e(t);else{for(var i=Array(arguments.length-1),n=0;n<i.length;)i[n++]=arguments[n];r.apply(null,i)}};try{t.apply(i||null,n)}catch(t){u&&(u=!1,e(t))}})}},{}],2:[function(t,i,n){n.length=function(t){var i=t.length;if(!i)return 0;for(var n=0;1<--i%4&&"="==(t[0|i]||"");)++n;return Math.ceil(3*t.length)/4-n};for(var f=Array(64),h=Array(123),r=0;r<64;)h[f[r]=r<26?r+65:r<52?r+71:r<62?r-4:r-59|43]=r++;n.encode=function(t,i,n){for(var r,e=null,s=[],u=0,o=0;i<n;){var h=t[i++];switch(o){case 0:s[u++]=f[h>>2],r=(3&h)<<4,o=1;break;case 1:s[u++]=f[r|h>>4],r=(15&h)<<2,o=2;break;case 2:s[u++]=f[r|h>>6],s[u++]=f[63&h],o=0}8191<u&&((e=e||[]).push(String.fromCharCode.apply(String,s)),u=0)}return o&&(s[u++]=f[r],s[u++]=61,1===o&&(s[u++]=61)),e?(u&&e.push(String.fromCharCode.apply(String,s.slice(0,u))),e.join("")):String.fromCharCode.apply(String,s.slice(0,u))};var c="invalid encoding";n.decode=function(t,i,n){for(var r,e=n,s=0,u=0;u<t.length;){var o=t.charCodeAt(u++);if(61==o&&1<s)break;if((o=h[o])===g)throw Error(c);switch(s){case 0:r=o,s=1;break;case 1:i[n++]=r<<2|(48&o)>>4,r=o,s=2;break;case 2:i[n++]=(15&r)<<4|(60&o)>>2,r=o,s=3;break;case 3:i[n++]=(3&r)<<6|o,s=0}}if(1===s)throw Error(c);return n-e},n.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},{}],3:[function(t,i,n){function a(i,n){"string"==typeof i&&(n=i,i=g);var h=[];function f(t){if("string"!=typeof t){var i=c();if(a.verbose&&console.log("codegen: "+i),i="return "+i,t){for(var n=Object.keys(t),r=Array(n.length+1),e=Array(n.length),s=0;s<n.length;)r[s]=n[s],e[s]=t[n[s++]];return r[s]=i,Function.apply(null,r).apply(null,e)}return Function(i)()}for(var u=Array(arguments.length-1),o=0;o<u.length;)u[o]=arguments[++o];if(o=0,t=t.replace(/%([%dfijs])/g,function(t,i){var n=u[o++];switch(i){case"d":case"f":return""+ +(""+n);case"i":return""+Math.floor(n);case"j":return JSON.stringify(n);case"s":return""+n}return"%"}),o!==u.length)throw Error("parameter count mismatch");return h.push(t),f}function c(t){return"function "+(t||n||"")+"("+(i&&i.join(",")||"")+"){\n "+h.join("\n ")+"\n}"}return f.toString=c,f}(i.exports=a).verbose=!1},{}],4:[function(t,i,n){function r(){this.t={}}(i.exports=r).prototype.on=function(t,i,n){return(this.t[t]||(this.t[t]=[])).push({fn:i,ctx:n||this}),this},r.prototype.off=function(t,i){if(t===g)this.t={};else if(i===g)this.t[t]=[];else for(var n=this.t[t],r=0;r<n.length;)n[r].fn===i?n.splice(r,1):++r;return this},r.prototype.emit=function(t){var i=this.t[t];if(i){for(var n=[],r=1;r<arguments.length;)n.push(arguments[r++]);for(r=0;r<i.length;)i[r].fn.apply(i[r++].ctx,n)}return this}},{}],5:[function(t,i,n){i.exports=o;var s=t(1),u=t(7)("fs");function o(n,r,e){return r="function"==typeof r?(e=r,{}):r||{},e?!r.xhr&&u&&u.readFile?u.readFile(n,function(t,i){return t&&"undefined"!=typeof XMLHttpRequest?o.xhr(n,r,e):t?e(t):e(null,r.binary?i:i.toString("utf8"))}):o.xhr(n,r,e):s(o,this,n,r)}o.xhr=function(t,n,r){var e=new XMLHttpRequest;e.onreadystatechange=function(){if(4!==e.readyState)return g;if(0!==e.status&&200!==e.status)return r(Error("status "+e.status));if(n.binary){if(!(t=e.response))for(var t=[],i=0;i<e.responseText.length;++i)t.push(255&e.responseText.charCodeAt(i));return r(null,"undefined"!=typeof Uint8Array?new Uint8Array(t):t)}return r(null,e.responseText)},n.binary&&("overrideMimeType"in e&&e.overrideMimeType("text/plain; charset=x-user-defined"),e.responseType="arraybuffer"),e.open("GET",t),e.send()}},{1:1,7:7}],6:[function(t,
// https://github.com/emn178/js-md5 做了修改
let md5=null;(function(){'use strict';var ERROR='input is invalid type';var WINDOW=typeof window==='object';var root=WINDOW?window:{};if(root.JS_MD5_NO_WINDOW){WINDOW=false}var WEB_WORKER=!WINDOW&&typeof self==='object';var NODE_JS=!root.JS_MD5_NO_NODE_JS&&typeof process==='object'&&process.versions&&process.versions.node;if(NODE_JS){root=global}else if(WEB_WORKER){root=self}var COMMON_JS=!root.JS_MD5_NO_COMMON_JS&&typeof module==='object'&&module.exports;var AMD=typeof define==='function'&&define.amd;var ARRAY_BUFFER=!root.JS_MD5_NO_ARRAY_BUFFER&&typeof ArrayBuffer!=='undefined';var HEX_CHARS='0123456789abcdef'.split('');var EXTRA=[128,32768,8388608,-2147483648];var SHIFT=[0,8,16,24];var OUTPUT_TYPES=['hex','array','digest','buffer','arrayBuffer','base64'];var BASE64_ENCODE_CHAR='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');var blocks=[],buffer8;if(ARRAY_BUFFER){var buffer=new ArrayBuffer(68);buffer8=new Uint8Array(buffer);blocks=new Uint32Array(buffer)}if(root.JS_MD5_NO_NODE_JS||!Array.isArray){Array.isArray=function(obj){return Object.prototype.toString.call(obj)==='[object Array]'}}if(ARRAY_BUFFER&&(root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)){ArrayBuffer.isView=function(obj){return typeof obj==='object'&&obj.buffer&&obj.buffer.constructor===ArrayBuffer}}var createOutputMethod=function(outputType){return function(message){return new Md5(true).update(message)[outputType]()}};var createMethod=function(){var method=createOutputMethod('hex');if(NODE_JS){method=nodeWrap(method)}method.create=function(){return new Md5()};method.update=function(message){return method.create().update(message)};for(var i=0;i<OUTPUT_TYPES.length;++i){var type=OUTPUT_TYPES[i];method[type]=createOutputMethod(type)}return method};var nodeWrap=function(method){var crypto=eval("require('crypto')");var Buffer=eval("require('buffer').Buffer");var nodeMethod=function(message){if(typeof message==='string'){return crypto.createHash('md5').update(message,'utf8').digest('hex')}else{if(message===null||message===undefined){throw ERROR;}else if(message.constructor===ArrayBuffer){message=new Uint8Array(message)}}if(Array.isArray(message)||ArrayBuffer.isView(message)||message.constructor===Buffer){return crypto.createHash('md5').update(new Buffer(message)).digest('hex')}else{return method(message)}};return nodeMethod};function Md5(sharedMemory){if(sharedMemory){blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0;this.blocks=blocks;this.buffer8=buffer8}else{if(ARRAY_BUFFER){var buffer=new ArrayBuffer(68);this.buffer8=new Uint8Array(buffer);this.blocks=new Uint32Array(buffer)}else{this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0;this.finalized=this.hashed=false;this.first=true}Md5.prototype.update=function(message){if(this.finalized){return}var notString,type=typeof message;if(type!=='string'){if(type==='object'){if(message===null){throw ERROR;}else if(ARRAY_BUFFER&&message.constructor===ArrayBuffer){message=new Uint8Array(message)}else if(!Array.isArray(message)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(message)){throw ERROR;}}}else{throw ERROR;}notString=true}var code,index=0,i,length=message.length,blocks=this.blocks;var buffer8=this.buffer8;while(index<length){if(this.hashed){this.hashed=false;blocks[0]=blocks[16];blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0}if(notString){if(ARRAY_BUFFER){for(i=this.start;index<length&&i<64;++index){buffer8[i++]=message[index]}}else{for(i=this.start;index<length&&i<64;++index){blocks[i>>2]|=message[index]<<SHIFT[i++&3]}}}else{if(ARRAY_BUFFER){for(i=this.start;index<length&&i<64;++index){code=message.charCodeAt(index);if(code<0x80){buffer8[i++]=code}else if(code<0x800){buffer8[i++]=0xc0|(code>>6);buffer8[i++]=0x80|(code&0x3f)}else if(code<0xd800||code>=0xe000){buffer8[i+
const baiduMapJson = {"options":{"java_package":"com.smile.baidumap.model"},"nested":{"RepHead":{"fields":{"md5":{"type":"string","id":1},"range":{"type":"string","id":2},"messageHead":{"rule":"repeated","type":"MessageHead","id":3}}},"MessageHead":{"fields":{"offset":{"type":"int32","id":1},"length":{"type":"int32","id":2},"name":{"type":"string","id":3}}},"Result":{"fields":{"type":{"type":"int32","id":1},"error":{"type":"int32","id":2}}},"Ads":{"fields":{"option":{"type":"Option","id":1},"content":{"rule":"repeated","type":"Content","id":2}}},"Option":{"fields":{"lasttime":{"type":"int32","id":1},"checkcode":{"type":"string","id":2},"errmsg":{"type":"string","id":3}}},"Content":{"fields":{"type":{"type":"string","id":1},"data":{"type":"string","id":2},"intval":{"type":"int32","id":3},"start":{"type":"int32","id":4},"end":{"type":"int32","id":5},"id":{"type":"int32","id":6},"updatetime":{"type":"int32","id":7},"order":{"type":"int32","id":8},"ctrlMode":{"type":"string","id":9},"dayTimes":{"type":"int32","id":10}}}}};
const baiduMapRoot = protobuf.Root.fromJSON(baiduMapJson);
const isQuanX = typeof $task != "undefined";
const binaryBody = isQuanX ? new Uint8Array($response.bodyBytes) : $response.body;
//console.log(`原始数据总长度:${binaryBody.byteLength}`);
const beginOffset = 4;
const prefixLength = new DataView(binaryBody.slice(0, beginOffset).buffer).getInt32(0);
//console.log(`前缀给定的RepHead长度:${prefixLength}`);
// 解析RepHead
const repHeadData = binaryBody.slice(beginOffset, beginOffset + prefixLength);
const repHeadType = baiduMapRoot.lookupType("RepHead");
const repHeadMessage = repHeadType.decode(repHeadData);
const originMd5 = repHeadMessage.md5;
//console.log(`解析出的原始repHead长度:${repHeadType.encode(repHeadMessage).finish().length}`);
//console.log("repHead:" + JSON.stringify(repHeadMessage));
let newResult = null;
let newAds = null;
const dataBeginOffset = beginOffset + prefixLength;
for(let i = 0; i < repHeadMessage.messageHead.length; i++) {
let messageHead = repHeadMessage.messageHead[i];
const name = messageHead.name;
const targetDataLength = messageHead.length;
//console.log("messageHead:" + JSON.stringify(messageHead));
// 开始解析 Result和Ads
const currentOffset = dataBeginOffset + messageHead.offset;
//console.log(`开始解析${name}数据,起始offset:${currentOffset},读取长度为:${targetDataLength}`);
const targetData = binaryBody.slice(currentOffset, currentOffset + targetDataLength);
if(name === 'Result'){
// Result我们无需修改
const resultType = baiduMapRoot.lookupType(name);
const resultMessage = resultType.decode(targetData);
const parseMd5 = md5(binaryBody.slice(currentOffset));
console.log(`解析出的md5和原始md5相同?:${parseMd5 === originMd5}`);
newResult = resultType.encode(resultMessage).finish();
//console.log(`解析出的Result:${JSON.stringify(resultMessage)}`);
}else if(name === 'Ads'){
// 对Ads进行修改
const adsType = baiduMapRoot.lookupType(name);
let adsMessage = adsType.decode(targetData);
for(let j = 0; j < adsMessage.content.length; j++) {
let item = adsMessage.content[j];
if((item.type.indexOf('_banner') !== -1 || item.type.indexOf('splash_screen1040') !== -1)
&& item.hasOwnProperty('start') && item.hasOwnProperty('end')){
adsMessage.content[j].start = 1648746061;
adsMessage.content[j].end = 1648832461;
console.log(`设置${item.type}时间为过期`);
}
}
newAds = adsType.encode(adsMessage).finish();
}
}
// 生成新RepHead
const mergeResultAndAds = Uint8Array.from([...newResult,...newAds]);
const newMd5 = md5(mergeResultAndAds);
console.log(`新md5:${newMd5}`);
repHeadMessage.md5 = newMd5;
repHeadMessage.messageHead[0].length = newResult.byteLength;
// Ads的offset为Result的偏移量+ Result的长度
repHeadMessage.messageHead[1].offset = newResult.byteLength;
repHeadMessage.messageHead[1].length = newAds.byteLength;
const newRepHead = repHeadType.encode(repHeadMessage).finish();
const totalLength = beginOffset + newRepHead.byteLength + newResult.byteLength + newAds.byteLength;
//console.log(`totalLength:${totalLength}`);
let body = new Uint8Array(totalLength);
body.set(Uint8Array.from([(newRepHead.byteLength >> 24) & 0xff, (newRepHead.byteLength >> 16) & 0xff, (newRepHead.byteLength >> 8) & 0xff, newRepHead.byteLength & 0xff]));
body.set(newRepHead,beginOffset);
body.set(newResult,beginOffset + newRepHead.byteLength);
body.set(newAds,beginOffset + newRepHead.byteLength + newResult.byteLength);
console.log(`${body.byteLength}---${body.buffer.byteLength}`);
if(isQuanX){
$done({bodyBytes: body.buffer.slice(body.byteOffset, body.byteLength + body.byteOffset)});
} else {
$done({body});
}