This commit is contained in:
2022-09-30 05:39:11 +00:00
parent 41ee9463ae
commit 4687fa49bc
11418 changed files with 1312504 additions and 0 deletions

View File

@ -0,0 +1,2 @@
export declare function readAsar(archive: string): Promise<AsarFilesystem>;
export declare function readAsarJson(archive: string, file: string): Promise<any>;

View File

@ -0,0 +1,213 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.readAsar = readAsar;
exports.readAsarJson = readAsarJson;
exports.AsarFilesystem = exports.Node = void 0;
function _chromiumPickleJs() {
const data = require("chromium-pickle-js");
_chromiumPickleJs = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/** @internal */
class Node {}
/** @internal */
exports.Node = Node;
class AsarFilesystem {
constructor(src, header = new Node(), headerSize = -1) {
this.src = src;
this.header = header;
this.headerSize = headerSize;
this.offset = 0;
if (this.header.files == null) {
this.header.files = {};
}
}
searchNodeFromDirectory(p, isCreate) {
let node = this.header;
for (const dir of p.split(path.sep)) {
if (dir !== ".") {
let child = node.files[dir];
if (child == null) {
if (!isCreate) {
return null;
}
child = new Node();
child.files = {};
node.files[dir] = child;
}
node = child;
}
}
return node;
}
getOrCreateNode(p) {
if (p == null || p.length === 0) {
return this.header;
}
const name = path.basename(p);
const dirNode = this.searchNodeFromDirectory(path.dirname(p), true);
if (dirNode.files == null) {
dirNode.files = {};
}
let result = dirNode.files[name];
if (result == null) {
result = new Node();
dirNode.files[name] = result;
}
return result;
}
addFileNode(file, dirNode, size, unpacked, stat) {
if (size > 4294967295) {
throw new Error(`${file}: file size cannot be larger than 4.2GB`);
}
const node = new Node();
node.size = size;
if (unpacked) {
node.unpacked = true;
} else {
// electron expects string
node.offset = this.offset.toString();
if (process.platform !== "win32" && stat.mode & 0o100) {
node.executable = true;
}
this.offset += node.size;
}
let children = dirNode.files;
if (children == null) {
children = {};
dirNode.files = children;
}
children[path.basename(file)] = node;
return node;
}
getNode(p) {
const node = this.searchNodeFromDirectory(path.dirname(p), false);
return node.files[path.basename(p)];
}
getFile(p, followLinks = true) {
const info = this.getNode(p); // if followLinks is false we don't resolve symlinks
return followLinks && info.link != null ? this.getFile(info.link) : info;
}
async readJson(file) {
return JSON.parse((await this.readFile(file)).toString());
}
readFile(file) {
return readFileFromAsar(this, file, this.getFile(file));
}
}
exports.AsarFilesystem = AsarFilesystem;
async function readAsar(archive) {
const fd = await (0, _fsExtra().open)(archive, "r");
let size;
let headerBuf;
try {
const sizeBuf = Buffer.allocUnsafe(8);
if ((await (0, _fsExtra().read)(fd, sizeBuf, 0, 8, null)).bytesRead !== 8) {
throw new Error("Unable to read header size");
}
const sizePickle = (0, _chromiumPickleJs().createFromBuffer)(sizeBuf);
size = sizePickle.createIterator().readUInt32();
headerBuf = Buffer.allocUnsafe(size);
if ((await (0, _fsExtra().read)(fd, headerBuf, 0, size, null)).bytesRead !== size) {
throw new Error("Unable to read header");
}
} finally {
await (0, _fsExtra().close)(fd);
}
const headerPickle = (0, _chromiumPickleJs().createFromBuffer)(headerBuf);
const header = headerPickle.createIterator().readString();
return new AsarFilesystem(archive, JSON.parse(header), size);
}
async function readAsarJson(archive, file) {
const fs = await readAsar(archive);
return await fs.readJson(file);
}
async function readFileFromAsar(filesystem, filename, info) {
const size = info.size;
const buffer = Buffer.allocUnsafe(size);
if (size <= 0) {
return buffer;
}
if (info.unpacked) {
return await (0, _fsExtra().readFile)(path.join(`${filesystem.src}.unpacked`, filename));
}
const fd = await (0, _fsExtra().open)(filesystem.src, "r");
try {
const offset = 8 + filesystem.headerSize + parseInt(info.offset, 10);
await (0, _fsExtra().read)(fd, buffer, 0, size, offset);
} finally {
await (0, _fsExtra().close)(fd);
}
return buffer;
}
// __ts-babel@6.0.4
//# sourceMappingURL=asar.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.checkFileInArchive = checkFileInArchive;
function _fs() {
const data = require("builder-util/out/fs");
_fs = function () {
return data;
};
return data;
}
function _asar() {
const data = require("./asar");
_asar = function () {
return data;
};
return data;
}
/** @internal */
async function checkFileInArchive(asarFile, relativeFile, messagePrefix) {
function error(text) {
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`);
}
let fs;
try {
fs = await (0, _asar().readAsar)(asarFile);
} catch (e) {
throw error(`is corrupted: ${e}`);
}
let stat;
try {
stat = fs.getFile(relativeFile);
} catch (e) {
const fileStat = await (0, _fs().statOrNull)(asarFile);
if (fileStat == null) {
throw error(`does not exist. Seems like a wrong configuration.`);
} // asar throws error on access to undefined object (info.link)
stat = null;
}
if (stat == null) {
throw error(`does not exist. Seems like a wrong configuration.`);
}
if (stat.size === 0) {
throw error(`is corrupted: size 0`);
}
}
// __ts-babel@6.0.4
//# sourceMappingURL=asarFileChecker.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/asar/asarFileChecker.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AACO,eAAe,kBAAf,CAAkC,QAAlC,EAAoD,YAApD,EAA0E,aAA1E,EAA+F;AACpG,WAAS,KAAT,CAAe,IAAf,EAA2B;AACzB,WAAO,IAAI,KAAJ,CAAU,GAAG,aAAa,KAAK,YAAY,aAAa,QAAQ,KAAK,IAAI,EAAzE,CAAP;AACD;;AAED,MAAI,EAAJ;;AACA,MAAI;AACF,IAAA,EAAE,GAAG,MAAM,sBAAS,QAAT,CAAX;AACD,GAFD,CAGA,OAAO,CAAP,EAAU;AACR,UAAM,KAAK,CAAC,iBAAiB,CAAC,EAAnB,CAAX;AACD;;AAED,MAAI,IAAJ;;AACA,MAAI;AACF,IAAA,IAAI,GAAG,EAAE,CAAC,OAAH,CAAW,YAAX,CAAP;AACD,GAFD,CAGA,OAAO,CAAP,EAAU;AACR,UAAM,QAAQ,GAAG,MAAM,sBAAW,QAAX,CAAvB;;AACA,QAAI,QAAQ,IAAI,IAAhB,EAAsB;AACpB,YAAM,KAAK,CAAC,mDAAD,CAAX;AACD,KAJO,CAMR;;;AACA,IAAA,IAAI,GAAG,IAAP;AACD;;AAED,MAAI,IAAI,IAAI,IAAZ,EAAkB;AAChB,UAAM,KAAK,CAAC,mDAAD,CAAX;AACD;;AACD,MAAI,IAAI,CAAC,IAAL,KAAc,CAAlB,EAAqB;AACnB,UAAM,KAAK,CAAC,sBAAD,CAAX;AACD;AACF,C","sourcesContent":["import { statOrNull } from \"builder-util/out/fs\"\nimport { Node, readAsar } from \"./asar\"\n\n/** @internal */\nexport async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {\n function error(text: string) {\n return new Error(`${messagePrefix} \"${relativeFile}\" in the \"${asarFile}\" ${text}`)\n }\n\n let fs\n try {\n fs = await readAsar(asarFile)\n }\n catch (e) {\n throw error(`is corrupted: ${e}`)\n }\n\n let stat: Node | null\n try {\n stat = fs.getFile(relativeFile)\n }\n catch (e) {\n const fileStat = await statOrNull(asarFile)\n if (fileStat == null) {\n throw error(`does not exist. Seems like a wrong configuration.`)\n }\n\n // asar throws error on access to undefined object (info.link)\n stat = null\n }\n\n if (stat == null) {\n throw error(`does not exist. Seems like a wrong configuration.`)\n }\n if (stat.size === 0) {\n throw error(`is corrupted: size 0`)\n }\n}\n"],"sourceRoot":""}

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,347 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AsarPackager = void 0;
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _fs() {
const data = require("builder-util/out/fs");
_fs = function () {
return data;
};
return data;
}
var _fs2 = require("fs");
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _appFileCopier() {
const data = require("../util/appFileCopier");
_appFileCopier = function () {
return data;
};
return data;
}
function _asar() {
const data = require("./asar");
_asar = function () {
return data;
};
return data;
}
function _unpackDetector() {
const data = require("./unpackDetector");
_unpackDetector = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pickle = require("chromium-pickle-js");
/** @internal */
class AsarPackager {
constructor(src, destination, options, unpackPattern) {
this.src = src;
this.destination = destination;
this.options = options;
this.unpackPattern = unpackPattern;
this.fs = new (_asar().AsarFilesystem)(this.src);
this.outFile = path.join(destination, "app.asar");
this.unpackedDest = `${this.outFile}.unpacked`;
} // sort files to minimize file change (i.e. asar file is not changed dramatically on small change)
async pack(fileSets, packager) {
if (this.options.ordering != null) {
// ordering doesn't support transformed files, but ordering is not used functionality - wait user report to fix it
await order(fileSets[0].files, this.options.ordering, fileSets[0].src);
}
await (0, _fsExtra().ensureDir)(path.dirname(this.outFile));
const unpackedFileIndexMap = new Map();
for (const fileSet of fileSets) {
unpackedFileIndexMap.set(fileSet, await this.createPackageFromFiles(fileSet, packager.info));
}
await this.writeAsarFile(fileSets, unpackedFileIndexMap);
}
async createPackageFromFiles(fileSet, packager) {
const metadata = fileSet.metadata; // search auto unpacked dir
const unpackedDirs = new Set();
const rootForAppFilesWithoutAsar = path.join(this.destination, "app");
if (this.options.smartUnpack !== false) {
await (0, _unpackDetector().detectUnpackedDirs)(fileSet, unpackedDirs, this.unpackedDest, rootForAppFilesWithoutAsar);
}
const dirToCreateForUnpackedFiles = new Set(unpackedDirs);
const correctDirNodeUnpackedFlag = async (filePathInArchive, dirNode) => {
for (const dir of unpackedDirs) {
if (filePathInArchive.length > dir.length + 2 && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {
dirNode.unpacked = true;
unpackedDirs.add(filePathInArchive); // not all dirs marked as unpacked after first iteration - because node module dir can be marked as unpacked after processing node module dir content
// e.g. node-notifier/example/advanced.js processed, but only on process vendor/terminal-notifier.app module will be marked as unpacked
await (0, _fsExtra().ensureDir)(path.join(this.unpackedDest, filePathInArchive));
break;
}
}
};
const transformedFiles = fileSet.transformedFiles;
const taskManager = new (_builderUtil().AsyncTaskManager)(packager.cancellationToken);
const fileCopier = new (_fs().FileCopier)();
let currentDirNode = null;
let currentDirPath = null;
const unpackedFileIndexSet = new Set();
for (let i = 0, n = fileSet.files.length; i < n; i++) {
const file = fileSet.files[i];
const stat = metadata.get(file);
if (stat == null) {
continue;
}
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, (0, _appFileCopier().getDestinationPath)(file, fileSet));
if (stat.isSymbolicLink()) {
const s = stat;
this.fs.getOrCreateNode(pathInArchive).link = s.relativeLink;
s.pathInArchive = pathInArchive;
unpackedFileIndexSet.add(i);
continue;
}
let fileParent = path.dirname(pathInArchive);
if (fileParent === ".") {
fileParent = "";
}
if (currentDirPath !== fileParent) {
if (fileParent.startsWith("..")) {
throw new Error(`Internal error: path must not start with "..": ${fileParent}`);
}
currentDirPath = fileParent;
currentDirNode = this.fs.getOrCreateNode(fileParent); // do not check for root
if (fileParent !== "" && !currentDirNode.unpacked) {
if (unpackedDirs.has(fileParent)) {
currentDirNode.unpacked = true;
} else {
await correctDirNodeUnpackedFlag(fileParent, currentDirNode);
}
}
}
const dirNode = currentDirNode;
const newData = transformedFiles == null ? null : transformedFiles.get(i);
const isUnpacked = dirNode.unpacked || this.unpackPattern != null && this.unpackPattern(file, stat);
this.fs.addFileNode(file, dirNode, newData == null ? stat.size : Buffer.byteLength(newData), isUnpacked, stat);
if (isUnpacked) {
if (!dirNode.unpacked && !dirToCreateForUnpackedFiles.has(fileParent)) {
dirToCreateForUnpackedFiles.add(fileParent);
await (0, _fsExtra().ensureDir)(path.join(this.unpackedDest, fileParent));
}
const unpackedFile = path.join(this.unpackedDest, pathInArchive);
taskManager.addTask(copyFileOrData(fileCopier, newData, file, unpackedFile, stat));
if (taskManager.tasks.length > _fs().MAX_FILE_REQUESTS) {
await taskManager.awaitTasks();
}
unpackedFileIndexSet.add(i);
}
}
if (taskManager.tasks.length > 0) {
await taskManager.awaitTasks();
}
return unpackedFileIndexSet;
}
writeAsarFile(fileSets, unpackedFileIndexMap) {
return new Promise((resolve, reject) => {
const headerPickle = pickle.createEmpty();
headerPickle.writeString(JSON.stringify(this.fs.header));
const headerBuf = headerPickle.toBuffer();
const sizePickle = pickle.createEmpty();
sizePickle.writeUInt32(headerBuf.length);
const sizeBuf = sizePickle.toBuffer();
const writeStream = (0, _fsExtra().createWriteStream)(this.outFile);
writeStream.on("error", reject);
writeStream.on("close", resolve);
writeStream.write(sizeBuf);
let fileSetIndex = 0;
let files = fileSets[0].files;
let metadata = fileSets[0].metadata;
let transformedFiles = fileSets[0].transformedFiles;
let unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[0]);
const w = index => {
while (true) {
if (index >= files.length) {
if (++fileSetIndex >= fileSets.length) {
writeStream.end();
return;
} else {
files = fileSets[fileSetIndex].files;
metadata = fileSets[fileSetIndex].metadata;
transformedFiles = fileSets[fileSetIndex].transformedFiles;
unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[fileSetIndex]);
index = 0;
}
}
if (!unpackedFileIndexSet.has(index)) {
break;
} else {
const stat = metadata.get(files[index]);
if (stat != null && stat.isSymbolicLink()) {
(0, _fs2.symlink)(stat.linkRelativeToFile, path.join(this.unpackedDest, stat.pathInArchive), () => w(index + 1));
return;
}
}
index++;
}
const data = transformedFiles == null ? null : transformedFiles.get(index);
const file = files[index];
if (data !== null && data !== undefined) {
writeStream.write(data, () => w(index + 1));
return;
} // https://github.com/yarnpkg/yarn/pull/3539
const stat = metadata.get(file);
if (stat != null && stat.size < 2 * 1024 * 1024) {
(0, _fsExtra().readFile)(file).then(it => {
writeStream.write(it, () => w(index + 1));
}).catch(e => reject(`Cannot read file ${file}: ${e.stack || e}`));
} else {
const readStream = (0, _fsExtra().createReadStream)(file);
readStream.on("error", reject);
readStream.once("end", () => w(index + 1));
readStream.pipe(writeStream, {
end: false
});
}
};
writeStream.write(headerBuf, () => w(0));
});
}
}
exports.AsarPackager = AsarPackager;
async function order(filenames, orderingFile, src) {
const orderingFiles = (await (0, _fsExtra().readFile)(orderingFile, "utf8")).split("\n").map(line => {
if (line.indexOf(":") !== -1) {
line = line.split(":").pop();
}
line = line.trim();
if (line[0] === "/") {
line = line.slice(1);
}
return line;
});
const ordering = [];
for (const file of orderingFiles) {
const pathComponents = file.split(path.sep);
for (const pathComponent of pathComponents) {
ordering.push(path.join(src, pathComponent));
}
}
const sortedFiles = [];
let missing = 0;
const total = filenames.length;
for (const file of ordering) {
if (!sortedFiles.includes(file) && filenames.includes(file)) {
sortedFiles.push(file);
}
}
for (const file of filenames) {
if (!sortedFiles.includes(file)) {
sortedFiles.push(file);
missing += 1;
}
}
_builderUtil().log.info({
coverage: (total - missing) / total * 100
}, "ordering files in ASAR archive");
return sortedFiles;
}
function copyFileOrData(fileCopier, data, source, destination, stats) {
if (data == null) {
return fileCopier.copy(source, destination, stats);
} else {
return (0, _fsExtra().writeFile)(destination, data);
}
}
// __ts-babel@6.0.4
//# sourceMappingURL=asarUtil.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,14 @@
export interface AsarIntegrityOptions {
/**
* Allows external asar files.
*
* @default false
*/
readonly externalAllowed?: boolean;
}
export interface AsarIntegrity extends AsarIntegrityOptions {
checksums: {
[key: string]: string;
};
}
export declare function computeData(resourcesPath: string, options?: AsarIntegrityOptions | null): Promise<AsarIntegrity>;

