⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flexptmi.cpp

📁 WinCE5.0部分核心源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        // Header only requests use virtual offset.
        // Otherwise, use the actual offset.
        if (fHeader && !fDesc && !fData)
            iElementStart = iVirtualOut;
        else
            iElementStart = iDataOut;

        // If data is being written, then actually write to the buffer.
        if (fData)
            pbDataOut = pbOut;

        // If no header is present, need to tell the user how many data elements
        // are in the output.
        DWORD iElementCnt;
        if (!fHeader)
        {
            iElementCnt = iDataOut;
            hr = Write ((DWORD)0, iDataOut, cbOut, pbDataOut);
        }
        
        if (SUCCEEDED (hr))
        {
            if (prsp->dwAddressMask & pRequest->dwRequest)
            {
                // Get a structure at a caller specified address
                hr = prsp->pfnMarshalOne (pRequest, iDataOut, cbOut, pbDataOut);
                if (SUCCEEDED (hr))
                    cElements = 1;
            }
            else
            {
                // Bulk get structures based on index.
                hr = prsp->pfnMarshal (pRequest, iDataOut, cbOut, pbDataOut, &cElements);
            }
        }

        // Write back the count if no header is present
        if (SUCCEEDED (hr) && !fHeader)
            hr = Write (cElements, iElementCnt, cbOut, pbDataOut); 

        if (SUCCEEDED(hr))
        {
            iVirtualOut += iDataOut - iDataStart;
            if (fData)
                riOut = iDataOut;
        }
    }

    // Patch in header information if necessary.
    if (SUCCEEDED (hr) && fHeader)
        hr = WritePTMResponseHeader (cFields, cElements, iElementStart, iHeaderStart, cbOut, pbOut);

    DEBUGGERMSG (OXZONE_FLEXI, (L"--WritePTMResponse: 0x%.08x\n", hr));
    return hr;
}


