How frank2/packer-tutorial works
Project type and purpose
• This is a native C++ “packer tutorial” project that demonstrates how to build a self-contained Windows packer/unpacker using CMake and zlib.
• It comprises three primary executables:
• dummy (a small test binary),
• stub (the unpacker runtime),
• packer (the compressor + resource-injector),
plus the zlib compression library.
File structure
• Top-level CMakeLists.txt orchestrates the build.
• Subdirectories:
• dummy/src/main.cpp – the target binary to be packed.
• stub/src/main.cpp – stub that unpacks and simulates the PE loader.
• src/main.cpp – packer logic (compress + embed stub).
• zlib-1.2.13/ – bundled zlib C library.
• CTest integration via add_test in root CMake to run test_pack and test_unpack.
• Build‐time flow: CMake → zlib build → stub build → packer build → dummy build.
Key insights from README
• Two-phase architecture:
a) Compression stage (packer.exe uses zlib to compress dummy.exe, injects stub.exe as a resource).
b) Unpacking stage (stub.exe at runtime extracts its “.packed” section, decompresses it, simulates Windows PE loader, resolves imports, relocations, transfers control to original entrypoint).
• Tutorial covers PE parsing/manipulation, resource embedding via Windows RC files generated by CMake.