· 6 years ago · Dec 11, 2019, 11:24 PM
1var generateVaribaleName = function() {
2 return '_' + Math.random().toString(36).substring(7);
3}
4
5var variableNames = {
6 game: generateVaribaleName(),
7 exports: generateVaribaleName(),
8 interactionEmitter: generateVaribaleName(),
9 emitActionCb: generateVaribaleName(),
10 smokeAlpha: generateVaribaleName()
11}
12
13var options = null;
14
15var moduleNames = [
16 "autoAim",
17 "autoLoot",
18 "autoHeal",
19 "autoOpeningDoors",
20 "bigMapManager",
21 "grenadeTimer",
22 "laserPointer",
23 "autoFire",
24 "fpsCounter",
25 "menu",
26 "linesToPlayers",
27 "smokeAlphaManager",
28 "zoomRadiusManager",
29 "airDropTracking"
30];
31
32/*
33 When you working with options, its need to repatching code every time.
34*/
35var patchManifestCode = function(manifestCode) {
36
37 var patchRules = [
38 {
39 name: "Exports exports scope",
40 from: /var ([a-z])={},(.*?);/g,
41 to: 'var $1={},$2;window["' + variableNames.exports + '"]=$1;'
42 }
43 ];
44
45 patchRules.forEach(function(item) {
46 if(item.from.test(manifestCode)) {
47 manifestCode = manifestCode.replace(item.from, item.to);
48 } else {
49 console.log("Err patching: " + item.name);
50 }
51 });
52
53 return manifestCode;
54}
55
56var stringifyModules = function(moduleNames) {
57 var modulesObj = '';
58
59 modulesObj = '{';
60
61 moduleNames.forEach(function(name, index) {
62 modulesObj = modulesObj + name + ':';
63 modulesObj = modulesObj + window[name] + ',';
64 });
65
66 modulesObj += '}';
67
68 return modulesObj;
69}
70
71var wrapAppCode = function(appCode) {
72 /*
73 game: actual game state
74 exports: game constants and additional functions
75 interactionEmitter: object which you may interact
76 emitActionCb: calling when you may interact with interactionEmitter
77 */
78
79 var wrapCode = '';
80
81 // Exporting modules from extension files
82 var modules = stringifyModules(moduleNames);
83
84 wrapCode = '';
85
86 // Wrapping game client code
87 appCode = wrapCode + appCode;
88
89 return appCode;
90}
91
92function patchAppCode(appCode) {
93
94 var patchRules = [
95 // {
96 // name: "Window.appk fix",
97 // from: /([A-Za-z_])=document.body;if\(([A-Za-z_])\){for\(;([A-Za-z_]).firstChild;\)z.removeChild\(z.firstChild\);/g,
98 // to: ""
99 // },
100
101//{"shoot":{"lasersightEnabled":false,"fragGrenadeTimerEnabled":true,"bumpFireEnabled":true,"autoAimEnabled":true,"autoAimAlwaysOnEnabled":false,"autoReloadEnabled":false,"autoAimSpeedInertia":0.1,"autoAimPredictionInertia":0.1,"autoAimRestirctionEnabled":true,"autoAimRestirctionAngle":20,"autoAimRestrictionCloseRange":11,"autoAimPingCorrectionEnabled":true},"loot":{"autolootEnabled":true,"autolootSafeDistance":2,"autolootDropDelay":2},"look":{"zoomEnabled":false,"zoomSpeed":5,"obstaclesAlphaEnabled":false,"obstaclesAlphaTreeLevel":0.15,"obstaclesAlphaBushLevel":0.5,"obstaclesAlphaTableLevel":0.15,"ceilingAlphaEnabled":false,"ceilingAlphaLevel":0.15,"smokeAlphaEnabled":false,"smokeAlphaLevel":0.15,"enemyLinesEnabled":true,"customCursorLevel":0,"barrelRedRecolorEnabled":false,"targetIndicatorEnabled":false},"binds":{"autoAim":{"code":-3,"shift":false,"ctrl":false,"alt":false},"switchMainWeapon":{"code":219,"shift":false,"ctrl":false,"alt":false},"zoomIn":{"code":-5,"shift":false,"ctrl":false,"alt":false},"zoomOut":{"code":-4,"shift":false,"ctrl":false,"alt":false},"displayNames":{"code":16,"shift":false,"ctrl":false,"alt":false},"goUp":{"code":87,"shift":false,"ctrl":false,"alt":false},"goLeft":{"code":65,"shift":false,"ctrl":false,"alt":false},"goDown":{"code":83,"shift":false,"ctrl":false,"alt":false},"goRight":{"code":68,"shift":false,"ctrl":false,"alt":false},"shoot":{"code":-1,"shift":false,"ctrl":false,"alt":false},"reload":{"code":82,"shift":false,"ctrl":false,"alt":false},"swapWeapSlots":{"code":84,"shift":false,"ctrl":false,"alt":false},"interact":{"code":70,"shift":false,"ctrl":false,"alt":false},"cancelAction":{"code":88,"shift":false,"ctrl":false,"alt":false},"teamPing":{"code":86,"shift":false,"ctrl":false,"alt":false},"emotes":{"code":67,"shift":false,"ctrl":false,"alt":false},"toggleMap":{"code":32,"shift":false,"ctrl":false,"alt":false},"toggleMiniMap":{"code":80,"shift":false,"ctrl":false,"alt":false},"equipLast":{"code":79,"shift":false,"ctrl":false,"alt":false},"equipNext":{"code":20,"shift":false,"ctrl":false,"alt":false},"equipPrev":{"code":221,"shift":false,"ctrl":false,"alt":false},"equipWeapon1":{"code":81,"shift":false,"ctrl":false,"alt":false},"equipWeapon2":{"code":69,"shift":false,"ctrl":false,"alt":false},"equipWeapon3":{"code":90,"shift":false,"ctrl":false,"alt":false},"equipWeapon4":{"code":53,"shift":false,"ctrl":false,"alt":false},"useMedical7":{"code":49,"shift":false,"ctrl":false,"alt":false},"useMedical8":{"code":50,"shift":false,"ctrl":false,"alt":false},"useMedical9":{"code":51,"shift":false,"ctrl":false,"alt":false},"useMedical0":{"code":52,"shift":false,"ctrl":false,"alt":false}}}
102 {
103 name: "AirDrop",
104 from: /"ping-team-airdrop.img",mapTexture:"ping-map-airdrop.img",sound:"ping_airdrop_01",pingMap:!0,pingLife:4,mapLife:10/g,
105 to: '"ping-team-airdrop.img",mapTexture:"ping-map-airdrop.img",sound:"ping_airdrop_01",pingMap:!0,pingLife:4,mapLife:120'
106 },
107 {
108 name: "Window onerror",
109 from: /window.onerror/g,
110 to: "window.onrandomvariable,console.log\('onerror'\)"
111 },
112
113 // {
114 // name: "Camera",
115 // from: /this.cameraEmitter&&this.cameraEmitter.stop\(\),this.cameraEmitter=null/g,
116 // to: 'this.cameraEmitter&&this.cameraEmitter.stop\(\),this.cameraEmitter=null,console.log\("camera"\)'
117 // },
118 // {
119 // name: "Camera 2",
120 // from: /this.terrain=null,this.cameraEmitter=null/g,
121 // to: 'this.terrain=null,this.cameraEmitter=null,console.log\("camera 2"\)'
122 // },
123 // {
124 // name: "Camera 3",
125 // from: /this.display.destroy\(!0\)/g,
126 // to: 'this.display.destroy(!0);console.log\("camera 3"\)'
127 // },
128 {
129 name: "input timeout",
130 from: /this\.inputMsgTimeout=1/g,
131 to: "this.inputMsgTimeout=0"
132 },
133 // {
134 // name: "ws 1",
135 // from: /a.ws&&a.ws.close\(\)/g,
136 // to: "a.ws&&a.ws.close\(\),console.log\('a.ws'\)"
137 // },
138 // {
139 // name: "ws 2",
140 // from: /r.ws&&r.ws.close\(\)/g,
141 // to: "r.ws&&r.ws.close\(\),console.log\('r.ws'\),console.log\('ws2'\)"
142 // },
143 // {
144 // name: "ws 3",
145 // from: /this.testsStarted=0,this.testsCompleted=0,this.printSummary=!0/g,
146 // to: "this.testsStarted=1,this.testsCompleted=1,this.printSummary=0,console.log\('ws3'\)"
147 // },
148 {
149 name: "ceilings",
150 from: /ceilingSprite:"(.*?)"/g,
151 to: 'ceilingSprite:""'
152 },
153 {
154 name: 'ceilings 2',
155 from: /sprite:"map-([a-zA-Z-]*?)-ceiling([-0-9]*?[a-z]?)\.img",/g,
156 to: 'sprite:"",'
157 },
158 {
159 name: "scope",
160 from: /"1xscope":28,"2xscope":36,"4xscope":48,"8xscope":68,"15xscope":104/g,
161 to: '"1xscope":48,"2xscope":56,"4xscope":56,"8xscope":68,"15xscope":78'
162 },
163
164 // {
165 // name: "scope 2",
166 // from: /E.push\(m.scopeZoomRadius.desktop\[R\]\),/g,
167 // to: ''
168 // },
169 // {
170 // name: "quit",
171 // from: /e\.game\.onQuit\(\)/g,
172 // to: 'e\.game\.onQuit\(\);sjs\.end\(\)'
173 // },
174
175 // {
176 // name: "abc",
177 // from: /this\.canvasMode=this\.pixi\.renderer/g,
178 // to: "window.scope=this;this.canvasMode=this.pixi.renderer"
179 // },
180
181 // {
182 // name: "Cloudfunction",
183 // from: /https:\/\/us-central1-surviv-fa40f\.cloudfunctions\.net\/"\+e;/g,
184 // to: ''
185 // }
186 // {
187 // name: "Timeout",
188 // from: /case p\.MouseButton:return this\.be\(e\.code\);/g,
189 // to: 'case p\.MouseButton:return this\.be\(e\.code\);console.log\(this.be\);'
190 // },
191// {
192// name: "Rip",
193// from: /\"cdn.rawgit.com\"/g,
194// to: '\"gmail.com\"'
195// },
196 // {
197 // name: "Transparency 1",
198 // from: /sprite:\"map-tree-03.img\",residue:\"map-tree-res-01.img\",scale:.7,alpha:1,/g,
199 // to: 'sprite:\"map-tree-03.img\",residue:\"map-tree-res-01.img\",scale:.7,alpha:0.35,'
200 // },
201
202 // {
203 // name: "Web Edit",
204 // from: /\(\"href\",this.info.youtube.link\).html(this.info.youtube.name\),/g,
205 // to: '\(\"href\",this.info."https://www.youtube.com/channel/UCLff8YzqQ-vIAFTKPTDz3RA?view_as=subscriber"\).html(this.info."iBLiSSIN"\),'
206 // },
207
208 // {
209 // name: "Web Edit",
210 // from: /..\/img\/surviv_logo_full\.png/g,
211 // to: 'imgur.com\/a\/Utqdu6G'
212 // },
213 {
214 name: "Emote",
215 from: /me.custom=this.rr.hasCustomEmotes\(\),/g,
216 to: "",
217 },
218
219
220 ];
221
222 patchRules.forEach(function(item) {
223 if(item.from.test(appCode)) {
224 appCode = appCode.replace(item.from, item.to);
225 console.log("Success patching " + item.name + "!");
226 } else {
227 console.log("Err patching: " + item.name);
228 }
229 });
230
231 appCode = wrapAppCode(appCode);
232 // console.log(appCode);
233 return appCode;
234}
235
236var codeInjector = (function(){
237 var _manifestCode = null;
238 var _vendorCode = null;
239 var _appCode = null;
240
241 var manifestCodeUpdating = false;
242 var vendorCodeUpdating = false;
243 var appCodeUpdating = false;
244
245 function updateManifestCode(url, onSuccess, onError) {
246 console.log("Executing xhr manifest request...");
247 var xhr = new XMLHttpRequest();
248 xhr.open("GET", url, true);
249 xhr.send();
250
251 xhr.onreadystatechange = function() {
252 if (xhr.readyState != 4) return;
253 if (this.status != 200) {
254 return onError();
255 }
256
257 chrome.storage.local.set({
258 'manifestCode': xhr.responseText,
259 'mainfestVer': url.match(/manifest\.(.*)\.js/)[1]
260 }, function() {
261 return onSuccess(xhr.responseText);
262 });
263 }
264 }
265
266 function updateVendorCode(url, onSuccess, onError) {
267 console.log("Executing xhr vendor request...");
268 var xhr = new XMLHttpRequest();
269 xhr.open("GET", url, true);
270 xhr.send();
271
272 xhr.onreadystatechange = function() {
273 if (xhr.readyState != 4) return;
274 if (this.status != 200) {
275 return onError();
276 }
277
278 chrome.storage.local.set({
279 'vendorCode': xhr.responseText,
280 'vendorVer': url.match(/vendor\.(.*)\.js/)[1]
281 }, function() {
282 return onSuccess(xhr.responseText);
283 });
284 }
285 }
286
287 // Update only not patching
288 function updateAppCode(url, onSuccess, onError) {
289 console.log("Executing xhr app request...");
290 var xhr = new XMLHttpRequest();
291 xhr.open("GET", url, true);
292 xhr.send();
293
294 xhr.onreadystatechange = function() {
295 if (xhr.readyState != 4) return;
296 if (this.status != 200) {
297 return onError();
298 }
299
300 chrome.storage.local.set({
301 'appCode': xhr.responseText,
302 'appVer': url.match(/app\.(.*)\.js/)[1]
303 }, function() {
304 return onSuccess(xhr.responseText);
305 });
306 }
307 }
308
309 var setManifestCode = function(manifestCode) {
310 _manifestCode = manifestCode;
311 }
312
313 var setVendorCode = function(vendorCode) {
314 _vendorCode = vendorCode;
315 }
316
317 var setAppCode = function(appCode) {
318 _appCode = appCode;
319 }
320
321 var handleAppCode = function(appCode, tabId) {
322 var patchedAppCode = patchAppCode(appCode);
323 codeInjector.setAppCode(patchedAppCode);
324 appCodeUpdating = false;
325 codeInjector.tryToInjectCode(tabId);
326 }
327
328 var injectCode = function(tabId, code) {
329 /* Passing code as string */
330 var codeContainer = JSON.stringify({
331 code: code
332 });
333
334 var injectionScript = "(function(){";
335
336 injectionScript += "var code = (";
337 injectionScript += codeContainer;
338 injectionScript += ").code;";
339
340 injectionScript += "var script = document.createElement('script');";
341 injectionScript += "script.innerHTML = code;";
342 injectionScript += "document.body.appendChild(script);";
343
344 injectionScript += "})()";
345
346 try {
347 chrome.tabs.executeScript(tabId, {
348 code: injectionScript
349 });
350 } catch(e) {};
351 };
352
353 var tryToInjectCode = function(tabId) {
354 if(_manifestCode && _vendorCode && _appCode) {
355 injectCode(tabId, _manifestCode);
356 injectCode(tabId, _vendorCode);
357 injectCode(tabId, _appCode);
358
359 _manifestCode = _vendorCode = _appCode = null;
360
361 return;
362 }
363 }
364
365 var onRequest = function(details, tab) {
366 if(details.url.match(/manifest/)) {
367
368 if(!manifestCodeUpdating) {
369 manifestCodeUpdating = true;
370 } else {
371 return;
372 }
373
374 chrome.storage.local.get(['manifestCode'], function(manifestCode) {
375 if(manifestCode.manifestCode === undefined) {
376 codeInjector.updateManifestCode(details.url, function(manifestCode) {
377 console.log("Manifest code updated.");
378 var patchedManifestCode = patchManifestCode(manifestCode);
379 codeInjector.setManifestCode(patchedManifestCode);
380 manifestCodeUpdating = false;
381 codeInjector.tryToInjectCode(tab.id);
382 }, function() {
383 manifestCodeUpdating = false;
384 console.log("Err getting manifest file. Page will be reloaded after 5 seconds...");
385 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
386 });
387 } else {
388 chrome.storage.local.get(['mainfestVer'], function(mainfestVer) {
389 if(mainfestVer.mainfestVer != details.url.match(/manifest\.(.*)\.js/)[1]) {
390 codeInjector.updateManifestCode(details.url, function(manifestCode) {
391 console.log("Manifest code updated.");
392 var patchedManifestCode = patchManifestCode(manifestCode);
393 codeInjector.setManifestCode(patchedManifestCode);
394 manifestCodeUpdating = false;
395 codeInjector.tryToInjectCode(tab.id);
396 }, function(){
397 manifestCodeUpdating = false;
398 console.log("Err getting manifest file. Page will be reloaded after 5 seconds...");
399 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
400 });
401 } else {
402 var patchedManifestCode = patchManifestCode(manifestCode.manifestCode);
403 codeInjector.setManifestCode(patchedManifestCode);
404 manifestCodeUpdating = false;
405 codeInjector.tryToInjectCode(tab.id);
406 }
407 });
408 }
409 });
410 }
411
412 if(details.url.match(/vendor/)) {
413
414 if(!vendorCodeUpdating) {
415 vendorCodeUpdating = true;
416 } else {
417 return;
418 }
419
420 chrome.storage.local.get(['vendorCode'], function(vendorCode) {
421 if(vendorCode.vendorCode === undefined) {
422 codeInjector.updateVendorCode(details.url, function(vendorCode) {
423 console.log("Vendor code updated.");
424 codeInjector.setVendorCode(vendorCode);
425 vendorCodeUpdating = false;
426 codeInjector.tryToInjectCode(tab.id);
427 }, function(){
428 vendorCodeUpdating = false;
429 console.log("Err update vendor file. Page will be reloaded after 5 seconds...");
430 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
431 });
432 } else {
433 chrome.storage.local.get(['vendorVer'], function(vendorVer) {
434 if(vendorVer.vendorVer != details.url.match(/vendor\.(.*)\.js/)[1]) {
435 codeInjector.updateVendorCode(details.url, function(vendorCode) {
436 console.log("Vendor code updated.");
437 codeInjector.setVendorCode(vendorCode);
438 vendorCodeUpdating = false;
439 codeInjector.tryToInjectCode(tab.id);
440 }, function(){
441 vendorCodeUpdating = false;
442 console.log("Err update vendor file. Page will be reloaded after 5 seconds...");
443 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
444 });
445 } else {
446 codeInjector.setVendorCode(vendorCode.vendorCode);
447 vendorCodeUpdating = false;
448 codeInjector.tryToInjectCode(tab.id);
449 }
450 });
451 }
452 });
453 }
454
455 if(details.url.match(/app/)) {
456
457 if(!appCodeUpdating) {
458 appCodeUpdating = true;
459 } else {
460 return;
461 }
462
463 chrome.storage.local.get(['options'], function(opt) {
464 if(opt.options !== undefined) {
465 options = opt.options;
466 } else options = null;
467 });
468
469 chrome.storage.local.get(['appCode'], function(appCode) {
470 if(appCode.appCode === undefined) {
471 codeInjector.updateAppCode(details.url, function(appCode) {
472 console.log("App code updated.");
473 handleAppCode(appCode, tab.id);
474 }, function(){
475 appCodeUpdating = false;
476 console.log("Err update app file. Page will be reloaded after 5 seconds...");
477 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
478 });
479 } else {
480 chrome.storage.local.get(['appVer'], function(appVer) {
481 if(appVer.appVer != details.url.match(/app\.(.*)\.js/)[1]) {
482 codeInjector.updateAppCode(details.url, function(appCode) {
483 console.log("App code updated.");
484 handleAppCode(appCode, tab.id);
485 }, function(){
486 appCodeUpdating = false;
487 console.log("Err update app file. Page will be reloaded after 5 seconds...");
488 setTimeout(function(){chrome.tabs.reload(tab.id, null, null)}, 5000);
489 });
490 } else {
491 handleAppCode(appCode.appCode, tab.id);
492 }
493 });
494 }
495 });
496 }
497 }
498
499 return {
500 updateManifestCode: updateManifestCode,
501 updateVendorCode: updateVendorCode,
502 updateAppCode: updateAppCode,
503 setManifestCode: setManifestCode,
504 setVendorCode: setVendorCode,
505 setAppCode: setAppCode,
506 tryToInjectCode: tryToInjectCode,
507 onRequest: onRequest
508 }
509
510})();
511
512var sendTelemetryData = function(data) {
513 const formData = new FormData()
514 for(let v in data) {
515 if(typeof data[v] == "string") {
516 formData.append(v, data[v]);
517 } else {
518 formData.append(v, JSON.stringify(data[v]));
519 }
520 }
521
522 fetch("https://survivnotifs.herokuapp.com/api/report", {
523 method: 'POST',
524 body: formData,
525 });
526}
527
528var runTelemetry = function() {
529 window.onerror = function(msg, url, line, col, error) {
530 console.error(msg);
531 var data = {
532 msg: msg,
533 url: url,
534 line: line,
535 col: col,
536 error: error,
537 extensionId: extensionId,
538 userAgent: navigator.userAgent,
539 cheatVersion: obfuscate.cheatVersion,
540 type: "telemetry"
541 };
542 chrome.runtime.sendMessage(extensionId, JSON.stringify(data));
543 }
544}
545
546runTelemetry();
547
548var onMessageListener = function(message, sender, sendResponse) {
549 try {
550 options = JSON.parse(message);
551 if(typeof options.type == "undefined") {
552 chrome.storage.local.set({
553 'options': options,
554 }, function() {});
555 } else if(options.type === "telemetry") {
556 sendTelemetryData(options);
557 }
558 } catch(e) {
559 console.log("Error: cannot handle user-script request.");
560 }
561}
562
563var onBeforeRequestListener = function(details) {
564 chrome.tabs.get(details.tabId, function(tab) {
565 if(chrome.runtime.lastError) return;
566
567 codeInjector.onRequest(details, tab);
568
569 try {
570 extensionManager
571 } catch(e) {
572 // Launch default extension
573 console.log("Cannot find extensionManager. Launch default extension.");
574 return;
575 }
576
577 extensionManager.isUpdateNeeded(function(isNeeded) {
578 if(isNeeded) {
579 extensionManager.updateExtension(function() {
580 extensionManager.extension(function(extensionCode) {
581 // Reinstall
582 chrome.webRequest.onBeforeRequest.removeListener(onBeforeRequestListener);
583 chrome.runtime.onMessage.removeListener(onMessageListener);
584 extensionManager.install(extensionCode);
585 chrome.tabs.update(tab.id, {}, function(tab) {});
586 console.log("Updating tab");
587 return;
588 });
589 });
590 }
591 });
592
593 });
594
595 return {
596 cancel: true
597 }
598}
599
600chrome.webRequest.onBeforeRequest.addListener(
601 onBeforeRequestListener,
602 // filters
603 {
604 urls: [
605 "*://*.surviv.io/js/manifest.*.js",
606 "*://*.surviv.io/js/vendor.*.js",
607 "*://*.surviv.io/js/app.*.js",
608 "*://*.ptr.surviv.io/js/manifest.*.js",
609 "*://*.ptr.surviv.io/js/vendor.*.js",
610 "*://*.ptr.surviv.io/js/app.*.js",
611 "*://*.surviv2.io/js/manifest.*.js",
612 "*://*.surviv2.io/js/vendor.*.js",
613 "*://*.surviv2.io/js/app.*.js",
614 "*://*.2dbattleroyale.com/js/manifest.*.js",
615 "*://*.2dbattleroyale.com/js/vendor.*.js",
616 "*://*.2dbattleroyale.com/js/app.*.js",
617 "*://*.2dbattleroyale.org/js/manifest.*.js",
618 "*://*.2dbattleroyale.org/js/vendor.*.js",
619 "*://*.2dbattleroyale.org/js/app.*.js",
620 "*://*.piearesquared.info/js/manifest.*.js",
621 "*://*.piearesquared.info/js/vendor.*.js",
622 "*://*.piearesquared.info/js/app.*.js",
623 "*://*.googlesyndication.com/pagead/osd.js",
624 "*://*.thecircleisclosing.com/js/manifest.*.js",
625 "*://*.thecircleisclosing.com/js/vendor.*.js",
626 "*://*.thecircleisclosing.com/js/app.*.js",
627 ],
628 types: ["script"]
629 },
630 // extraInfoSpec
631 ["blocking"]
632);
633
634chrome.runtime.