Performance improvements

main
Elbert Alias 12 years ago
parent 758afea8e3
commit 52ba2d69c1

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -2,33 +2,37 @@
(function() { (function() {
var var
lastEnv = null, data = {},
prefs = {} lastEnv = [],
prefs = null
; ;
addEventListener('DOMContentLoaded', function() { addEventListener('DOMContentLoaded', function() {
removeEventListener('DOMContentLoaded', onLoad, false); removeEventListener('DOMContentLoaded', onLoad, false);
if ( prefs != null || content.document.contentType != 'text/html' ) {
return;
}
prefs = sendSyncMessage('wappalyzer', { action: 'get prefs' })[0]; prefs = sendSyncMessage('wappalyzer', { action: 'get prefs' })[0];
onLoad(); onLoad();
}, false); }, false);
function onLoad() { function onLoad() {
if ( content.document.contentType != 'text/html' ) { return; } if ( prefs.analyzeJavaScript && prefs.analyzeOnLoad ) {
if ( prefs.analyzeOnLoad ) {
content.document.documentElement.addEventListener('load', function() { content.document.documentElement.addEventListener('load', function() {
var env = Object.keys(content.wrappedJSObject); var env = Object.keys(content.wrappedJSObject);
if ( env.join() !== lastEnv ) { // Only analyze new variables
lastEnv = env.join(); data = { env: env.filter(function(i) { return lastEnv.indexOf(i) === -1; }) };
lastEnv = env;
if ( data.env.length ) {
sendAsyncMessage('wappalyzer', { sendAsyncMessage('wappalyzer', {
action: 'analyze', action: 'analyze',
analyze: { analyze: data
env: Object.keys(content.wrappedJSObject)
}
}); });
} }
@ -48,14 +52,17 @@
html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length); html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length);
} }
data = { html: html };
if ( prefs.analyzeJavaScript ) {
data.env = Object.keys(content.wrappedJSObject);
}
sendAsyncMessage('wappalyzer', { sendAsyncMessage('wappalyzer', {
action: 'analyze', action: 'analyze',
hostname: content.location.hostname, hostname: content.location.hostname,
url: content.location.href, url: content.location.href,
analyze: { analyze: data
html: html,
env: prefs.analyzeJavaScript ? Object.keys(content.wrappedJSObject) : []
}
}); });
} }
})(); })();

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -92,60 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
// Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue;
}
next:
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; } regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = new RegExp(w.apps[app][type], 'i');
regex = /<script[^>]+src=("|')([^"']+)\1/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) { profiler.regexCount ++;
if ( regex.test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -153,25 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) { profiler.regexCount ++;
if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -180,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -247,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

@ -92,67 +92,107 @@ var wappalyzer = wappalyzer || (function() {
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
w.log('w.analyze'); w.log('w.analyze');
data.url = url;
if ( w.apps == null || w.categories == null ) { if ( w.apps == null || w.categories == null ) {
w.log('apps.json not loaded'); w.log('apps.json not loaded');
return; return;
} }
var i, app, type, regex, match, content, meta, header, apps = []; if ( w.detected[url] == null ) {
w.detected[url] = [];
}
if ( w.detected[url] == null ) { w.detected[url] = []; } var
i, app, type, regex, match, content, meta, header,
profiler = {
regexCount: 0,
startTime: ( new Date ).getTime()
},
apps = []
;
if ( data ) {
for ( app in w.apps ) { for ( app in w.apps ) {
for ( type in w.apps[app] ) {
// Skip if the app has already been detected // Skip if the app has already been detected
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) {
continue; continue;
} }
next:
for ( type in w.apps[app] ) {
if ( data[type] == null ) {
continue;
}
switch ( type ) { switch ( type ) {
case 'url': case 'url':
regex = new RegExp(w.apps[app][type], 'i'); regex = new RegExp(w.apps[app][type], 'i');
if ( regex.test(url) ) { apps.push(app); } profiler.regexCount ++;
if ( regex.test(url) ) {
apps.push(app);
break next;
}
break; break;
case 'html': case 'html':
if ( data[type] == null ) { break; }
regex = new RegExp(w.apps[app][type], 'i'); regex = new RegExp(w.apps[app][type], 'i');
if ( regex.test(data[type]) ) { apps.push(app); } profiler.regexCount ++;
if ( regex.test(data[type]) ) {
apps.push(app);
break next;
}
break; break;
case 'script': case 'script':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<script[^>]+src=("|')([^"']+)\1/ig; regex = new RegExp(w.apps[app][type], 'i');
profiler.regexCount ++;
while ( match = new RegExp('<script[^>]+src=("|\')([^"\']+)\1', 'ig').exec(data['html']) ) {
profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { if ( regex.test(match[2]) ) {
if ( w.apps[app][type].test(match[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'meta': case 'meta':
if ( data['html'] == null ) { break; } if ( data['html'] == null ) {
break;
}
regex = /<meta[^>]+>/ig; profiler.regexCount ++;
while ( match = regex.exec(data['html']) ) { while ( match = new RegExp('<meta[^>]+>', 'ig').exec(data['html']) ) {
for ( meta in w.apps[app][type] ) { for ( meta in w.apps[app][type] ) {
profiler.regexCount ++;
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i); content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) { regex = new RegExp(w.apps[app].meta[meta], 'i');
profiler.regexCount ++;
if ( content && content.length === 4 && regex.test(content[2]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
} }
@ -160,29 +200,37 @@ var wappalyzer = wappalyzer || (function() {
break; break;
case 'headers': case 'headers':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
for ( header in w.apps[app].headers ) { for ( header in w.apps[app].headers ) {
regex = new RegExp(w.apps[app][type][header], 'i'); regex = new RegExp(w.apps[app][type][header], 'i');
profiler.regexCount ++;
if ( data[type][header] != null && regex.test(data[type][header]) ) { if ( data[type][header] != null && regex.test(data[type][header]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
break; break;
case 'env': case 'env':
if ( data[type] == null ) { break; } if ( data[type] == null ) {
break;
}
regex = RegExp(w.apps[app][type], 'i'); regex = RegExp(w.apps[app][type], 'i');
for ( i in data[type] ) { for ( i in data[type] ) {
profiler.regexCount ++;
if ( regex.test(data[type][i]) ) { if ( regex.test(data[type][i]) ) {
apps.push(app); apps.push(app);
break; break next;
} }
} }
@ -191,6 +239,8 @@ var wappalyzer = wappalyzer || (function() {
} }
} }
w.log('Tested ' + profiler.regexCount + ' regular expressions in ' + ( ( ( new Date ).getTime() - profiler.startTime ) / 1000 ) + 's');
// Implied applications // Implied applications
var i, j, k, implied; var i, j, k, implied;
@ -258,7 +308,6 @@ var wappalyzer = wappalyzer || (function() {
apps = null; apps = null;
data = null; data = null;
}
driver('displayApps'); driver('displayApps');
} }

Loading…
Cancel
Save