View File

@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.computeData = computeData;
function _bluebirdLst() {
const data = _interopRequireDefault(require("bluebird-lst"));
_bluebirdLst = function () {
return data;
};
return data;
}
function _crypto() {
const data = require("crypto");
_crypto = function () {
return data;
};
return data;
}
var _fs = require("fs");
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function computeData(resourcesPath, options) {
// sort to produce constant result
const names = (await (0, _fsExtra().readdir)(resourcesPath)).filter(it => it.endsWith(".asar")).sort();
const checksums = await _bluebirdLst().default.map(names, it => hashFile(path.join(resourcesPath, it)));
const result = {};
for (let i = 0; i < names.length; i++) {
result[names[i]] = checksums[i];
}
return {
checksums: result,
...options
};
}
function hashFile(file, algorithm = "sha512", encoding = "base64") {
return new Promise((resolve, reject) => {
const hash = (0, _crypto().createHash)(algorithm);
hash.on("error", reject).setEncoding(encoding);
(0, _fs.createReadStream)(file).on("error", reject).on("end", () => {
hash.end();
resolve(hash.read());
}).pipe(hash, {
end: false
});
});
}
// __ts-babel@6.0.4
//# sourceMappingURL=integrity.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/asar/integrity.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;;;;;;;AAeO,eAAe,WAAf,CAA2B,aAA3B,EAAkD,OAAlD,EAAuF;AAC5F;AACA,QAAM,KAAK,GAAG,CAAC,MAAM,wBAAQ,aAAR,CAAP,EAA+B,MAA/B,CAAsC,EAAE,IAAI,EAAE,CAAC,QAAH,CAAY,OAAZ,CAA5C,EAAkE,IAAlE,EAAd;AACA,QAAM,SAAS,GAAG,MAAM,uBAAgB,GAAhB,CAAoB,KAApB,EAA2B,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAL,CAAU,aAAV,EAAyB,EAAzB,CAAD,CAAzC,CAAxB;AAEA,QAAM,MAAM,GAA8B,EAA1C;;AACA,OAAK,IAAI,CAAC,GAAG,CAAb,EAAgB,CAAC,GAAG,KAAK,CAAC,MAA1B,EAAkC,CAAC,EAAnC,EAAuC;AACrC,IAAA,MAAM,CAAC,KAAK,CAAC,CAAD,CAAN,CAAN,GAAmB,SAAS,CAAC,CAAD,CAA5B;AACD;;AACD,SAAO;AAAC,IAAA,SAAS,EAAE,MAAZ;AAAoB,OAAG;AAAvB,GAAP;AACD;;AAED,SAAS,QAAT,CAAkB,IAAlB,EAAgC,SAAA,GAAoB,QAApD,EAA8D,QAAA,GAAwC,QAAtG,EAA8G;AAC5G,SAAO,IAAI,OAAJ,CAAoB,CAAC,OAAD,EAAU,MAAV,KAAoB;AAC7C,UAAM,IAAI,GAAG,0BAAW,SAAX,CAAb;AACA,IAAA,IAAI,CACD,EADH,CACM,OADN,EACe,MADf,EAEG,WAFH,CAEe,QAFf;AAIA,8BAAiB,IAAjB,EACG,EADH,CACM,OADN,EACe,MADf,EAEG,EAFH,CAEM,KAFN,EAEa,MAAK;AACd,MAAA,IAAI,CAAC,GAAL;AACA,MAAA,OAAO,CAAC,IAAI,CAAC,IAAL,EAAD,CAAP;AACD,KALH,EAMG,IANH,CAMQ,IANR,EAMc;AAAC,MAAA,GAAG,EAAE;AAAN,KANd;AAOD,GAbM,CAAP;AAcD,C","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { readdir } from \"fs-extra\"\nimport * as path from \"path\"\n\nexport interface AsarIntegrityOptions {\n /**\n * Allows external asar files.\n *\n * @default false\n */\n readonly externalAllowed?: boolean\n}\n\nexport interface AsarIntegrity extends AsarIntegrityOptions {\n checksums: { [key: string]: string }\n}\n\nexport async function computeData(resourcesPath: string, options?: AsarIntegrityOptions | null): Promise<AsarIntegrity> {\n // sort to produce constant result\n const names = (await readdir(resourcesPath)).filter(it => it.endsWith(\".asar\")).sort()\n const checksums = await BluebirdPromise.map(names, it => hashFile(path.join(resourcesPath, it)))\n\n const result: { [key: string]: string } = {}\n for (let i = 0; i < names.length; i++) {\n result[names[i]] = checksums[i]\n }\n return {checksums: result, ...options}\n}\n\nfunction hashFile(file: string, algorithm: string = \"sha512\", encoding: \"hex\" | \"base64\" | \"latin1\" = \"base64\") {\n return new Promise<string>((resolve, reject) => {\n const hash = createHash(algorithm)\n hash\n .on(\"error\", reject)\n .setEncoding(encoding)\n\n createReadStream(file)\n .on(\"error\", reject)\n .on(\"end\", () => {\n hash.end()\n resolve(hash.read() as string)\n })\n .pipe(hash, {end: false})\n })\n}"],"sourceRoot":""}

View File

@ -0,0 +1 @@
export declare function isLibOrExe(file: string): boolean;

View File

@ -0,0 +1,206 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isLibOrExe = isLibOrExe;
exports.detectUnpackedDirs = detectUnpackedDirs;
function _bluebirdLst() {
const data = _interopRequireDefault(require("bluebird-lst"));
_bluebirdLst = function () {
return data;
};
return data;
}
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _fs() {
const data = require("builder-util/out/fs");
_fs = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
function _isbinaryfile() {
const data = require("isbinaryfile");
_isbinaryfile = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _fileTransformer() {
const data = require("../fileTransformer");
_fileTransformer = function () {
return data;
};
return data;
}
function _appFileCopier() {
const data = require("../util/appFileCopier");
_appFileCopier = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function addValue(map, key, value) {
let list = map.get(key);
if (list == null) {
list = [value];
map.set(key, list);
} else {
list.push(value);
}
}
function isLibOrExe(file) {
return file.endsWith(".dll") || file.endsWith(".exe") || file.endsWith(".dylib") || file.endsWith(".so");
}
/** @internal */
async function detectUnpackedDirs(fileSet, autoUnpackDirs, unpackedDest, rootForAppFilesWithoutAsar) {
const dirToCreate = new Map();
const metadata = fileSet.metadata;
function addParents(child, root) {
child = path.dirname(child);
if (autoUnpackDirs.has(child)) {
return;
}
do {
autoUnpackDirs.add(child);
const p = path.dirname(child); // create parent dir to be able to copy file later without directory existence check
addValue(dirToCreate, p, path.basename(child));
if (child === root || p === root || autoUnpackDirs.has(p)) {
break;
}
child = p;
} while (true);
autoUnpackDirs.add(root);
}
for (let i = 0, n = fileSet.files.length; i < n; i++) {
const file = fileSet.files[i];
const index = file.lastIndexOf(_fileTransformer().NODE_MODULES_PATTERN);
if (index < 0) {
continue;
}
let nextSlashIndex = file.indexOf(path.sep, index + _fileTransformer().NODE_MODULES_PATTERN.length + 1);
if (nextSlashIndex < 0) {
continue;
}
if (file[index + _fileTransformer().NODE_MODULES_PATTERN.length] === "@") {
nextSlashIndex = file.indexOf(path.sep, nextSlashIndex + 1);
}
if (!metadata.get(file).isFile()) {
continue;
}
const packageDir = file.substring(0, nextSlashIndex);
const packageDirPathInArchive = path.relative(rootForAppFilesWithoutAsar, (0, _appFileCopier().getDestinationPath)(packageDir, fileSet));
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, (0, _appFileCopier().getDestinationPath)(file, fileSet));
if (autoUnpackDirs.has(packageDirPathInArchive)) {
// if package dir is unpacked, any file also unpacked
addParents(pathInArchive, packageDirPathInArchive);
continue;
} // https://github.com/electron-userland/electron-builder/issues/2679
let shouldUnpack = false; // ffprobe-static and ffmpeg-static are known packages to always unpack
const moduleName = path.basename(packageDir);
if (moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
shouldUnpack = true;
} else if (!file.includes(".", nextSlashIndex) && path.extname(file) === "") {
shouldUnpack = await (0, _isbinaryfile().isBinaryFile)(file);
}
if (!shouldUnpack) {
continue;
}
if (_builderUtil().log.isDebugEnabled) {
_builderUtil().log.debug({
file: pathInArchive,
reason: "contains executable code"
}, "not packed into asar archive");
}
addParents(pathInArchive, packageDirPathInArchive);
}
if (dirToCreate.size > 0) {
await (0, _fsExtra().ensureDir)(unpackedDest + path.sep + "node_modules"); // child directories should be not created asynchronously - parent directories should be created first
await _bluebirdLst().default.map(dirToCreate.keys(), async parentDir => {
const base = unpackedDest + path.sep + parentDir;
await (0, _fsExtra().ensureDir)(base);
await _bluebirdLst().default.each(dirToCreate.get(parentDir), it => {
if (dirToCreate.has(parentDir + path.sep + it)) {
// already created
return null;
} else {
return (0, _fsExtra().ensureDir)(base + path.sep + it);
}
});
}, _fs().CONCURRENCY);
}
}
// __ts-babel@6.0.4
//# sourceMappingURL=unpackDetector.js.map

File diff suppressed because one or more lines are too long