Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Windows: Only REPL is started if package was compressed with UPX #121

Closed
CherryDT opened this issue Jun 4, 2017 · 15 comments
Closed

Windows: Only REPL is started if package was compressed with UPX #121

CherryDT opened this issue Jun 4, 2017 · 15 comments

Comments

@CherryDT
Copy link

CherryDT commented Jun 4, 2017

I'm using upx to reduce file size. Normally, any executable packed with UPX will behave the same as before. However, the Windows executables created by pkg seem to be broken afterwards, in that they seem to behave like node instead of node the_file.js when run.

david@CHE-X1 MINGW64 ~/Temp/nodetest
$ pkg . --targets node6-win-x86
> pkg@3.0.6
> Fetching base Node.js binaries to: ~/.pkg-cache
  fetched-v6.10.0-win-x86      [====================] 100%

david@CHE-X1 MINGW64 ~/Temp/nodetest
$ ./nodetest.exe
Hello World!

david@CHE-X1 MINGW64 ~/Temp/nodetest
$ upx nodetest.exe
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2013
UPX 3.91w       Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  15253504 ->   5018624   32.90%    win32/pe     nodetest.exe

Packed 1 file.

david@CHE-X1 MINGW64 ~/Temp/nodetest
$ ./nodetest.exe
>
(To exit, press ^C again or type .exit)
>
@vweevers
Copy link

Doesn't seem to be an issue with latest upx 3.94w. As long as you don't do upx --overlay=strip. The default overlay=copy option correctly preserves the JS in my testing (with node8-win-x64,node8-win-x86).

@astefanutti
Copy link

astefanutti commented Jul 13, 2017

I can reproduce on Mac OS with UPX 3.94 (using --overlay=copy).

UPX reduces the executable size from 50MB to 13MB in my case, so that would be worth a fix.

Note that executing the compressed-then-decompressed executable works as expected.

@cayuu
Copy link

cayuu commented Aug 8, 2017

@vweevers so it seems things work fine on Windows? This looks to be at least a macOS specific issue - I've not tested on Linux, but can back up @astefanutti that this is happening on macOS Sierra 10.12.6, upx 3.94 and pkg 4.2.4.

@vweevers
Copy link

vweevers commented Aug 8, 2017

Looks that way, yes. A confirmation from the OP @CherryDT would be nice. Then this issue (title) can be updated accordingly.

@CherryDT
Copy link
Author

CherryDT commented Aug 8, 2017

I can confirm that with the latest pkg version in npm, it works fine with my original test case in Windows, I had version 3.0.6 when I encountered this issue, and now I successfully tested with version 4.2.2. (Only updating UPX didn't solve it, though.)

@astefanutti
Copy link

I've just re-tested with pkg version 4.2.2 and UPX 3.94 on Mac OS Sierra and it still fails with the same error. I think the issue can be renamed according to those tests.

@roccomuso
Copy link

roccomuso commented Sep 4, 2017

I've tested it too with UPX 3.94 and pkg@4.2.2 on Linux Ubuntu 16.04.
I have the same issue..

PS. I'm using a node-wrapper for upx.

@aluxian
Copy link

aluxian commented Sep 14, 2017

Still failing, upx 3.94 and pkg@4.2.4 on MacOS Sierra

@cancerberoSgx
Copy link

cancerberoSgx commented Oct 22, 2017

I'm having the same problem in arch linux. Using the command :

$ upx -1 -o myexec2 --strip-relocs=0 --overlay=skip myexec

$ upx -V 
upx 3.94
UCL data compression library 1.03
zlib data compression library 1.2.11
LZMA SDK version 4.43

@cancerberoSgx
Copy link

Question to the owners @igorklopov . upx guys are asking (upx/upx#2) :

The first thing that'd be important is to figure out where pkg is actually storing that information.
(eg. Is it just concatenating it onto the end like a self-extracting archive or actually storing it within the ELF structure the way debugging information is stored?)

Do you have this info? Thanks

@vladholubiev
Copy link

vladholubiev commented Nov 6, 2017

Adding to the pile, error on Amazon Linux AMI 2017.03, upx 3.9.4

This happens when I try to add any arguments, like ./bin a b c d e

(function (exports, require, module, __filename, __dirname) { ��ࡱ�
                                                              ^
SyntaxError: Invalid or unexpected token
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:432:7)
    at startup (bootstrap_node.js:192:9)

@FallingSnow
Copy link

On Arch Linux with upx 3.95-git-e633c51b50c1. Would be a nice feature to have since it reduces file sizes quite significantly. When using upx -1 -o output-test input-test I get:

Pkg: Error reading from file.

@elderapo
Copy link

elderapo commented May 8, 2019

As an alternative to upx, I recommend gzexe.

gzexe ./build/uncompressed && mv ./build/uncompressed ./build/compressed && mv ./build/uncompressed~ ./build/uncompressed

@nd0164
Copy link

nd0164 commented Apr 28, 2020

you may try a new toy pkgx

@jesec
Copy link
Contributor

jesec commented Nov 10, 2021

Dupe of #1370.

@jesec jesec closed this as completed Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests