Get it working for some files

This commit is contained in:
Nemo 2021-07-15 21:36:12 +05:30
parent a57a42b092
commit 422cd3a254
5 changed files with 109 additions and 44 deletions

View File

@ -5,7 +5,7 @@ const isDirectory = require('./utils').isDirectory;
module.exports = {
// Finds the electron asar file, if we can
asar: function(entries) {
return Object.values(entries)
return entries
.filter((e) => {
return (
isDirectory(e.attributes) == false &&

View File

@ -1,36 +1,32 @@
const Seven = require("node-7z");
const path = require("path");
const osguess = require("./os");
const finder = require("./finder");
const zip = require("./zip");
// Input file comes from process.argv[2]
const FILENAME = process.argv[2];
console.log(FILENAME)
const zip = Seven.list(FILENAME);
entries = [];
zip.on("data", (data) => {
entries.push(data);
});
zip.on("end", () => {
zip.listFileContents(FILENAME, (entries)=> {
let asar = finder.asar(entries);
let binary = finder.binary(entries);
let versionFiles = finder.version(entries);
let enm = finder.findElectronPackageInsideNodeModules(entries);
if (asar.length > 0) {
asar.forEach((a) => {
console.log(`${process.argv[2]}:${a}`);
});
}
if (binary) {
console.log(`${process.argv[2]}:${binary}`);
}
// if (asar.length > 0) {
// asar.forEach((a) => {
// console.log(`${process.argv[2]}:${a}`);
// });
// }
// if (binary) {
// console.log(`${process.argv[2]}:${binary}`);
// }
if (versionFiles.length > 0) {
versionFiles.forEach((a) => {
console.log(`${process.argv[2]}:${a}`);
versionFiles.map((f) => {
zip.readFileContents(FILENAME, f, (c)=>console.log(c))
});
}
if (enm) {
enm.forEach((a) => console.log(`${process.argv[2]}:${a}`));
}
// if (enm) {
// enm.forEach((a) => {
// zip.readFileContents(FILENAME, a, (c)=>console.log(c))
// });
// }
});

76
package-lock.json generated
View File

@ -10,8 +10,9 @@
"dependencies": {
"asar": "^3.0.3",
"elfinfo": "*",
"node-7z": "^3.0.0",
"node-stream-zip": "^1.13.6"
"elfy": "^1.0.0",
"macho": "^1.4.0",
"node-7z": "^3.0.0"
}
},
"node_modules/@types/glob": {
@ -117,6 +118,24 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.5.tgz",
"integrity": "sha512-bjqH2cX/O33jXT/UmReo2pM7DIJREPMnarixbQ57DOOzzFaI6D2+IcwaJQaJpv0M1E9TIhPCYVxrkcityLjlqA=="
},
"node_modules/elfy": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/elfy/-/elfy-1.0.0.tgz",
"integrity": "sha512-4Kp3AA94jC085IJox+qnvrZ3PudqTi4gQNvIoTZfJJ9IqkRuCoqP60vCVYlIg00c5aYusi5Wjh2bf0cHYt+6gQ==",
"dependencies": {
"endian-reader": "^0.3.0"
}
},
"node_modules/elfy/node_modules/endian-reader": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.3.0.tgz",
"integrity": "sha1-hOykNrgK7Q0GOcRykTOLky7+UKA="
},
"node_modules/endian-reader": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.1.0.tgz",
"integrity": "sha1-7tYexWSqX2KFJI82JF4siRVtlKw="
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -180,6 +199,14 @@
"resolved": "https://registry.npmjs.org/lodash.negate/-/lodash.negate-3.0.2.tgz",
"integrity": "sha1-nIl7C/YQAZ4LQ7j/Pwr+89e2bzQ="
},
"node_modules/macho": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/macho/-/macho-1.4.0.tgz",
"integrity": "sha512-PT3YMEKYogCeVYEA2bCFRZASNyn/JaOhjq6eV8SzBQ3RFia7XU8ASQCgGx+f3RnJFHT+xavLP+Qds48jQb0J5Q==",
"dependencies": {
"endian-reader": "^0.1.0"
}
},
"node_modules/minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
@ -213,18 +240,6 @@
"node": ">=10"
}
},
"node_modules/node-stream-zip": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.13.6.tgz",
"integrity": "sha512-c7tRSVkLNOHvasWgmZ2d86cDgTWEygnkuuHNOY9c0mR3yLZtQTTrGvMaJ/fPs6+LOJn3240y30l5sjLaXFtcvw==",
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/antelle"
}
},
"node_modules/normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
@ -342,6 +357,26 @@
}
}
},
"elfy": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/elfy/-/elfy-1.0.0.tgz",
"integrity": "sha512-4Kp3AA94jC085IJox+qnvrZ3PudqTi4gQNvIoTZfJJ9IqkRuCoqP60vCVYlIg00c5aYusi5Wjh2bf0cHYt+6gQ==",
"requires": {
"endian-reader": "^0.3.0"
},
"dependencies": {
"endian-reader": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.3.0.tgz",
"integrity": "sha1-hOykNrgK7Q0GOcRykTOLky7+UKA="
}
}
},
"endian-reader": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.1.0.tgz",
"integrity": "sha1-7tYexWSqX2KFJI82JF4siRVtlKw="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -399,6 +434,14 @@
"resolved": "https://registry.npmjs.org/lodash.negate/-/lodash.negate-3.0.2.tgz",
"integrity": "sha1-nIl7C/YQAZ4LQ7j/Pwr+89e2bzQ="
},
"macho": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/macho/-/macho-1.4.0.tgz",
"integrity": "sha512-PT3YMEKYogCeVYEA2bCFRZASNyn/JaOhjq6eV8SzBQ3RFia7XU8ASQCgGx+f3RnJFHT+xavLP+Qds48jQb0J5Q==",
"requires": {
"endian-reader": "^0.1.0"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
@ -426,11 +469,6 @@
"normalize-path": "^3.0.0"
}
},
"node-stream-zip": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.13.6.tgz",
"integrity": "sha512-c7tRSVkLNOHvasWgmZ2d86cDgTWEygnkuuHNOY9c0mR3yLZtQTTrGvMaJ/fPs6+LOJn3240y30l5sjLaXFtcvw=="
},
"normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",

View File

@ -3,6 +3,9 @@
"version": "1.0.0",
"description": "Guess which electron version is bundled in an application",
"main": "index.js",
"bin": {
"which-electron": "index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@ -26,7 +29,8 @@
"dependencies": {
"asar": "^3.0.3",
"elfinfo": "*",
"node-7z": "^3.0.0",
"node-stream-zip": "^1.13.6"
"elfy": "^1.0.0",
"macho": "^1.4.0",
"node-7z": "^3.0.0"
}
}

27
zip.js Normal file
View File

@ -0,0 +1,27 @@
const Seven = require("node-7z");
const path = require("path");
const fs = require("fs");
module.exports = {
readFileContents: function(archive, filepath, cb) {
// TODO: Create a new temp directory
let stream = Seven.extract(archive, "/tmp", {
recursive: true,
$cherryPick: filepath,
});
let fn = path.basename(filepath);
stream.on("end", ()=>{
cb(fs.readFileSync(`/tmp/${fn}`, {encoding: 'utf8'}))
});
},
listFileContents: function(archive, cb) {
let zip = Seven.list(archive);
let entries = [];
zip.on("data", (data) => {
entries.push(data);
});
zip.on("end", () => {
cb(entries);
});
},
};