static HRESULT WriteRegistersForThread(CPUCONTEXT *pCtx, DWORD &riOut, const DWORD cbOut, BYTE *pbOut)
{
    HRESULT hr = S_OK;
    
#if defined(x86) // note:  size = 16 * sizeof(DWORD)
    OsAxsX86IntContext ctx;

    ctx.Gs = pCtx->TcxGs;
    ctx.Fs = pCtx->TcxFs;
    ctx.Es = pCtx->TcxEs;
    ctx.Ds = pCtx->TcxDs;
    ctx.Edi = pCtx->TcxEdi;
    ctx.Esi = pCtx->TcxEsi;
    ctx.Ebx = pCtx->TcxEbx;
    ctx.Edx = pCtx->TcxEdx;
    ctx.Ecx = pCtx->TcxEcx;
    ctx.Eax = pCtx->TcxEax;
    ctx.Ebp = pCtx->TcxEbp;
    ctx.Eip = pCtx->TcxEip;
    ctx.Cs = pCtx->TcxCs;
    ctx.Eflags = pCtx->TcxEFlags;
    ctx.Esp = pCtx->TcxEsp;
    ctx.Ss = pCtx->TcxSs;

    hr = Write (&ctx, sizeof (ctx), riOut, cbOut, pbOut);

#elif defined (SH4) // note:  size = 22 * sizeof(DWORD)
    OsAxsShxIntContext ctx;

    ctx.PR = pCtx->PR;
    ctx.MACH = pCtx->MACH;
    ctx.MACL = pCtx->MACL;
    ctx.GBR = pCtx->GBR;
    ctx.R[0] = pCtx->R0;
    ctx.R[1] = pCtx->R1;
    ctx.R[2] = pCtx->R2;
    ctx.R[3] = pCtx->R3;
    ctx.R[4] = pCtx->R4;
    ctx.R[5] = pCtx->R5;
    ctx.R[6] = pCtx->R6;
    ctx.R[7] = pCtx->R7;
    ctx.R[8] = pCtx->R8;
    ctx.R[9] = pCtx->R9;
    ctx.R[10] = pCtx->R10;
    ctx.R[11] = pCtx->R11;
    ctx.R[12] = pCtx->R12;
    ctx.R[13] = pCtx->R13;
    ctx.R[14] = pCtx->R14;
    ctx.R[15] = pCtx->R15;
    ctx.Fir = pCtx->Fir;
    ctx.Psr = pCtx->Psr;

    hr = Write (&ctx, sizeof (ctx), riOut, cbOut, pbOut);
    
#elif defined (ARM)
    OsAxsArmIntContext ctx;

    ctx.Psr = pCtx->Psr;
    ctx.R[0] = pCtx->R0;
    ctx.R[1] = pCtx->R1;
    ctx.R[2] = pCtx->R2;
    ctx.R[3] = pCtx->R3;
    ctx.R[4] = pCtx->R4;
    ctx.R[5] = pCtx->R5;
    ctx.R[6] = pCtx->R6;
    ctx.R[7] = pCtx->R7;
    ctx.R[8] = pCtx->R8;
    ctx.R[9] = pCtx->R9;
    ctx.R[10] = pCtx->R10;
    ctx.R[11] = pCtx->R11;
    ctx.R[12] = pCtx->R12;
    ctx.Sp = pCtx->Sp;
    ctx.Lr = pCtx->Lr;
    ctx.Pc = pCtx->Pc;

    hr = Write (&ctx, sizeof (ctx), riOut, cbOut, pbOut);

#elif defined (MIPS)

#ifdef _MIPS64
    OsAxsMips64IntContext ctx;
#else
    OsAxsMips32IntContext ctx;
#endif

    ctx.IntAt = pCtx->IntAt;

    ctx.IntV0 = pCtx->IntV0;
    ctx.IntV1 = pCtx->IntV1;

    ctx.IntA0 = pCtx->IntA0;
    ctx.IntA1 = pCtx->IntA1;
    ctx.IntA2 = pCtx->IntA2;
    ctx.IntA3 = pCtx->IntA3;

    ctx.IntT0 = pCtx->IntT0;
    ctx.IntT1 = pCtx->IntT1;
    ctx.IntT2 = pCtx->IntT2;
    ctx.IntT3 = pCtx->IntT3;
    ctx.IntT4 = pCtx->IntT4;
    ctx.IntT5 = pCtx->IntT5;
    ctx.IntT6 = pCtx->IntT6;
    ctx.IntT7 = pCtx->IntT7;

    ctx.IntS0 = pCtx->IntS0;
    ctx.IntS1 = pCtx->IntS1;
    ctx.IntS2 = pCtx->IntS2;
    ctx.IntS3 = pCtx->IntS3;
    ctx.IntS4 = pCtx->IntS4;
    ctx.IntS5 = pCtx->IntS5;
    ctx.IntS6 = pCtx->IntS6;
    ctx.IntS7 = pCtx->IntS7;

    ctx.IntT8 = pCtx->IntT8;
    ctx.IntT9 = pCtx->IntT9;

    ctx.IntK0 = pCtx->IntK0;
    ctx.IntK1 = pCtx->IntK1;

    ctx.IntGp = pCtx->IntGp;
    ctx.IntSp = pCtx->IntSp;

    ctx.IntS8 = pCtx->IntS8;

    ctx.IntRa = pCtx->IntRa;

    ctx.IntLo = pCtx->IntLo;
    ctx.IntHi = pCtx->IntHi;

    ctx.IntFir = pCtx->Fir;
    ctx.IntPsr = pCtx->Psr;

    hr = Write (&ctx, sizeof (ctx), riOut, cbOut, pbOut);

#endif /*#if defined (MIPS) */
    return hr;
}


