From 144249b34dbc7671068b157a4240cc3486e7fb78 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 30 Jul 2006 18:45:36 +0000 Subject: [PATCH] bump thread priority in encoded payload generation to fix thread starvation issues git-svn-id: file:///home/svn/framework3/trunk@3777 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/encoded_payload.rb | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/msf/core/encoded_payload.rb b/lib/msf/core/encoded_payload.rb index a8f7324c0f..a06dec32c5 100644 --- a/lib/msf/core/encoded_payload.rb +++ b/lib/msf/core/encoded_payload.rb @@ -46,20 +46,34 @@ class EncodedPayload self.encoder = nil self.nop = nil - # First, validate - pinst.validate() + # Increase thread priority as necessary. This is done + # to ensure that the encoding and sled generation get + # enough time slices from the ruby thread scheduler. + priority = Thread.current.priority - # Generate the raw version of the payload first - generate_raw() + if (priority == 0) + Thread.current.priority = 1 + end - # Encode the payload - encode() + begin + # First, validate + pinst.validate() - # Build the NOP sled - generate_sled() + # Generate the raw version of the payload first + generate_raw() - # Finally, set the complete payload definition - self.encoded = (self.nop_sled || '') + self.encoded + # Encode the payload + encode() + + # Build the NOP sled + generate_sled() + + # Finally, set the complete payload definition + self.encoded = (self.nop_sled || '') + self.encoded + ensure + # Restore the thread priority + Thread.current.priority = priority + end # Return the complete payload return encoded