Exemplo n.º 1
0
HRESULT RemoteDebuggerProxy::GetThreadContext(
    ICoreProcess* process, ICoreThread* thread, IRegisterSet*& regSet )
{
    _ASSERT( process != NULL );
    _ASSERT( thread != NULL );
    if ( process == NULL || thread == NULL )
        return E_INVALIDARG;

    if ( process->GetProcessType() != CoreProcess_Remote
            || thread->GetProcessType() != CoreProcess_Remote )
        return E_INVALIDARG;

    HRESULT hr = S_OK;
    ArchData* archData = process->GetArchData();
    ArchThreadContextSpec contextSpec;
    UniquePtr<BYTE[]> context;

    archData->GetThreadContextSpec( contextSpec );

    context.Attach( new BYTE[ contextSpec.Size ] );
    if ( context.IsEmpty() )
        return E_OUTOFMEMORY;

    hr = GetThreadContextNoException( process, thread, GetContextHandle(), contextSpec, context.Get() );
    if ( FAILED( hr ) )
        return hr;

    hr = archData->BuildRegisterSet( context.Get(), contextSpec.Size, regSet );
    if ( FAILED( hr ) )
        return hr;

    return S_OK;
}
Exemplo n.º 2
0
    HRESULT ImageDebugContainer::LoadDbg( 
        BinImage::ImageFile* image, 
        const IMAGE_DEBUG_DIRECTORY* miscDebugDir, 
        ILoadCallback* callback )
    {
        _ASSERT( image != NULL );
        _ASSERT( miscDebugDir != NULL );

        HRESULT     hr = S_OK;
        HandlePtr   hMapping;
        DWORD       viewAlignedAddr = 0;
        DWORD       viewDiff = 0;
        MappedPtr   view;
        IMAGE_DEBUG_MISC*       misc = NULL;
        UniquePtr<wchar_t[]>    strBuf;
        DWORD       dataLen = 0;

        if ( miscDebugDir->SizeOfData < sizeof( IMAGE_DEBUG_MISC ) )
            return E_FAIL;

        hr = image->GetMappingHandle( hMapping.Ref() );
        if ( FAILED( hr ) )
            return hr;

        AlignAddress( miscDebugDir->PointerToRawData, viewAlignedAddr, viewDiff );

        view = MapViewOfFile( hMapping, FILE_MAP_READ, 0, viewAlignedAddr, miscDebugDir->SizeOfData + viewDiff );
        if ( view.IsEmpty() )
            return GetLastHr();

        misc = (IMAGE_DEBUG_MISC*) view.Get();
        dataLen = misc->Length - offsetof( IMAGE_DEBUG_MISC, Data );

        if ( misc->DataType != IMAGE_DEBUG_MISC_EXENAME )
            return E_FAIL;

        // I don't know that the string in data is definitely \0 terminated, so we force it
        if ( misc->Unicode )
        {
            size_t  charCount = wcsnlen( (wchar_t*) misc->Data, dataLen / sizeof( wchar_t ) );

            // TODO: why were we calling wcsnlen twice?
            //charCount = wcsnlen( (wchar_t*) misc->Data, charCount );
            strBuf.Attach( new wchar_t[ charCount + 1 ] );
            if ( strBuf.Get() == NULL )
                return E_OUTOFMEMORY;

            // adds terminator
            wcsncpy_s( strBuf.Get(), charCount + 1, (wchar_t*) misc->Data, charCount );
        }
        else
        {
            size_t  charCount = strnlen( (char*) misc->Data, dataLen );
            int     nChars = 0;

            nChars = MultiByteToWideChar( 
                CP_ACP, 
                MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
                (char*) misc->Data,
                charCount,
                NULL,
                0 );
            if ( nChars == 0 )
                return GetLastHr();

            strBuf.Attach( new wchar_t[ nChars + 1 ] );
            if ( strBuf.Get() == NULL )
                return E_OUTOFMEMORY;

            nChars = MultiByteToWideChar( 
                CP_ACP, 
                MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
                (char*) misc->Data,
                charCount,
                strBuf.Get(),
                nChars + 1 );
            if ( nChars == 0 )
                return GetLastHr();

            strBuf[nChars] = L'\0';
        }

        hr = LoadDbg( strBuf.Get(), callback );

        return hr;
    }