示例#1
0
BOOL ReadImageGlobalFlagsFromRegistry( _In_z_ PCWSTR ImageName, _Out_ ULONG* Flag )
{
    HKEY hKey;
    WCHAR FullKey[260];
    if(!ImageName || !ImageName[0])
    {
        *Flag = 0;
        return TRUE;
    }
    StringCchPrintfW(FullKey, 260, IMAGE_FILE_OPTIONS, ImageName);
    if(EnableDebug())
    {
        LONG lRet = RegOpenKeyExW( HKEY_LOCAL_MACHINE, FullKey, 0, KEY_READ, &hKey );
        if( ERROR_SUCCESS == lRet )
        {
            AutoCloseReg raii(hKey);
            DWORD Type = 0, cbData = sizeof(*Flag);
            if( ERROR_SUCCESS == RegQueryValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, &Type, (LPBYTE)Flag, &cbData ) && Type == REG_DWORD )
            {
                return TRUE;
            }
        }
        else if(ERROR_FILE_NOT_FOUND == lRet)
        {
            *Flag = 0;
            return TRUE;
        }
    }
    return FALSE;
}
    void multithreaded_object::
    thread_helper(
    )
    {
        mfp mf;
        thread_id_type id = get_thread_id();

        // this guy's destructor does all the necessary cleanup in this function
        raii_thread_helper raii(*this, id);

        // if there is a dead_thread sitting around then pull it
        // out and put it into mf
        {
            auto_mutex M(m_);
            if (dead_threads.size() > 0)
            {
                dead_threads.dequeue(mf);
                mfp temp(mf);
                thread_ids.add(id,temp);
            }
        }

        if (mf.is_set())
        {
            // call the registered thread function
            mf();
        }
    }
示例#3
0
BOOL WriteGlobalFlagsToRegistry( _In_ DWORD Flag )
{
    HKEY hKey;
    if(EnableDebug() && ERROR_SUCCESS == RegOpenKeyExW( HKEY_LOCAL_MACHINE, GLOBALFLAG_REGKEY, 0, KEY_WRITE, &hKey ) )
    {
        AutoCloseReg raii(hKey);
        if( ERROR_SUCCESS == RegSetValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, REG_DWORD, (LPBYTE)&Flag, sizeof(Flag) ) )
        {
            return TRUE;
        }
    }
    return FALSE;
}
示例#4
0
BOOL ReadGlobalFlagsFromRegistry( _Out_ DWORD* Flag )
{
    HKEY hKey;
    if(EnableDebug() && ERROR_SUCCESS == RegOpenKeyExW( HKEY_LOCAL_MACHINE, GLOBALFLAG_REGKEY, 0, KEY_READ, &hKey ) )
    {
        AutoCloseReg raii(hKey);
        DWORD Type = 0, cbData = sizeof(*Flag);
        if( ERROR_SUCCESS == RegQueryValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, &Type, (LPBYTE)Flag, &cbData ) && Type == REG_DWORD )
        {
            return TRUE;
        }
    }
    return FALSE;
}
示例#5
0
BOOL WriteImageGlobalFlagsToRegistry( _In_z_ PCWSTR ImageName,_In_ ULONG Flag )
{
    HKEY hKey;
    WCHAR FullKey[260];
    StringCchPrintfW(FullKey, 260, IMAGE_FILE_OPTIONS, ImageName);
    DWORD dwDisposition = 0;
    if(EnableDebug() && ERROR_SUCCESS == RegCreateKeyExW( HKEY_LOCAL_MACHINE, FullKey, 0, 0, 0, KEY_WRITE, NULL, &hKey, &dwDisposition ))
    {
        AutoCloseReg raii(hKey);
        //dwDisposition == REG_CREATED_NEW_KEY || REG_OPENED_EXISTING_KEY;
        if( ERROR_SUCCESS == RegSetValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, REG_DWORD, (LPBYTE)&Flag, sizeof(Flag) ) )
        {
            return TRUE;
        }
    }
    return FALSE;

}
示例#6
0
BOOL EnableDebug()
{
    static BOOL debugEnabled = FALSE;
    if( !debugEnabled )
    {
        HANDLE hToken;
        if( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken ) )
        {
            AutoCloseHandle raii(hToken);
            TOKEN_PRIVILEGES tp = {0};
            tp.PrivilegeCount = 1;
            tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
            if( LookupPrivilegeValueW( NULL, L"SeDebugPrivilege", &tp.Privileges[0].Luid) )
            {
                debugEnabled = AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof(tp), NULL, NULL );
            }
        }
    }
    return debugEnabled;
}