aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nexe/lib/patches/boot-nexe.js
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
commitd25e11bee6ca5ca523884da132d18e1400e077b9 (patch)
tree8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/nexe/lib/patches/boot-nexe.js
downloadkartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip
Initial commit
Diffstat (limited to 'node_modules/nexe/lib/patches/boot-nexe.js')
-rw-r--r--node_modules/nexe/lib/patches/boot-nexe.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/nexe/lib/patches/boot-nexe.js b/node_modules/nexe/lib/patches/boot-nexe.js
new file mode 100644
index 0000000..d5aa8db
--- /dev/null
+++ b/node_modules/nexe/lib/patches/boot-nexe.js
@@ -0,0 +1,38 @@
+"use strict";
+const fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), tailSize = Math.min(stat.size, 16000), tailWindow = Buffer.from(Array(tailSize));
+fs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize);
+const footerPosition = tailWindow.indexOf('<nexe~~sentinel>');
+if (footerPosition == -1) {
+ throw 'Invalid Nexe binary';
+}
+const footer = tailWindow.slice(footerPosition, footerPosition + 32), contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize;
+Object.defineProperty(process, '__nexe', (function () {
+ let nexeHeader = null;
+ return {
+ get: function () {
+ return nexeHeader;
+ },
+ set: function (value) {
+ if (nexeHeader) {
+ throw new Error('This property is readonly');
+ }
+ nexeHeader = Object.assign({}, value, {
+ blobPath: process.execPath,
+ layout: {
+ stat,
+ contentSize,
+ contentStart,
+ resourceSize,
+ resourceStart,
+ },
+ });
+ Object.freeze(nexeHeader);
+ },
+ enumerable: false,
+ configurable: false,
+ };
+})());
+const contentBuffer = Buffer.from(Array(contentSize)), Module = require('module');
+fs.readSync(fd, contentBuffer, 0, contentSize, contentStart);
+fs.closeSync(fd);
+new Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath);