first try at cathcing up with latest stock changes

This commit is contained in:
fkloft 2015-02-06 21:33:18 +01:00
parent fe230dc8dd
commit f619911a98

View File

@ -4,7 +4,9 @@
window.extractFromStock = function() { window.extractFromStock = function() {
window.niantic_params = {} window.niantic_params = {}
window.niantic_params.botguard_group_a_methods = [];
var methods = ['artifacts', 'getGameScore', 'getPlexts', 'getPortalDetails', 'redeemReward', 'sendInviteEmail', 'sendPlext'];
// extract the former nemesis.dashboard.config.CURRENT_VERSION from the code // extract the former nemesis.dashboard.config.CURRENT_VERSION from the code
var reVersion = new RegExp('[a-z]=[a-z].getData\\(\\);[a-z].v="([a-f0-9]{40})";'); var reVersion = new RegExp('[a-z]=[a-z].getData\\(\\);[a-z].v="([a-f0-9]{40})";');
@ -14,19 +16,31 @@ window.extractFromStock = function() {
var minified = new RegExp('^[a-zA-Z$][a-zA-Z$0-9]$'); var minified = new RegExp('^[a-zA-Z$][a-zA-Z$0-9]$');
// required for botguard
var requestPrototype = (function() {
for(var topLevel in window) {
if(!window[topLevel]) continue;
// need an example for a request object
for(var property in window[topLevel]) {
if(window[topLevel][property] == "getRegionScoreDetails") {
return Object.getPrototypeOf(window[topLevel]);
}
}
}
})();
for (var topLevel in window) { for (var topLevel in window) {
if (minified.test(topLevel)) { if (minified.test(topLevel)) {
// a minified object - check for minified prototype entries // a minified object - check for minified prototype entries
if (window[topLevel] && window[topLevel].prototype) { var topObject = window[topLevel];
if (topObject && topObject.prototype) {
// the object has a prototype - iterate through the properties of that // the object has a prototype - iterate through the properties of that
for (var secLevel in window[topLevel].prototype) { for (var secLevel in topObject.prototype) {
if (minified.test(secLevel)) { if (minified.test(secLevel)) {
// looks like we've found an object of the format "XX.prototype.YY"... // looks like we've found an object of the format "XX.prototype.YY"...
var item = topObject.prototype[secLevel];
var item = window[topLevel].prototype[secLevel];
if (item && typeof(item) == "function") { if (item && typeof(item) == "function") {
// a function - test it against the relevant regular expressions // a function - test it against the relevant regular expressions
@ -37,63 +51,74 @@ window.extractFromStock = function() {
console.log('Found former CURRENT_VERSION in '+topLevel+'.prototype.'+secLevel); console.log('Found former CURRENT_VERSION in '+topLevel+'.prototype.'+secLevel);
niantic_params.CURRENT_VERSION = match[1]; niantic_params.CURRENT_VERSION = match[1];
} }
}
} }
} }
}
} //end 'if .prototype' } //end 'if .prototype'
// finding the required method names for the botguard interface code // finding the required method names for the botguard interface code
if (window[topLevel] && Object.prototype.toString.call(window[topLevel]) == "[object Array]") { if(topObject && Object.getPrototypeOf(topObject) == requestPrototype) {
// look for all arrays in the top-level namespace var methodKey = Object
.keys(topObject)
.filter(function(key) { return typeof key == "string"; })[0];
var arr = window[topLevel]; for(var secLevel in topObject) {
var onlyStrings = true; if(typeof topObject[secLevel] == "boolean" && topObject[secLevel]) {
if (arr.length > 0) { window.niantic_params.botguard_group_a_methods.push(topObject[methodKey]);
for (var i in arr) {
if (Object.prototype.toString.call(arr[i]) != "[object String]") {
onlyStrings = false;
break;
} }
if(typeof topObject[secLevel] == "boolean" && !topObject[secLevel]) {
console.info("b-action:", topObject[methodKey]);
} }
if (onlyStrings) {
arrays.push(arr);
} }
} }
} // if (window[topLevel] && Object.prototype.toString.call(window[topLevel]) == "[object Array]") {
// // look for all arrays in the top-level namespace
// var arr = window[topLevel];
// var onlyStrings = true;
// if (arr.length > 0) {
// for (var i in arr) {
// if (Object.prototype.toString.call(arr[i]) != "[object String]") {
// onlyStrings = false;
// break;
// }
// }
// if (onlyStrings) {
// arrays.push(arr);
// }
// }
// }
} }
} }
// we extracted a list of string arrays. now, we need to find which ones we want to use // we extracted a list of string arrays. now, we need to find which ones we want to use
// there are two. both contain a list of method names - one is the list of methods protected by either // there are two. both contain a list of method names - one is the list of methods protected by either
// botguard group-a or group-b, while the others is just a list of those in one group // botguard group-a or group-b, while the others is just a list of those in one group
// window.niantic_params.botguard_protected_methods = []; // window.niantic_params.botguard_protected_methods = [];
window.niantic_params.botguard_group_a_methods = [];
var countMethods = function(arr) { //var countMethods = function(arr) {
var methods = ['artifacts', 'getGameScore', 'getPlexts', 'getPortalDetails', 'redeemReward', 'sendInviteEmail', 'sendPlext']; // var count = 0;
var count = 0; // for (var j in arr) {
for (var j in arr) { // if (methods.indexOf(arr[j]) != -1) {
if (methods.indexOf(arr[j]) != -1) { // count++;
count++; // }
} // }
} // return count;
return count; //}
}
// var protectedMethodsCount = 0; // var protectedMethodsCount = 0;
var groupMethodsCount = 0; // var groupMethodsCount = 0;
//
for (var i in arrays) { // for (var i in arrays) {
var arr = arrays[i]; // var arr = arrays[i];
var arrCount = countMethods(arr); // var arrCount = countMethods(arr);
//
// if (arrCount > protectedMethodsCount) { // if (arrCount > protectedMethodsCount) {
// // longest found - copy any existing longest to the 2nd longest // // longest found - copy any existing longest to the 2nd longest
// //
@ -105,13 +130,13 @@ window.extractFromStock = function() {
// protectedMethodsCount = arrCount; // protectedMethodsCount = arrCount;
// //
// } else // } else
if (arrCount > groupMethodsCount) { // if (arrCount > groupMethodsCount) {
// 2nd longest - store // // 2nd longest - store
window.niantic_params.botguard_group_a_methods = arr; // window.niantic_params.botguard_group_a_methods = arr;
groupMethodsCount = arrCount; // groupMethodsCount = arrCount;
} // }
//
} // }
if (niantic_params.CURRENT_VERSION === undefined || window.niantic_params.botguard_group_a_methods.length == 0) { if (niantic_params.CURRENT_VERSION === undefined || window.niantic_params.botguard_group_a_methods.length == 0) {