# Any idea how to call UPX recursively?

32 posts / 0 new
Klonk
Offline
Last seen: 10 years 10 months ago
Joined: 2006-04-21 03:08
Any idea how to call UPX recursively?

Hi everyone,
any ideas how to achieve that task?

It seems that UPX does not have a commandline switch to do that (At least I didn't find it).
Then I tried to get a (recursive) list of *.dll and *.exe files (with DIR) but struggled to get it working in an universal plattform independant way (To later call UPX with each item of the list.)

Any ideas?

Ryan McCue
Offline
Last seen: 13 years 4 months ago
Joined: 2006-01-06 21:27
Well,

In a batch file, it's:

for /r %%e in (*.exe,*.dll) do upx "%%e" --best --compress-icons=0 --nrv2d --crp-ms=999999 -k

"If you're not part of the solution, you're part of the precipitate."

BuddhaChu
Offline
Last seen: 6 years 3 months ago
Joined: 2006-11-18 10:26
Bump it up

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

Ryan McCue
Offline
Last seen: 13 years 4 months ago
Joined: 2006-01-06 21:27
Well,

"If you're not part of the solution, you're part of the precipitate."

John T. Haller
Offline
Last seen: 1 hour 32 min ago
Joined: 2005-11-28 22:21
2e now

No, I use nrv2e now for releases. It was UPX's LZMA I was ranting about because it's got compatibility issues (it breaks more DLLs than nrv2d/2e).

Sometimes, the impossible can become possible, if you're awesome!

Steve Lamerton
Offline
Last seen: 9 years 4 months ago
Joined: 2005-12-10 15:22
You're

posting early, getting some more releases out?

John T. Haller
Offline
Last seen: 1 hour 32 min ago
Joined: 2005-11-28 22:21
Yup

Working on Toucan now

Sometimes, the impossible can become possible, if you're awesome!

Steve Lamerton
Offline
Last seen: 9 years 4 months ago
Joined: 2005-12-10 15:22
*grins wildly*

Excellent, although I just realised how sad it is for me to have an intuitive knowledge of when you should be posting.

Ryan McCue
Offline
Last seen: 13 years 4 months ago
Joined: 2006-01-06 21:27
Served

Well, I just got served

"If you're not part of the solution, you're part of the precipitate."

Klonk
Offline
Last seen: 10 years 10 months ago
Joined: 2006-04-21 03:08
Problems?

also with the version 3.01 of UPX?
I didn't have an problems yet using "--lzma". maybe I was lucky

BuddhaChu
Offline
Last seen: 6 years 3 months ago
Joined: 2006-11-18 10:26
not as "safe"

lzma compression isn't as "safe" as nrv2e and can cause issues for some people on some machines. The nrv2e compression causes less problems. John had a good post in one of my portable game threads in the Beta forum (that's the one he's referring to above).

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

Bahamut
Offline
Last seen: 11 years 2 months ago
Joined: 2006-04-07 08:44
So that's how for works! Oh,

So that's how for works! Oh, and %%e doesn't work (but %e does). I have work to do.

Vintage!

rab040ma
Offline
Last seen: 6 months 1 week ago
Joined: 2007-08-27 13:35
I think you double the % in

I think you double the % in a cmd file, but just use one from the command line ... or something like that.

MC

Ryan McCue
Offline
Last seen: 13 years 4 months ago
Joined: 2006-01-06 21:27
Yep.

I put it in a batch file called upax.bat, so I just cd to the App\Whatever directory and type upax

"If you're not part of the solution, you're part of the precipitate."

Bahamut
Offline
Last seen: 11 years 2 months ago
Joined: 2006-04-07 08:44
Nope. I first tried it on

Nope. I first tried it on the command line and it said %%e was unexpected. %e works just fine both directly typed onto the command line and in a batch file.

Vintage!

wraithdu
Offline
Last seen: 9 years 7 months ago
Joined: 2007-06-27 20:22
%e for commandline, %%e for

%e for commandline, %%e for a batch file.

http://www.ss64.com/nt/for.html

Bahamut
Offline
Last seen: 11 years 2 months ago
Joined: 2006-04-07 08:44
A quick test shows you are

A quick test shows you are right. It's messed up.

Vintage!

ATimson
Offline
Last seen: 15 years 3 months ago
Joined: 2007-10-26 20:22
Not if you know batch files

It's not really "messed up", if you know about batch files using parameters they receive on the command line.

A batch file can use the first parameter as %1, second as %2, etc. Without doubling the % sign, the command interpreter thinks it's supposed to evaluate the % sign as a parameter, not pass it on to the command.

"Niceness is the greatest human flaw, except for all the others."
--Brendan Moody

Klonk
Offline
Last seen: 10 years 10 months ago
Joined: 2006-04-21 03:08
Thanks

and how to call it from within a NSIS script?

Zach Thibeau
Offline
Last seen: 3 months 2 weeks ago
Joined: 2006-05-26 12:08

hmnis edit when you install it it has an nsis script for repackaging the program and it includes a function within the script to call and compress with upx

your friendly neighbourhood moderator Zach Thibeau

wraithdu
Offline
Last seen: 9 years 7 months ago
Joined: 2007-06-27 20:22
How are you generating the file list?

Depends on how you want to generate the file list. If you are drag-and-dropping files on the EXE, then use GetParameters and pass it to upx -

${GetParameters}$FILELIST
ExecWait '"UPX" $FILELIST --OPTIONS' If you need to search a list of files, use FindFirst/FindNext/FindClose to concatenate your file list and pass it to UPX like above. Klonk Offline Last seen: 10 years 10 months ago Joined: 2006-04-21 03:08 Well yes you're right. But how to call that recursive call above? wraithdu Offline Last seen: 9 years 7 months ago Joined: 2007-06-27 20:22 Try this for recursive search http://nsis.sourceforge.net/RecFind:_Recursive_FindFirst%2C_FindNext%2C_... Then you can test the extension from${GetFileExt}, and if it matches your set of criteria (EXE or DLL, etc), UPX each file individually.

I thought about the file list approach again last night, and it would fail miserably if the directory structure and number of files was large. I can't imagine how big that string would be....

Klonk
Offline
Last seen: 10 years 10 months ago
Joined: 2006-04-21 03:08
Thanks,

that gave me an idea how to do it.
In fact I only need the list of recursive folders as I could call "UPX ... \*.exe" and/or "UPX ... \*.dll"

wraithdu
Offline
Last seen: 9 years 7 months ago
Joined: 2007-06-27 20:22
Better idea I think...

I thought about this some more, and I think this is better and faster than using NSIS to search the directories and call UPX. Just use good old commandline FOR to do it for you (like above) -

ExecWait cmd /k "FOR /R "TOPLEVELDIR" %G IN (*.exe, *.dll) DO "X:\path\to\upx\upx.exe" "%G" --best --compress-icons.....-k"

You can use 'cmd /c' if you want the console window to close when it's done.

BuddhaChu
Offline
Last seen: 6 years 3 months ago
Joined: 2006-11-18 10:26
I would recommend expanding

I would recommend expanding the extensions you're compressing or use *.* as you're missing out on a lot of squishing opportunities.

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

Lurking_Biohazard
Offline
Last seen: 4 years 5 months ago
Joined: 2006-02-18 18:06
Squishing

Oh BuddhaChu, I love it when you get all technical!

~Lurk~

BuddhaChu
Offline
Last seen: 6 years 3 months ago
Joined: 2006-11-18 10:26
What's that I smell?

Smells like sarcasm...

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

Ryan McCue
Offline
Last seen: 13 years 4 months ago
Joined: 2006-01-06 21:27
Actually

Those are the only ones I have, otherwise it's too slow.

"If you're not part of the solution, you're part of the precipitate."

qwertymodo
Offline
Last seen: 10 years 6 months ago
Joined: 2008-03-17 19:08
compress...test...undo

Recursive compressing is nice and all but what about the odd .exe or .dll that doesn't work after compression? Anybody have a way to recursively search for files and then for each file first compress it then test it then if upx returns bad for the compressed file decompress that one and move on to the next (e.g. using upx -t filename)? Also, I have yet to actually encounter such a file where upx "breaks" the file. Can anybody point me to such a file (or send me one) so I can play around with it myself? I've heard that a lot of the Windows files won't work compressed so I can try that...

Quamquam omniam nescio, nec nihil scio.

BuddhaChu
Offline
Last seen: 6 years 3 months ago
Joined: 2006-11-18 10:26
If I remember correctly, the

If I remember correctly, the following app incorporated some kind of testing in it to help eliminate files that "didn't play nice" with compression.

https://portableapps.com/apps/utilities/appcompactor

Yep, testing was added to version PR2 of the beta of the above app.

https://portableapps.com/node/12241#comment-72276

From the beta release notes (scroll up in the above thread):

ENHANCEMENT: UPXed files are tested to ensure they decompress

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

John T. Haller
Offline
Last seen: 1 hour 32 min ago
Joined: 2005-11-28 22:21
Correct

The AppCompactor uses UPX to compress each EXE/DLL/etc and then it uses UPX to test it (UPX -t as you mentioned). Some files can still slip through the cracks but those are relatively few, often some plugins. That's why we encourage NRV2E (the method with the least issues) and testing of the compressed app.

Sometimes, the impossible can become possible, if you're awesome!