Search code examples
.netcompressionexecutableportable-executable

Why doesn't UPX work for .NET executables?


If .NET executables are PE Files, why all packers like UPX "corrupts" it?


Solution

  • UPX is designed for native applications. These are applications that compile directly to machine code.

    Executables that target the .NET Framework are not native applications, but rather managed ones. In other words, they run on top of a runtime enviroment (the Common Language Runtime, or CLR) and are compiled to an "intermediate language" (IL) that is not compiled into machine language until runtime (this process is known as JIT, or just-in-time, compilation).

    UPX can deal directly with unmanaged machine code, but it doesn't work for managed applications. How is the JIT compiler going to compile the application's code on-the-fly if it's compressed and therefore unreadable? It won't; it's going to see the file as corrupted.

    No big loss, though. There are more disadvantages today to compressing an executable than there are advantages. And besides that, since managed applications are compiled to IL, they are often smaller than the equivalent unmanaged application in the first place.