From e674c15ad008e98aeeae634d67822ef593fa9c5e Mon Sep 17 00:00:00 2001 From: Nemo Date: Fri, 16 Jul 2021 20:16:29 +0530 Subject: [PATCH] Functional for zip files! --- README.md | 21 +++++++++++++++---- fingerprint.js | 40 +++++++++++++++++++++++++++++++------ index.js | 22 +++++++++++++++++--- package-lock.json | 51 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + zip.js | 9 +++++++++ 6 files changed, 131 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 615e0df..9e0d151 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,23 @@ Try to find out which Electron version is bundled inside an application. ## Usage ```shell -npm install which-electron -which-electron Google.Play.Music.Desktop.Player.OSX.zip -which-electron Google.Play.Music.Desktop.Player.OSX.dmg -which-electron Google.Play.Music.Desktop.Player.deb +$ npm install which-electron +$ which-electron Google.Play.Music.Desktop.Player.OSX.zip +Version Constraint: hashList.includes(value) ); // Set it to the starting list of versions. - let possibleVersions = lookupTable[intersectingHashes[0]]; + let possibleVersions = allVersions; for (i in hashList) { let hash = hashList[i]; let versions = lookupTable[hash]; - possibleVersions = possibleVersions.filter((value) => - versions.includes(value) - ); + if (versions) { + possibleVersions = possibleVersions.filter((value) => + versions.includes(value) + ); + } } return possibleVersions; }, + + getHashes: function(dir) { + let list = fs.readdirSync(dir); + return list.map((f) => { + let fn = `${dir}/${f}`; + return hasha.fromFileSync(fn, {algorithm: 'sha1'}) + }) + }, }; diff --git a/index.js b/index.js index a3d38e9..58e9df6 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const path = require("path"); const osguess = require("./os"); const finder = require("./finder"); const zip = require("./zip"); +const fp = require('./fingerprint') // Input file comes from process.argv[2] const FILENAME = process.argv[2]; @@ -14,17 +15,32 @@ zip.listFileContents(FILENAME, (entries)=> { let versionFiles = finder.version(entries); let enm = finder.findElectronPackageInsideNodeModules(entries); + let filesToHash = finder.fingerprintable(entries) + + zip.extractSomeFiles(FILENAME, filesToHash, (dir)=>{ + hashes = fp.getHashes(dir) + guesses = fp.guessFromHashes('win32', 'x64', hashes) + if (guesses.length == 1) { + console.log("Fingerprint: " + guesses[0]) + } else { + console.log("Multiple guesses from fingerprinting:") + console.log(guesses) + } + }) + // if (binary) { // console.log(`${process.argv[2]}:${binary}`); // } if (versionFiles.length > 0) { versionFiles.map((f) => { - zip.readFileContents(FILENAME, f, (c)=>console.log(c)) + zip.readFileContents(FILENAME, f, (c)=>{ + console.log("Found Version file: v" + c) + }) }); } if (asar.length > 0) { asar.forEach((a) => { - console.log(" { zip.readFileContents(FILENAME, a, (c)=>{ try { let packageData = JSON.parse(c) - console.log(packageData['version']) + console.log("Found version in package.json file: " + packageData['version']) }catch(e){ // TODO: Do something } diff --git a/package-lock.json b/package-lock.json index 3cb6e7b..4955f3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "asar": "^3.0.3", "electron-fingerprints": "^1.0.0", "elfinfo": "*", + "hasha": "^5.2.2", "macho": "^1.4.0", "node-7z": "^3.0.0" }, @@ -191,6 +192,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/hasha": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz", + "integrity": "sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==", + "dependencies": { + "is-stream": "^2.0.0", + "type-fest": "^0.8.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -205,6 +221,14 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, + "node_modules/is-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", + "engines": { + "node": ">=8" + } + }, "node_modules/kuta": { "version": "2.0.0-beta.6", "resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz", @@ -367,6 +391,14 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", "dev": true }, + "node_modules/type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "engines": { + "node": ">=8" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -509,6 +541,15 @@ "path-is-absolute": "^1.0.0" } }, + "hasha": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz", + "integrity": "sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==", + "requires": { + "is-stream": "^2.0.0", + "type-fest": "^0.8.0" + } + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -523,6 +564,11 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, + "is-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==" + }, "kuta": { "version": "2.0.0-beta.6", "resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz", @@ -658,6 +704,11 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", "dev": true }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==" + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index c26baf0..3c185b1 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "asar": "^3.0.3", "electron-fingerprints": "^1.0.0", "elfinfo": "*", + "hasha": "^5.2.2", "macho": "^1.4.0", "node-7z": "^3.0.0" }, diff --git a/zip.js b/zip.js index 117b850..594139c 100644 --- a/zip.js +++ b/zip.js @@ -14,6 +14,15 @@ module.exports = { cb(fs.readFileSync(`/tmp/${fn}`, {encoding: 'utf8'})) }); }, + extractSomeFiles: function(archive, list, cb) { + let dir = fs.mkdtempSync('/tmp/which-electron') + let stream = Seven.extract(archive, dir, { + $cherryPick: list + }) + stream.on('end', ()=>{ + cb(dir) + }) + }, listFileContents: function(archive, cb) { let zip = Seven.list(archive); let entries = [];