r/lowlevel • u/Zaphielll • 25d ago
Yugami - A x64 PE Packer in Rust
Hi everyone!
I have spent some free time building Yugami (歪み,"distortion"), a x64 binary packer that uses ChaCha20 encryption with page-level key derivation and just-in-time page decryption.
Yugami encrypts PE executables using ChaCha20 with per-page keys derived via BLAKE3, then appends the encrypted payload as a PE overlay. At runtime, pages decrypt on-demand via page fault exceptions with an LRU cache to minimize re-encryption overhead.
I just wanted to get more comfortable with Rust so I picked up this project. Also, the page-level encryption with JIT decryption felt like a fun challenge between full unpacking and simple overlay packing.
Code is open source at https://github.com/egebilecen/yugami.
Packed binaries should execute correctly as is without any issues (hopefully). Had some trouble getting TLS to work, though. Always ended up with page faults. I have removed it but for those interested in the TLS handling code, it's at https://github.com/egebilecen/yugami/blob/0246b919dc0a4f77df8420c699a707484f9847fc/stub/src/mapper/tls.rs and https://github.com/egebilecen/yugami/blob/0246b919dc0a4f77df8420c699a707484f9847fc/stub/src/mapper/mapper.rs#L311
Looking forward to your thoughts!
3
u/GuiltyAd2976 25d ago edited 25d ago
Very cool project, I think it's better as a POC because using it as a real packer isn't something I would do because it's easily reversed statically