vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.32k stars 1.01k forks source link

Private option is not working as expected #1885

Closed 0xARROWK closed 1 year ago

0xARROWK commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

16.19.1

What operating system are you using?

Ubuntu 20.04

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node16-win-x64

Describe the Bug

I tried to reverse my own application using pkg-unpacker to see if pkg was working as I expected.

Concerning the top-level code it seems to be good, code is well converted to v8 bytecode, but when I looked at dependencies used, I saw that they was included as plain js.

So I looked at issue for solving it (since I didn't saw anything in the README), and I used the following options in my top-level packages.json file :

"pkg": {
    "private": true
}

But once I used pkg-unpacker after recompiling my app, dependencies code was in plain js again.

Expected Behavior

The expected behavior was that dependencies are also packed as v8 bytecode.

To Reproduce

Set in top-level packages.json file :

"pkg": {
    "private": true
}

Package app :

pkg app.js -t win

Clone pkg-unpacker and run :

node unpack.js -i app.exe -o ./output/
robertsLando commented 1 year ago

The expected behavior was that dependencies are also packed as v8 bytecode.

Dependecies pkg.json file must also have private: true field in order to be translated to v8

0xARROWK commented 1 year ago

Thanks for your answer.

So, if I understand well, I need to put "private": true in every package.json files inside my node_modules folder ?

robertsLando commented 1 year ago

yeah

liesauer commented 1 year ago

not working for me +1, maybe wrong config?

  "bin": "./obfuscated/index.js",
  "pkg": {
    "private": true,
    "assets": [
      "./obfuscated/core.js",
      "./node_modules/axios/dist/node/axios.cjs"
    ],
    "targets": ["node16-win"],
    "compress": "GZip",
    "outputPath": "dist"
  }

still pack as plain js, btw, compress option seems not working either.

image

image

damartripamungkas commented 1 year ago

not working for me +1, maybe wrong config?

  "bin": "./obfuscated/index.js",
  "pkg": {
    "private": true,
    "assets": [
      "./obfuscated/core.js",
      "./node_modules/axios/dist/node/axios.cjs"
    ],
    "targets": ["node16-win"],
    "compress": "GZip",
    "outputPath": "dist"
  }

still pack as plain js, btw, compress option seems not working either.

image

image

do not use pkg . to compile but use this method pkg ./obfuscated/index.js -t node16-win -C GZip -o dist it works for me, the code has been converted to bytecode but some strings are still plain text