cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

vampyr_6
Journeyman III

A fix for the TLS bug (unable to dynamic load STREAMS dlls.)

Hi. I am the author of a sha1 bruteforcer (passrape @ governmentsecurity). I had the need to dynamic load dll files in the latest version of my cracker, so i messed around a bit, and this is how i fixed the TLS stuff. Making you able to dynamic-load a dll.

The header file i modified is KernelInterface.h

See attached code.


 

Replace the file contents with: #ifndef _KERNELINTERFACE_H_ #define _KERNELINTERFACE_H_ /**************************************************************************** Copyright (c) 2008, Advanced Micro Devices, Inc. Modified by vampyr_6@hotmail.com (vampyr) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Advanced Micro Devices, Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************************/ //////////////////////////////////////////////////////////////////////////////// //! //! \file KernelInterface.h //! //! \brief Contains method for all the generated kernel classes //! //////////////////////////////////////////////////////////////////////////////// #ifdef _WIN32 #define __THREAD__ #else #define __THREAD__ __thread #endif #define MaxRank 4 //workaround for the shitty ATI tls. allows dynamic loading. struct intTuple{ unsigned int unused; unsigned int values[MaxRank]; }; template <unsigned int N>class dmoffset{ public: dmoffset(){ if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) throw(new std::exception("TlsAlloc failed")); } unsigned int & operator[](int n){ LPVOID lpvData = TlsGetValue(dwTlsIndex); if( lpvData==0){ if (!TlsSetValue(dwTlsIndex, new intTuple())) throw(new std::exception("LocalAlloc failed")); static_cast<intTuple*>(TlsGetValue(dwTlsIndex))->unused=N; } return static_cast<intTuple*>(TlsGetValue(dwTlsIndex))->values; } void kill(){ delete (intTuple*)static_cast<intTuple*>(TlsGetValue(dwTlsIndex)); TlsSetValue(dwTlsIndex, 0); }; ~dmoffset(){ TlsFree(dwTlsIndex); } inline operator unsigned int *(){ if(TlsGetValue(dwTlsIndex)==0)return 0; return (unsigned int*)&(operator[](0)); } private: static DWORD dwTlsIndex; }; template <unsigned int N>DWORD dmoffset<N>::dwTlsIndex=0; #include <iostream> #define EXTENDCLASS() \ void domainOffset(uint4 offset) \ { \ memcpy(&_domainOffset[0], offset, MaxRank * sizeof(unsigned int));\ std::cout<<_domainOffset[0]<<_domainOffset[1]<<_domainOffset[2]<<_domainOffset[3]<<std::endl;\ } \ void domainSize(uint4 size) \ { \ memcpy(&_domainSize[0], size, MaxRank * sizeof(unsigned int));\ std::cout<<_domainSize[0]<<_domainSize[1]<<_domainSize[2]<<_domainSize[3]<<std::endl;\ } \ dmoffset<1> _domainOffset; \ dmoffset<2> _domainSize; #define DESTROYPARAM() \ _domainOffset.kill();\ _domainSize.kill(); #endif // _KERNELINTERFACE_H_

0 Likes
2 Replies
gaurav_garg
Adept I

Thanks for the fix. You can submit this patch on sourceforge Brook+ project.

First file a bug on Brook+ explaining the problem you are trying to fix and attach the patch with the bug.

0 Likes

There are of course other ways to load Brook+ code dynamically, such as writing a dll wrapper around the Brook code.

For instance like I did for the GSM A5/1 rainbow table generator:

http://reflextor.com/trac/a51/browser/ati_shared_lib

 

0 Likes