Why and How to Compress EXE Files with UPX

Among the developers community, compressing the executable files has always been a topic of discussion. By compressing the executable files (such as the programs with EXE extension), we can reduce the size of the executable file without affecting the overall functionality of the program. When a compressed EXE is run, it is decompressed before being loaded into the memory. This is why it works the same as before.

Why do we compress EXE files?

There are many reasons why would a developer decide to compress the EXE files. One very obvious reason is the reduction of the EXE file size. By using an EXE compression tool such as UPX, we can almost half the size of a typical EXE file.

Another reason, which is related to the first one, is the faster downloads. After you have compressed a large EXE file, it can be downloaded faster because now it is very small in size. It can also be distributed much more conveniently through various online and offline platforms.

Final reason, and also sometimes very important to the developers, is the ability to prevent reverse engineering (to a certain degree). Some of the EXE compression tools add some extra code to detect the debuggers. So if someone is trying to check the code execution sequence inside your program using a debugger, it will detect the debugger and exit the program.

How to compress EXE files with UPX?

UPX is a very popular and very old compression tool for EXE files. It has been around since early 90s. It is a command line tool but there are several GUI frontends available. In general, we can compress an EXE simply by supplying it as the only parameter. For example, a command like upx.exe notepad.exe can be used in which case notepad.exe will be compressed using the default settings.

Compress EXE Using UPX

If you want to backup the EXE first, then you can do it manually yourself or you can use the option -k. For example, if you want to create backup, you can use the command upx.exe -k notepad.exe .

We can also specify a compression level from 1 to 9. This can be done by simply giving the number level of compression as the parameter. For example, upx.exe -5 notepad.exe will compress with level 5 compression.

If you run UPX without any parameters, then it shows all the options and syntax of using this very useful tool. Much more detailed information can be had by using the -h switch with the UPX command.

You can download the latest version of UPX from https://upx.github.io/ or from https://github.com/upx/upx/.