In LLMachineID::init: Do not fail if CoInitializeEx fails, likely this happens due to some injected DLL already having called ColInitialize (With creates a single threaded apartment).

I the COM subsystem really failed to initialize later COM calls will fail with CO_E_NOTINITIALIZED and LLMachineID::init will handle this as an error and return;
meow-7.2.2
Nicky 2017-06-25 23:23:19 +02:00
parent c6108dfa73
commit d3e89cdea3
1 changed files with 36 additions and 12 deletions

View File

@ -37,6 +37,24 @@ using namespace std;
unsigned char static_unique_id[] = {0,0,0,0,0,0};
bool static has_static_unique_id = false;
class FSComInitialize
{
HRESULT mHR;
public:
FSComInitialize()
{
mHR = CoInitializeEx( 0, COINIT_MULTITHREADED );
if( FAILED( mHR ) )
LL_DEBUGS( "AppInit" ) << "Failed to initialize COM library. Error code = 0x" << hex << mHR << LL_ENDL;
}
~FSComInitialize()
{
if( SUCCEEDED( mHR ) )
CoUninitialize();
}
};
// get an unique machine id.
// NOT THREAD SAFE - do before setting up threads.
// MAC Address doesn't work for Windows 7 since the first returned hardware MAC address changes with each reboot, Go figure??
@ -59,12 +77,18 @@ S32 LLMachineID::init()
// Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
LL_DEBUGS("AppInit") << "Failed to initialize COM library. Error code = 0x" << hex << hres << LL_ENDL;
return 1; // Program has failed.
}
// <FS:ND> Do not fail in case CoInitialize fails as it can be harmless
//hres = CoInitializeEx(0, COINIT_MULTITHREADED);
//if (FAILED(hres))
//{
// LL_DEBUGS("AppInit") << "Failed to initialize COM library. Error code = 0x" << hex << hres << LL_ENDL;
// return 1; // Program has failed.
//}
FSComInitialize comInit;
// </FS:ND>
// Step 2: --------------------------------------------------
// Set general COM security levels --------------------------
@ -89,7 +113,7 @@ S32 LLMachineID::init()
if (FAILED(hres))
{
LL_WARNS("AppInit") << "Failed to initialize security. Error code = 0x" << hex << hres << LL_ENDL;
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
return 1; // Program has failed.
}
@ -107,7 +131,7 @@ S32 LLMachineID::init()
if (FAILED(hres))
{
LL_WARNS("AppInit") << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << LL_ENDL;
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
return 1; // Program has failed.
}
@ -134,7 +158,7 @@ S32 LLMachineID::init()
{
LL_WARNS("AppInit") << "Could not connect. Error code = 0x" << hex << hres << LL_ENDL;
pLoc->Release();
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
return 1; // Program has failed.
}
@ -160,7 +184,7 @@ S32 LLMachineID::init()
LL_WARNS("AppInit") << "Could not set proxy blanket. Error code = 0x" << hex << hres << LL_ENDL;
pSvc->Release();
pLoc->Release();
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
return 1; // Program has failed.
}
@ -181,7 +205,7 @@ S32 LLMachineID::init()
LL_WARNS("AppInit") << "Query for operating system name failed." << " Error code = 0x" << hex << hres << LL_ENDL;
pSvc->Release();
pLoc->Release();
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
return 1; // Program has failed.
}
@ -236,7 +260,7 @@ S32 LLMachineID::init()
pLoc->Release();
if (pEnumerator)
pEnumerator->Release();
CoUninitialize();
// CoUninitialize(); <FS:ND/> Counitialize will be handled by RAII class
ret_code=0;
#else
unsigned char * staticPtr = (unsigned char *)(&static_unique_id[0]);