Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 3 tasks
YanDevDe opened this issue Sep 7, 2017 · 25 comments
Closed
1 of 3 tasks
Labels

Comments

@YanDevDe
Copy link

YanDevDe commented Sep 7, 2017

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"

@calebboyd
Copy link
Member

This is expected behavior.. Don't use --empty
Where did you see that was an option?
Its not documented anywhere...Because its just used to generate base binaries

@YanDevDe
Copy link
Author

YanDevDe commented Sep 7, 2017

Hey!
When I enter this for the first time

nexe index.js -o executeableFile

Then I get a message that I should use --build --empty
Maybe you want to remove "--empty" from the warning information. :)

I'm going to try tomorow if this work.

@calebboyd calebboyd added the bug label Sep 7, 2017
@calebboyd
Copy link
Member

Haha Whoops. Thanks

@calebboyd calebboyd reopened this Sep 7, 2017
@calebboyd
Copy link
Member

I'd also suggest using a maintained version of node :)

@YanDevDe
Copy link
Author

YanDevDe commented Sep 8, 2017

No problem! Yeah, I'll do when I got time. :) Thanks!

@calebboyd
Copy link
Member

Fixed in @latest and @beta

@twmarr
Copy link

twmarr commented Dec 20, 2017

I got this same error when I signed the executable and then tried to run it. Is there a way to sign the executable?

@calebboyd
Copy link
Member

@twmarr can you share your signed executable?
https://dropfile.to should work..

Its actually truncating the file, so you won't be sharing any of your application code/functionality.

@twmarr
Copy link

twmarr commented Dec 21, 2017

@calebboyd
Copy link
Member

calebboyd commented Dec 21, 2017

@twmarr You could make a patch like the following, the resulting executable (slow build) should allow signing.

require('nexe').compile({
  build: true,
  input: './app.js',
  patches: [
    (x, next) => {
      x.code = () => [x.shims.join(''), x.input].join(';')
      return next()
    },
   (compiler, next) => {
      return compiler.setFileContentsAsync(
        'lib/_third_party_main.js',
        compiler.code()
      ).then(next)
    }
  ]
})

Note: resources won't work

@twmarr
Copy link

twmarr commented Dec 21, 2017

@calebboyd
Thanks.

@calebboyd
Copy link
Member

@twmarr Did that work for you?

@twmarr
Copy link

twmarr commented Dec 21, 2017

@calebboyd I am getting an error:

async (compiler, next) => {
^

SyntaxError: Unexpected token (

@calebboyd
Copy link
Member

@twmarr I updated the example, removing async await

@twmarr
Copy link

twmarr commented Dec 21, 2017

Ah, I am using 6.11.3

@twmarr
Copy link

twmarr commented Dec 22, 2017

@calebboyd Sorry I didn't get back yesterday and I do appreciate your help. I had a problem with my environment and realized I needed to Install Nexe locally and not globally. Anyway, It did not work. After signing the executable, It still gives me this error when I run it:
_third_party_main.js:8
throw 'Invalid Nexe binary';
^
Invalid Nexe binary

@calebboyd
Copy link
Member

calebboyd commented Dec 22, 2017

Hmm. That shouldn't be possible. If you clear out the temp directory ~/.nexe and try again, it should be good
re: here https://gitter.im/nexe/nexe

@twmarr
Copy link

twmarr commented Dec 22, 2017

@calebboyd That got me past that error, but I am using a global.require for the configuration since I do not want it bundled and it can't find it. Anyway...thanks for the help. I'm out until after Jan 1. Happy Holidays!

@twmarr
Copy link

twmarr commented Jan 4, 2018

@calebboyd Is there a reason that global.require wouldn't work using the patch? I am testing it before signing and when running, the file I am trying to global.require is created and exists, but I get No such native module when on the global.require line. The reason for the global require is so that I don't include the configuration in the exe so that the configuration can be changed later.

@calebboyd
Copy link
Member

Ahh Sorry @twmarr. Fusebox is responsible for global.require. It must have broken transiently... That is very frustrating...

Alternatively you can prepend any code you like to the call to code() which is in an outside context.

so you can do 'global.require = require;' + compiler.code() instead of compiler.code()

@calebboyd calebboyd mentioned this issue Jan 25, 2018
3 tasks
@tamasszarka
Copy link

tamasszarka commented Nov 13, 2018

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;

@foxever
Copy link
Contributor

foxever commented Apr 2, 2019

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

@calebboyd
Copy link
Member

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

Thanks for the PR @foxever

uzdry pushed a commit to uzdry/nexe that referenced this issue Feb 28, 2020
@taajuddin
Copy link

I have also same issue
_third_party_main.js:6
throw 'Invalid Nexe binary'; Invalid Nexe binary

@frank-f-bader
Copy link

frank-f-bader commented Jul 7, 2022

@twmarr You could make a patch like the following, the resulting executable (slow build) should allow signing.

require('nexe').compile({
  build: true,
  input: './app.js',
  patches: [
    (x, next) => {
      x.code = () => [x.shims.join(''), x.input].join(';')
      return next()
    },
   (compiler, next) => {
      return compiler.setFileContentsAsync(
        'lib/_third_party_main.js',
        compiler.code()
      ).then(next)
    }
  ]
})

Note: resources won't work

I am having the same issue after signing the exe
All our builds run without internet access so we have the node version available internally and copied during the build to the temp directory.
I tried adding the patches to the compile call but now nexe tries to download node.js source then it tries to compile it. Is there a way to add the patches and not have it try to download/build node, to get the signing to work at runtime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants