Finish implement js field

main
Camille Barneaud 7 years ago
parent 7d268ed8a3
commit 9ba4c7ea85

@ -35,7 +35,25 @@ if ( typeof browser !== 'undefined' && typeof document.body !== 'undefined' ) {
script.setAttribute('id', 'wappalyzerEnvDetection'); script.setAttribute('id', 'wappalyzerEnvDetection');
script.setAttribute('src', browser.extension.getURL('js/inject.js')); script.setAttribute('src', browser.extension.getURL('js/inject.js'));
container.addEventListener('wappalyzerEvent', (event => { container.addEventListener('wappalyzerEnvEvent', (event => {
browser.runtime.sendMessage({
id: 'JS_ready',
subject: { },
source: 'content.js'
}, response => {
window.postMessage({patterns: response.patterns}, "*");
});
window.addEventListener('message', (event => {
if (event.data.js === undefined)
return;
var js = event.data.js ;
browser.runtime.sendMessage({
id: 'analyze',
subject: { js },
source: 'content.js'
});
}), true);
var env = event.target.childNodes[0].nodeValue; var env = event.target.childNodes[0].nodeValue;
document.documentElement.removeChild(container); document.documentElement.removeChild(container);

@ -1,42 +1,33 @@
(function() { (function() {
try { try {
var i, environmentVars = '', e = document.createEvent('Events'); var i, environmentVars = '', eEnv = document.createEvent('Events'), container = document.getElementById('wappalyzerData');
e.initEvent('wappalyzerEvent', true, false); eEnv.initEvent('wappalyzerEnvEvent', true, false);
for ( i in window ) { for ( i in window ) {
environmentVars += i + ' '; environmentVars += i + ' ';
} }
container.appendChild(document.createComment(environmentVars));
container.dispatchEvent(eEnv);
document.getElementById('wappalyzerData').appendChild(document.createComment(environmentVars)); window.addEventListener('message', (event => {
document.getElementById('wappalyzerData').dispatchEvent(e); if (event.data.patterns === undefined)
return;
// Handle property match var properties = event.data.patterns;
browser.runtime.sendMessage({
id: 'JS_ready',
subject: { },
source: 'inject.js'
}, response => {
var properties = response.patterns;
var js = {}; var js = {};
Object.keys(properties).forEach(app => { Object.keys(properties).forEach(appname => {
Object.keys(properties[app]).forEach(property => { Object.keys(properties[appname]).forEach(property => {
var content = false; var content = false;
if( content = JSdetection(property) ){ if( content = JSdetection(property) ){
if ( js[appname] === undefined ) { if ( js[appname] === undefined )
js[appname] = {}; js[appname] = {};
} js[appname][property] = properties[appname][property];
js[appname][property] = properties[app][property];
js[appname][property]["content"] = content; js[appname][property]["content"] = content;
} }
}); });
}); });
browser.runtime.sendMessage({ window.postMessage({js: js}, "*");
id: 'analyze', }), false);
subject: { js },
source: 'inject.js'
});
});
} catch(e) { } catch(e) {
// Fail quietly // Fail quietly
} }
@ -49,4 +40,4 @@ function JSdetection(p){
}, window); }, window);
return typeof value === 'string' ? value : !!value; return typeof value === 'string' ? value : !!value;
} }

@ -18,7 +18,7 @@ class Wappalyzer {
this.apps = {}; this.apps = {};
this.categories = {}; this.categories = {};
this.driver = {}; this.driver = {};
this.parsedJS = {}; this.parsedJS = undefined;
this.detected = {}; this.detected = {};
this.hostnameCache = {}; this.hostnameCache = {};
@ -85,7 +85,7 @@ class Wappalyzer {
if ( data.js ) { if ( data.js ) {
Object.keys(data.js).forEach(appName => { Object.keys(data.js).forEach(appName => {
this.analyzeJS(this.apps[appname], data.js[appname]) this.analyzeJS(apps[appName], data.js[appName]);
}); });
} }
@ -255,14 +255,13 @@ class Wappalyzer {
* Parse JS patterns * Parse JS patterns
*/ */
parseJS() { parseJS() {
if ( this.parsedJS == {} ){ if ( this.parsedJS === undefined){
this.parsedJS = {};
Object.keys(this.apps).forEach(appName => { Object.keys(this.apps).forEach(appName => {
if (apps[appName].props.js){ if (this.apps[appName].js)
parsedJS[appName] = this.parsePatterns(apps[appName].props.js); this.parsedJS[appName] = this.parsePatterns(this.apps[appName].js);
}
}); });
} }
return this.parsedJS
} }
resolveExcludes(apps) { resolveExcludes(apps) {

Loading…
Cancel
Save