-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappanalytics.js
65 lines (56 loc) · 2.39 KB
/
appanalytics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const {
loadPatterns,
resolveExcludes,
resolveImplies,
parsePatterns,
displayApps,
preParsePatterns
} = require('./modules/patterns');
const CookieAnalyzer = require('./modules/cookies');
const MetaAnalyzer = require('./modules/meta');
const HtmlAnalyzer = require('./modules/html');
const HeadersAnalyzer = require('./modules/headers');
const ScriptAnalyzer = require('./modules/script');
const JsAnalyzer = require('./modules/js');
class AppAnalytics {
async loadAppsjson(appjson) {
//console.time('load');
const patternRaw = await loadPatterns(appjson);
this.categories = patternRaw.categories;
this.apps = preParsePatterns(patternRaw.apps);
this.cookieAnalyzer = new CookieAnalyzer(this.apps);
this.metaAnalyzer = new MetaAnalyzer(this.apps);
this.htmlAnalyzer = new HtmlAnalyzer(this.apps);
this.headersAnalyzer = new HeadersAnalyzer(this.apps);
this.scriptAnalyzer = new ScriptAnalyzer(this.apps);
this.jsAnalyzer = new JsAnalyzer(this.apps);
this.langMetaRegex = new RegExp('<html[^>]*[: ]lang="([a-z]{2}((-|_)[A-Z]{2})?)"', 'i');
//console.timeEnd('load');
}
async runAnalytics(page, html, scripts, cookies, headers) {
let foundApps = {};
//console.time('processing');
/**
* Original wappalyzer flow
* - html, meta, scripts, cookies, headers, js
* - excludes,implies
* - displayapps
*/
foundApps = await this.htmlAnalyzer.analyzeHtml(html, foundApps);
foundApps = await this.metaAnalyzer.analyzeHtml(html, foundApps);
foundApps = await this.scriptAnalyzer.analyzeScripts(scripts, foundApps);
foundApps = await this.cookieAnalyzer.analyze(page, foundApps);
foundApps = await this.headersAnalyzer.analyzeHeaders(headers, foundApps);
foundApps = await this.jsAnalyzer.analyze(page, foundApps);
foundApps = await resolveExcludes(foundApps, this.apps);
foundApps = await resolveImplies(foundApps, this.apps);
// some meta
const meta = {};
let matches = html.match(this.langMetaRegex);
meta.language = matches && matches.length ? matches[1] : null;
const result = displayApps('url', foundApps, this.apps, this.categories, meta);
//console.timeEnd('processing');
return result;
}
}
module.exports = AppAnalytics;