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

Compiled to bytecode or something? #66

Open
ForbiddenEra opened this issue Apr 20, 2023 · 3 comments
Open

Compiled to bytecode or something? #66

ForbiddenEra opened this issue Apr 20, 2023 · 3 comments

Comments

@ForbiddenEra
Copy link

Just saw thisthinghere; interesting.

I'd like to add some input while it's early still.

Besides the ease-of-distribution/runnability, IMO it seems like the two main desires for devs wanting something like this (eg. the stuff listed as 'existing sea solutions') is:

  • some code protection
  • better performance

While it wouldn't be impossible to 'decompile' v8 bytecode into some sort of source, neither is it impossible to decompile an executable binary to C or something in general.

Due to my lack of deep v8 knowledge, I'm not sure how much/if any performance improvement could be seen by pre-compiling any bundled code into it's bytecode but if there's a potential performance gain then I think this should be considered, plus the side-effect of making it at least slightly more difficult to get the original/similar representation to the original code back out.

I'm not sure if there's any interest towards this or if perhaps there's a consensus toward including the code as-is for some sort of transparency reasons but I thought it might be worth mentioning/opening an issue for discussion.

@RaisinTen
Copy link
Contributor

RaisinTen commented Apr 21, 2023

FWIW, it is already possible to use the V8 bytecode equivalent of your code for the SEA. Here's a step by step demo (on macOS):

# The code you want to obfuscate by translating to V8 bytecode.
$ echo 'console.log(`Hello, ${process.argv[2]}`);' > hello.js

# Installing the dependencies.
$ npm init --yes && npm i --save-dev bytenode esbuild postject

# Creating a standalone JS file that uses the V8 bytecode of your original application.
$ node_modules/.bin/bytenode --compile hello.js
$ echo "require('bytenode').runBytecode(Buffer.from('$(base64 -i hello.jsc)', 'base64'))()" > input.js
$ node_modules/.bin/esbuild input.js --bundle --platform=node --external:electron > bundle.js

# Building the SEA.
$ echo '{ "main": "bundle.js", "output": "sea-prep.blob" }' > sea-config.json
$ node --experimental-sea-config sea-config.json
$ cp $(command -v node) hello
$ node_modules/.bin/postject hello NODE_SEA_BLOB sea-prep.blob \
    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
    --macho-segment-name NODE_SEA

# Running it.
$ ./hello world
Hello, world
(node:2561) ExperimentalWarning: Single executable application is an experimental feature and might change at any time
(Use `hello --trace-warnings ...` to show where the warning was created)

@Bennch
Copy link

Bennch commented Jan 8, 2024

This will just work as hello.js contains no require. As soon the code gets a require like "const http = require('http');", it breaks..
Any idea?

The error message is this

`evalmachine.:1
"​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​"
^

TypeError: undefined is not a function
at evalmachine.:1:113
at Object. (C:\Users\User\Desktop\test\run.js:1:1511)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49

Node.js v20.10.0`

@the-foreigner
Copy link

node:internal/util/embedding:48
throw new ERR_UNKNOWN_BUILTIN_MODULE(id);
^

Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: express
at embedderRequire (node:internal/util/embedding:48:11)
at src/index.js:2:17
at embedderRunCjs (node:internal/util/embedding:37:10)
at node:internal/main/embedding:18:8 {
code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}

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

No branches or pull requests

4 participants