Developing PE file packer step-by-step. Step 11. Command line interface. Final version

Previous step is here.


At this step we will develop nice command line interface for our packer.

At first we need compiled Boost library. If you studied previous steps, you should have it already. If you have not built it yet, I will explain how to do that. For example, you unpacked the library archive to C:\boost directory. Open this directory and run bootstrap.bat file. bjam.exe file will appear in this directory in some time. Run the console (cmd) and go to C:\boost directory with cd command. Type the command

wait for debug version with static linking to be built, and then type

to build the release version. Boost is built and we can turn to the packer (simple_pe_packer project). Add two includes to main.cpp:

First one is necessary to implement command line interface, the second one is used to count file packing time. Replace lines

to these ones:

I will not describe the piece of code in detail, just say that we here process our packer command line easily and conveniently using boost::program_options library. I put all options available via command line (bool force_mode, bool repack_resources, bool rebuild_load_config, bool strip_dos_headers, unsigned long file_alignment, std::string input_file_name, std::string output_file_name) to the packer source code, and I will not explain what exactly has changed, because many parts of the code were slightly modified. Besides that, at the end of the source code I made output of the elapsed packing time, which was counted with boost::timer library. You can view all changes as always by downloading the full packer solution.

This version of the packer could be perhaps considered completed. Yes, it creates suspicious imports and probably has other issues, but it is fully operable, it supports things that other packers can’t do (for example, TLS with callbacks or loading configuration repacking) and it has command line interface. So, besides the source code I will share the packer EXE file, in case it will be useful for someone.

Full solution for this step: own-packer-step-11
Built packer (EXE):

UPD: New version with fixed bugs is here.

Leave a Reply

Your email address will not be published. Required fields are marked *