nexe: _third_party_main.js:12 throw 'Invalid Nexe binary' ^ Invalid Nexe binary

This is a

  • Bug Report
  • Feature Request
  • Other

If this is a bug report, What are the steps to reproduce?
nexe index.js -o executeableFile --build --empty

//when compiler is done

executeableFile.exe

When I’m trying to run executeableFile.exe then I get a error:

C:\Users\Chinafreak\Documents\example>executeableFile.exe

_third_party_main.js:12
  throw 'Invalid Nexe binary'
  ^
Invalid Nexe binary



Please also provide:

  • Platform(OS/Version): Windows 10
  • Host Node Version: v7.9.0
  • Target Node Version: v7.9.0
  • Nexe version: 2.0.0-rc.2
  • Python Version: 2.7.13

I’m abled to execute “node index.js”

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I run into the same issue after using signtool on Windows. This is the patch I created locally, currently it runs on the nexe dir after npm install, and I’m patching boot-nexe.js and third-party-main.js. Two questions:

  1. Do you think this is safe? It seems to work.
  2. We have not been using --build so far as we compiled our source with nexe, as the extra 25min of the node build is excessive for us daily. How can I prebuild nexe as the fetched package when no --build option is used? I do not want to keep around the entire node build, the directory is ~18Gb after building.

Many thanks for answers.

diff --git a/boot-nexe.js b/boot-nexe.js
index 2eed93b61..5af138e69 100644
--- a/boot-nexe.js
+++ b/boot-nexe.js
@@ -2,14 +2,23 @@
 var fs = require('fs');
 var fd = fs.openSync(process.execPath, 'r');
 var stat = fs.statSync(process.execPath);
-var footer = Buffer.from(Array(32));
-fs.readSync(fd, footer, 0, 32, stat.size - 32);
-if (!footer.slice(0, 16).equals(Buffer.from('<nexe~~sentinel>'))) {
-    throw 'Invalid Nexe binary';
+// need to find the real nexe footer for validation, but the
+// signing process adds extra bytes to the end of the file
+var tailSize = 16000;
+if(tailSize > stat.size) {
+  tailSize = stat.size;
 }
+var tailBuf = Buffer.from(Array(tailSize));
+fs.readSync(fd, tailBuf, 0, tailSize, stat.size - tailSize);
+var sentinelPos = tailBuf.indexOf('<nexe~~sentinel>');
+if(sentinelPos == -1) {
+  throw 'Invalid Nexe binary';
+}
+var endNexeContent = stat.size - tailSize + sentinelPos + 32;
+var footer = tailBuf.slice(sentinelPos, sentinelPos+32);
 var contentSize = footer.readDoubleLE(16);
 var resourceSize = footer.readDoubleLE(24);
-var contentStart = stat.size - 32 - resourceSize - contentSize;
+var contentStart = endNexeContent - 32 - resourceSize - contentSize;
 var resourceStart = contentStart + contentSize;
 Object.defineProperty(process, '__nexe', (function () {
     var nexeHeader = null;

Wow I never saw this comment on this issue. Great Find @tamasszarka.

Thanks for the PR @foxever

I ran into the same issue on windows when digital signing a nexe binary @tamasszarka’s patch works for me, FYI.

Fixed in @latest and @beta