static HRESULT WriteRegistersForAllThreads(FLEXI_REQUEST *pRequest, DWORD &riOut, const DWORD cbOut, BYTE *pbOut, DWORD *pcElements)
{
    HRESULT hr = S_OK;

    PROCESS *pProcArray;
    PTHREAD pThread;
    DWORD cThreadElements = 0;

    DEBUGGERMSG (OXZONE_FLEXI, (L"++WriteRegistersForAllThreads: Off:%d\r\n", riOut));

    pProcArray = FetchProcArray();
    if (!pProcArray)
        hr = E_FAIL;

    if ((pRequest->Proc.dwStart > pRequest->Proc.dwEnd) || (pRequest->Thread.dwStart > pRequest->Thread.dwEnd))
        hr = E_INVALIDARG;
    

    DWORD iProc = 0;
    DWORD iThread = 0;
    DWORD iProcSlot = 0;
    for (iProcSlot = 0; SUCCEEDED (hr) && iProcSlot < MAX_PROCESSES && iProc <= pRequest->Proc.dwEnd; iProcSlot++)
    {
        if (pProcArray[iProcSlot].dwVMBase)
        {
            if (!(pRequest->dwRequest & FLEXI_FILTER_PROCESS_HANDLE) || (reinterpret_cast<DWORD>(pProcArray[iProcSlot].hProc) == pRequest->dwHProc))
            {
                if (iProc >= pRequest->Proc.dwStart)
                {
                    pThread = pProcArray[iProcSlot].pTh;
                    while (SUCCEEDED (hr) && pThread && iThread <= pRequest->Thread.dwEnd)
                    {
                        if (!(pRequest->dwRequest & FLEXI_FILTER_THREAD_HANDLE) || (reinterpret_cast<DWORD>(pThread->hTh) == pRequest->dwHThread))
                        {
                            if (iThread >= pRequest->Thread.dwStart)
                            {
                                hr = Write ((DWORD)pThread->hTh, riOut, cbOut, pbOut);
                                if (SUCCEEDED (hr))
                                {
                                    if (! OsAxsIsCurThread (pThread))
                                        hr = WriteRegistersForThread (&pThread->ctx, riOut, cbOut, pbOut);
                                    else
                                        hr = WriteExceptionContext (riOut, cbOut, pbOut, TRUE);
                                }
                                cThreadElements++;    
                            }
                            iThread++;
                        }
                        else
                        {
                            DEBUGGERMSG(OXZONE_FLEXI, (L"  WriteRegistersForAllThreads: Thread 0x%.08x does not match handle 0x%.08x\r\n",
                                                       pThread, pRequest->dwHThread));
                        }
                        pThread = pThread->pNextInProc;
                    }
                }
                iProc++;
            }
            else
            {
                DEBUGGERMSG(OXZONE_FLEXI, (L"  WriteRegistersForAllThreads: Proc #%d does not match proc handle 0x%.08x\r\n",
                                           iProcSlot, pRequest->dwHProc));
            }
        }
    }

    if (pcElements)
        *pcElements = (SUCCEEDED (hr))? cThreadElements : 0;

        DEBUGGERMSG (OXZONE_FLEXI, (L"--WriteRegistersForAllThreads: 0x%.08x, Off:%d, Cnt:%d\r\n", hr, riOut, cThreadElements));

    return hr;
}


/*++

Routine Name:

    GetFPTMI

Routine Description:

    Handle Flexible Info request and package the response into a caller specified buffer.

Arguments:

    pRequest     - IN Request structure
    pcbOutBuffer - IN/OUT The size of the buffer / The size consumed by response.
    pbOutBuffer  - IN/OUT The response buffer.

Return Value:

    S_OK : success,
    E_FAIL : general failure,
    E_OUTOFMEMORY : buffer is too small, partial response contained within.

--*/
HRESULT GetFPTMI (FLEXI_REQUEST *pRequest, DWORD *pcbOutBuffer, BYTE *pbOutBuffer)
{
    HRESULT hr = S_OK;
    DWORD cbOutBuffer = *pcbOutBuffer;
    DWORD iOutBuffer = 0;

    DEBUGGERMSG (OXZONE_FLEXI, (L"++GetFPTMI: ReplyBuf = %d\r\n", cbOutBuffer));

    if (!pRequest || !pcbOutBuffer)
        hr = E_INVALIDARG;

    if (SUCCEEDED (hr) && (pRequest->dwRequest & FLEXI_REQ_PROCESS_ALL))
    {
        struct RespSt rsp = {FLEXI_REQ_PROCESS_HDR, FLEXI_REQ_PROCESS_DESC, FLEXI_REQ_PROCESS_DATA, FLEXI_FILTER_PROCESS_POINTER,
            MarshalProcessData, MarshalOneProcess, ProcessDesc, C_PROCESSFIELDS};
        hr = WritePTMResponse (pRequest, &rsp, iOutBuffer, cbOutBuffer, pbOutBuffer);
    }
    if (SUCCEEDED (hr) && (pRequest->dwRequest & FLEXI_REQ_THREAD_ALL))
    {
        struct RespSt rsp = {FLEXI_REQ_THREAD_HDR, FLEXI_REQ_THREAD_DESC, FLEXI_REQ_THREAD_DATA, FLEXI_FILTER_THREAD_POINTER,
            MarshalThreadData, MarshalOneThread, ThreadDesc, C_THREADFIELDS};
        hr = WritePTMResponse (pRequest, &rsp, iOutBuffer, cbOutBuffer, pbOutBuffer);
    }
    if (SUCCEEDED (hr) && (pRequest->dwRequest & FLEXI_REQ_MODULE_ALL))
    {
        struct RespSt rsp = {FLEXI_REQ_MODULE_HDR, FLEXI_REQ_MODULE_DESC, FLEXI_REQ_MODULE_DATA, FLEXI_FILTER_MODULE_POINTER,
            MarshalModuleData, MarshalOneModule, ModuleDesc, C_MODULEFIELDS};
        hr = WritePTMResponse (pRequest, &rsp, iOutBuffer, cbOutBuffer, pbOutBuffer);
    }
    else if (SUCCEEDED(hr) && (pRequest->dwRequest & FLEXI_REQ_CONTEXT_ALL))
    {
        FLEXI_FIELD_INFO rgFieldInfo[2] =
        {
            {cfiThreadId, cfsThreadId, L"ThreadID", L"0x%.08x"},
#if defined (x86)
            {cfiX86IntCxt, cfsX86IntCxt, L"X86 Integer Context", L""},
#elif defined (ARM)
            {cfiArmIntCxt, cfsArmIntCxt, L"Arm Integer Context", L""},
#elif defined (MIPS)
#ifdef _MIPS64
            {cfiMips64IntCxt, cfsMips64IntCxt, L"Mips64 Integer Context", L""},
#else
            {cfiMips32IntCxt, cfsMips32IntCxt, L"Mips32 Integer Context", L""},
#endif
#elif defined (SHx)
            {cfiSHxIntCxt, cfsSHxIntCxt, L"SH Integer Context", L""}
#endif
        };

        struct RespSt rsp = {FLEXI_REQ_CONTEXT_HDR, FLEXI_REQ_CONTEXT_DESC, 
            FLEXI_REQ_CONTEXT_DATA, 0, WriteRegistersForAllThreads, 0, rgFieldInfo, 2};
        
        hr = WritePTMResponse(pRequest, &rsp, iOutBuffer, cbOutBuffer, pbOutBuffer);
    }
    
    if (SUCCEEDED (hr))
        *pcbOutBuffer = iOutBuffer;
    
    DEBUGGERMSG (OXZONE_FLEXI || FAILED (hr), (L"--GetFPTMI: hr=0x%08x, bytes=%d\r\n", hr, iOutBuffer));
    return hr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -