Jump to content











Photo

[How to] UPX compress all files in subfolder


  • Please log in to reply
2 replies to this topic

#1 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 08 June 2008 - 03:18 PM

Hi everyone.

I wanted to compress a few DLL's to make a program become smaller sized but this program had several subfolders inside and this was a complication because I wanted to use UPX (the exe/dll compression tool) .

Since upx didn't had an option to do scan inside all available subfolders, I decided to use the FOR command that is available as a NT batch script for this task.

Here is the code that made it possible:
FOR /F "tokens=*" %%G IN ('dir/b/s ^"*.dll^"') DO upx.exe -9 "%%G"


This code will run "upx.exe -9" and mention the exe we want to compress using the variable "%%G"

You can also adapt this code for any other uses, just change the .DLL with whatever extension you wish to find.


- Do notice that upx (upx.exe) needs to be found either on the same folder from where you run this script or inside a windows folder (such as c:\windows).

For knowing the correct syntax of the above mentioned command, I used this guide from Rick Lively here: http://www.geocities...NDS/F/FOR_F.HTM


And here is a script ready for download: Attached File  compsub.cmd   73bytes   120 downloads

;)

#2 ispy

ispy

    Silver Member

  • Tutorial Writer
  • 646 posts
  • Location:PILGRIM

Posted 09 June 2008 - 08:23 PM

Hi Nuno ;) ,

I like these one liner "For in do" Commandline commands not that I understand the For-in-do concept but you can do powerful things with it.

One question please?

When you are upx'ing files which ones as a general rule is it safe to compress, is there a convention that has to be adopted or is it by trial & error?

Regards & Respect,

ispy :thumbup:

#3 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 10 June 2008 - 01:35 AM

Mostly trial and error my friend.

If some DLL doesn't like compression you might get lucky and see it complaining when it gets loaded by the respective program.

The serious issue - what happens if your program doesn't call a faulty dll except in special occasions and you end up missing a fault as easy as this when you apply UPX to so many DLL's like on this case.

Also, some DLL's like shell32.dlk require you to keep intact the resources. it can be compressed but you need to add the respective switch to keep the resources (if my memory doesn't fail on me)

;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users