rapid7/metasploit-framework — pull request #3770 by hmoore-r7 (2014-09-09 19:29:51+00:00)
Title: Stage encoding is now SaveRegister aware

This change makes EnableStageEncoding reliable. Prior to this patch, there was no way to tell the encode what registers to preserve, which led to shikata_ga_nai stepping on the EDI register when used with sockedi stagers. This patch now automatically determines what registers to preserve by scanning the Compatibility key and passes these, along with any set by the user, to the EncodedPayload class for the stage. The EncodedPayload class now looks for 'ForceSaveRegisters' set in ```req[]``` and then verifies that the encoder supports register preservation if ```EncoderOptions['SaveRegisters']``` is set.

TL;DR: Backwards compatible and now limits stage encoding to compatible encoders when a stager is used that requires a register to be preserved. Future work would include making additional encoders compatible with register_preservation (or at least check to see if they can support the given SaveRegisters).