Functional for zip files!
This commit is contained in:
parent
949d12789c
commit
e674c15ad0
21
README.md
21
README.md
|
@ -5,10 +5,23 @@ Try to find out which Electron version is bundled inside an application.
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
npm install which-electron
|
$ npm install which-electron
|
||||||
which-electron Google.Play.Music.Desktop.Player.OSX.zip
|
$ which-electron Google.Play.Music.Desktop.Player.OSX.zip
|
||||||
which-electron Google.Play.Music.Desktop.Player.OSX.dmg
|
Version Constraint: <v7.0.0
|
||||||
which-electron Google.Play.Music.Desktop.Player.deb
|
Multiple guesses from fingerprinting:
|
||||||
|
[
|
||||||
|
'v3.1.10', 'v3.1.11',
|
||||||
|
'v3.1.12', 'v3.1.13',
|
||||||
|
'v3.1.5', 'v3.1.6',
|
||||||
|
'v3.1.7', 'v3.1.8',
|
||||||
|
'v3.1.9'
|
||||||
|
]
|
||||||
|
|
||||||
|
$ which-electron HashTag-win32-x64.zip
|
||||||
|
Found Version file: v7.1.10
|
||||||
|
Fingerprint: v7.1.10
|
||||||
|
|
||||||
|
$ which-electron Google.Play.Music.Desktop.Player.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
|
@ -1,22 +1,50 @@
|
||||||
const DB = require("electron-fingerprints");
|
const DB = require("electron-fingerprints");
|
||||||
|
const fs = require("fs");
|
||||||
|
const hasha = require('hasha');
|
||||||
|
const allVersions = require('./versions')['all']
|
||||||
|
|
||||||
|
function checksumFile(algorithm, path) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
let fs = require('fs');
|
||||||
|
let crypto = require('crypto');
|
||||||
|
|
||||||
|
let hash = crypto.createHash(algorithm).setEncoding('hex');
|
||||||
|
fs.createReadStream(path)
|
||||||
|
.once('error', reject)
|
||||||
|
.pipe(hash)
|
||||||
|
.once('finish', function () {
|
||||||
|
resolve(hash.read());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
guessFromHashes: function(os, arch, hashList) {
|
guessFromHashes: function(os, arch, hashList) {
|
||||||
let lookupTable = DB[`${os}-${arch}`]
|
let lookupTable = DB[`${os}-${arch}`];
|
||||||
let allPossibleHashes = Object.keys(lookupTable)
|
let allPossibleHashes = Object.keys(lookupTable);
|
||||||
const intersectingHashes = allPossibleHashes.filter((value) =>
|
const intersectingHashes = allPossibleHashes.filter((value) =>
|
||||||
hashList.includes(value)
|
hashList.includes(value)
|
||||||
);
|
);
|
||||||
// Set it to the starting list of versions.
|
// Set it to the starting list of versions.
|
||||||
let possibleVersions = lookupTable[intersectingHashes[0]];
|
let possibleVersions = allVersions;
|
||||||
for (i in hashList) {
|
for (i in hashList) {
|
||||||
let hash = hashList[i];
|
let hash = hashList[i];
|
||||||
let versions = lookupTable[hash];
|
let versions = lookupTable[hash];
|
||||||
possibleVersions = possibleVersions.filter((value) =>
|
if (versions) {
|
||||||
versions.includes(value)
|
possibleVersions = possibleVersions.filter((value) =>
|
||||||
);
|
versions.includes(value)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return possibleVersions;
|
return possibleVersions;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getHashes: function(dir) {
|
||||||
|
let list = fs.readdirSync(dir);
|
||||||
|
return list.map((f) => {
|
||||||
|
let fn = `${dir}/${f}`;
|
||||||
|
return hasha.fromFileSync(fn, {algorithm: 'sha1'})
|
||||||
|
})
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
22
index.js
22
index.js
|
@ -2,6 +2,7 @@ const path = require("path");
|
||||||
const osguess = require("./os");
|
const osguess = require("./os");
|
||||||
const finder = require("./finder");
|
const finder = require("./finder");
|
||||||
const zip = require("./zip");
|
const zip = require("./zip");
|
||||||
|
const fp = require('./fingerprint')
|
||||||
|
|
||||||
// Input file comes from process.argv[2]
|
// Input file comes from process.argv[2]
|
||||||
const FILENAME = process.argv[2];
|
const FILENAME = process.argv[2];
|
||||||
|
@ -14,17 +15,32 @@ zip.listFileContents(FILENAME, (entries)=> {
|
||||||
let versionFiles = finder.version(entries);
|
let versionFiles = finder.version(entries);
|
||||||
let enm = finder.findElectronPackageInsideNodeModules(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) {
|
// if (binary) {
|
||||||
// console.log(`${process.argv[2]}:${binary}`);
|
// console.log(`${process.argv[2]}:${binary}`);
|
||||||
// }
|
// }
|
||||||
if (versionFiles.length > 0) {
|
if (versionFiles.length > 0) {
|
||||||
versionFiles.map((f) => {
|
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) {
|
if (asar.length > 0) {
|
||||||
asar.forEach((a) => {
|
asar.forEach((a) => {
|
||||||
console.log("<v7.0.0")
|
console.log("Version Constraint: <v7.0.0")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (enm) {
|
if (enm) {
|
||||||
|
@ -32,7 +48,7 @@ zip.listFileContents(FILENAME, (entries)=> {
|
||||||
zip.readFileContents(FILENAME, a, (c)=>{
|
zip.readFileContents(FILENAME, a, (c)=>{
|
||||||
try {
|
try {
|
||||||
let packageData = JSON.parse(c)
|
let packageData = JSON.parse(c)
|
||||||
console.log(packageData['version'])
|
console.log("Found version in package.json file: " + packageData['version'])
|
||||||
}catch(e){
|
}catch(e){
|
||||||
// TODO: Do something
|
// TODO: Do something
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"asar": "^3.0.3",
|
"asar": "^3.0.3",
|
||||||
"electron-fingerprints": "^1.0.0",
|
"electron-fingerprints": "^1.0.0",
|
||||||
"elfinfo": "*",
|
"elfinfo": "*",
|
||||||
|
"hasha": "^5.2.2",
|
||||||
"macho": "^1.4.0",
|
"macho": "^1.4.0",
|
||||||
"node-7z": "^3.0.0"
|
"node-7z": "^3.0.0"
|
||||||
},
|
},
|
||||||
|
@ -191,6 +192,21 @@
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
"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": {
|
"node_modules/inflight": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
"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": {
|
"node_modules/kuta": {
|
||||||
"version": "2.0.0-beta.6",
|
"version": "2.0.0-beta.6",
|
||||||
"resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz",
|
"resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz",
|
||||||
|
@ -367,6 +391,14 @@
|
||||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
@ -509,6 +541,15 @@
|
||||||
"path-is-absolute": "^1.0.0"
|
"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": {
|
"inflight": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
"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": {
|
"kuta": {
|
||||||
"version": "2.0.0-beta.6",
|
"version": "2.0.0-beta.6",
|
||||||
"resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz",
|
"resolved": "https://registry.npmjs.org/kuta/-/kuta-2.0.0-beta.6.tgz",
|
||||||
|
@ -658,6 +704,11 @@
|
||||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
||||||
"dev": true
|
"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": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
"asar": "^3.0.3",
|
"asar": "^3.0.3",
|
||||||
"electron-fingerprints": "^1.0.0",
|
"electron-fingerprints": "^1.0.0",
|
||||||
"elfinfo": "*",
|
"elfinfo": "*",
|
||||||
|
"hasha": "^5.2.2",
|
||||||
"macho": "^1.4.0",
|
"macho": "^1.4.0",
|
||||||
"node-7z": "^3.0.0"
|
"node-7z": "^3.0.0"
|
||||||
},
|
},
|
||||||
|
|
9
zip.js
9
zip.js
|
@ -14,6 +14,15 @@ module.exports = {
|
||||||
cb(fs.readFileSync(`/tmp/${fn}`, {encoding: 'utf8'}))
|
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) {
|
listFileContents: function(archive, cb) {
|
||||||
let zip = Seven.list(archive);
|
let zip = Seven.list(archive);
|
||||||
let entries = [];
|
let entries = [];
|
||||||
|
|
Loading…
Reference in New Issue