Skip to content

Compiled to bytecode or something? #66

Description

@ForbiddenEra

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.

Activity

  1. RaisinTen commented on Apr 21, 2023

    @RaisinTen
    Member

    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)
  2. Bennch commented on Jan 8, 2024

    @Bennch

    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`

  3. the-foreigner commented on Jan 11, 2024

    @the-foreigner

    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'
    }

  4. m4Nu2oo7 commented on Jun 30, 2024

    @m4Nu2oo7

    any solution for this? :)

    Here someone said we need to do this:
    const bytenode = require('bytenode');
    const result = require("./path/to/compiled.jsc");
    console.log(result)
    bytenode/bytenode#236 (comment)

    but the problem is that with sea the require to the compiled.jsc will not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions