You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is considered a large resource? I successfully tested this project with the new Node Single Executable Application functionality with a relatively trivial size, but when I created a bundle (and confirmed execution of the bundle works with a node build/main.js call) that is 3.1MB in size, postject provides a very simple error that it failed:
$ npx postject node NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
Start injection of NODE_SEA_BLOB in node...
Error: Error when injecting resource
I can't find any arg to enter a verbose mode, so not sure how to debug further.
I was trying to find that out in #7 where I tried injecting large files into a tiny hello-world executable and I posted about my findings in nodejs/single-executable#23 (comment).
that is 3.1MB in size, postject provides a very simple error that it failed
@dfellis looking at the command, I'm guessing that happened on Linux? (very curious what the distro name and the arch is) I tried injecting a 16MB file into the official Node.js Linux binary (92 MB) I downloaded from the website and it is able to finish the injection with no errors for me (final executable size - 107 MB). It also ran with no errors.
I can't find any arg to enter a verbose mode, so not sure how to debug further.
Assuming that this is an ELF binary, it means that the error was reported from
returned null. As you said, there were no additional logs, so it probably means that there is a part in LIEF's code where this error happens but it doesn't log about it. To find that out, you would need to build Postject from source on your system and trace the calls inside LIEF's (a C++ dependency of this project that does the actual injection) LIEF::ELF::Parser::parse function -
But I was under the impression that these are basically just stock, as well.
As for building from source and tracing, is there a particular version of emscripten that should be used, as it appears that it's presumed to be set up outside of the build system?
Trying to catch throw in gdb isn't picking up on the failure, though (I don't have a debug build yet, but I figured I could try to figure out how to grab the error first and then figure out the debug build second). Any suggestions on that front?
Hmm... so while waiting, I decided to just dig into the Node.js code for postject to see what's going on, adding some console.logs to the inject function, and I got something interesting:
The check that the executable format is supported is incorrect, an unknown executable format is truthy.
I think I realized what's going on here. When I try to build stuff with yarn build, yarn is injecting its own wrapper around node in the $PATH (for some reason that I'm not entirely sure of), like this:
And that is not a binary, so when my build script (which is mostly just a copy-paste of the official docs) runs, command -v node returns that weird wrapper, which then grabs the wrong file to attach payload to.
And now when I run my build script with npm run build instead, I get
Trying to catch throw in gdb isn't picking up on the failure
Are you referring to the exceptions that are being thrown in JS? That actually causes the Node.js process to print the error info and exit.
I was running gdb node --args ./node_modules/.bin/postject ... and then tried to use the catch throw command to catch exceptions down at the binary level, hoping to find the LIEF error that way, even if I didn't have debug symbols, to make sure I was debugging it correctly, but that didn't work, and while probing in other ways I figured out what was actually happening. (My second comment.)
Activity
Add tests
Add tests
Add tests for injecting large resources
tests: add tests for injecting large resources
tests: add tests for injecting large resources
tests: add tests for injecting large resources
dfellis commentedon Apr 24, 2023
What is considered a large resource? I successfully tested this project with the new Node Single Executable Application functionality with a relatively trivial size, but when I created a bundle (and confirmed execution of the bundle works with a
node build/main.jscall) that is 3.1MB in size, postject provides a very simple error that it failed:I can't find any arg to enter a verbose mode, so not sure how to debug further.
RaisinTen commentedon Apr 27, 2023
I was trying to find that out in #7 where I tried injecting large files into a tiny hello-world executable and I posted about my findings in nodejs/single-executable#23 (comment).
@dfellis looking at the command, I'm guessing that happened on Linux? (very curious what the distro name and the arch is) I tried injecting a 16MB file into the official Node.js Linux binary (92 MB) I downloaded from the website and it is able to finish the injection with no errors for me (final executable size - 107 MB). It also ran with no errors.
Assuming that this is an ELF binary, it means that the error was reported from
postject/src/postject.cpp
Line 48 in 3edd1dd
postject/src/postject.cpp
Line 45 in 3edd1dd
LIEF::ELF::Parser::parsefunction -postject/vendor/lief/src/ELF/Parser.cpp
Lines 346 to 355 in 3edd1dd
dfellis commentedon Apr 28, 2023
@RaisinTen thanks for replying. Couldn't get back to this until today.
It's a mostly stock Ubuntu 22.04 LTS (with System76 kernel and drivers). The node binary I'm using is from
nvmBut I was under the impression that these are basically just stock, as well.
As for building from source and tracing, is there a particular version of emscripten that should be used, as it appears that it's presumed to be set up outside of the build system?
Trying to
catch throwingdbisn't picking up on the failure, though (I don't have a debug build yet, but I figured I could try to figure out how to grab the error first and then figure out the debug build second). Any suggestions on that front?dfellis commentedon Apr 28, 2023
Hmm... so while waiting, I decided to just dig into the Node.js code for postject to see what's going on, adding some
console.logs to theinjectfunction, and I got something interesting:Two things:
yarn build,yarnis injecting its own wrapper aroundnodein the$PATH(for some reason that I'm not entirely sure of), like this:And that is not a binary, so when my build script (which is mostly just a copy-paste of the official docs) runs,
command -v nodereturns that weird wrapper, which then grabs the wrong file to attach payload to.And now when I run my build script with
npm run buildinstead, I getConfirming that it's not a "too large" issue, it's that
yarnwraps calls tonodewith its own logic andpostjectwas not catching this.If you want, I can make a small PR to correct this (already confirmed here):
RaisinTen commentedon Apr 29, 2023
Thanks for looking into this, great work! 🎉
And to answer your questions:
Not really because Postject's CircleCI config currently uses the latest commit from emsdk's main -
postject/.circleci/config.yml
Line 105 in 3edd1dd
Are you referring to the exceptions that are being thrown in JS? That actually causes the Node.js process to print the error info and exit.
dfellis commentedon Apr 29, 2023
I was running
gdb node --args ./node_modules/.bin/postject ...and then tried to use thecatch throwcommand to catch exceptions down at the binary level, hoping to find the LIEF error that way, even if I didn't have debug symbols, to make sure I was debugging it correctly, but that didn't work, and while probing in other ways I figured out what was actually happening. (My second comment.)gsabran commentedon Jan 31, 2025
I mitigated this issue by adding
PATH=`echo ${PATH} | awk -v RS=: -v ORS=: '/var/ {next} {print}'`which removes the wrapper added by yarn from the PATH.