From e72f705298a0d12284a55df958bbcaaa8586ad8b Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Mon, 8 Jun 2015 09:46:04 -0500 Subject: [PATCH] Add new code template --- modules/encoders/x86/alpha_mixed.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/encoders/x86/alpha_mixed.rb b/modules/encoders/x86/alpha_mixed.rb index 0a95ba3d24..e0d655a07f 100644 --- a/modules/encoders/x86/alpha_mixed.rb +++ b/modules/encoders/x86/alpha_mixed.rb @@ -31,6 +31,7 @@ class Metasploit3 < Msf::Encoder::Alphanum # being encoded. # def decoder_stub(state) + modified_registers = [] reg = datastore['BufferRegister'] off = (datastore['BufferOffset'] || 0).to_i buf = '' @@ -52,7 +53,14 @@ class Metasploit3 < Msf::Encoder::Alphanum reg.upcase! end - buf + Rex::Encoder::Alpha2::AlphaMixed::gen_decoder(reg, off) + stub = buf + Rex::Encoder::Alpha2::AlphaMixed::gen_decoder(reg, off) + + # Sanity check that saved_registers doesn't overlap with modified_registers + if (modified_registers & saved_registers).length > 0 + raise BadGenerateError + end + + stub end # @@ -69,4 +77,14 @@ class Metasploit3 < Msf::Encoder::Alphanum def encode_end(state) state.encoded += Rex::Encoder::Alpha2::AlphaMixed::add_terminator() end + + # Indicate that this module can preserve some registers + def can_preserve_registers? + true + end + + # Convert the SaveRegisters to an array of x86 register constants + def saved_registers + Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters']) + end end