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

📄 packdata.cpp

📁 WinCE5.0部分核心源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    DEBUGGERMSG (OXZONE_PACKDATA, (L"++UnpackThreadContext: pTh=0x%08x, cb=%d\r\n", pThread, cbCtx));

    if (
#if defined (ARM)
            cbCtx != sizeof (OsAxsArmIntContext)
#elif defined (MIPS)
#   ifdef _MIPS64
            cbCtx != sizeof (OsAxsMips64IntContext)
#   else
            cbCtx != sizeof (OsAxsMips32IntContext)
#   endif
#elif defined (SHx)
            cbCtx != sizeof (OsAxsShxIntContext)
#elif defined (x86)
            cbCtx != sizeof (OsAxsX86IntContext)
#else
#   error "Unknown CPU type"
#endif
       )
    {
        hr = E_FAIL;
    }

    if (SUCCEEDED (hr))
    {
#if defined (ARM)
        OsAxsArmIntContext *pCtx = reinterpret_cast <OsAxsArmIntContext *> (pvCtx);

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

#elif defined (MIPS)
#   ifdef _MIPS64
        OsAxsMips64IntContext *pCtx = reinterpret_cast <OsAxsMips64IntContext *> (pvCtx);
#   else
        OsAxsMips32IntContext *pCtx = reinterpret_cast <OsAxsMips32IntContext *> (pvCtx);
#   endif

        pThread->ctx.IntAt = pCtx->IntAt;

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

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

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

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

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

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

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

        pThread->ctx.IntS8 = pCtx->IntS8;

        pThread->ctx.IntRa = pCtx->IntRa;

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

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

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

#elif defined (x86)
        OsAxsX86IntContext *pCtx = reinterpret_cast <OsAxsX86IntContext *> (pvCtx);

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

#else
#   error "Unknown CPU type"
#endif
    }

    DEBUGGERMSG (OXZONE_PACKDATA, (L"--UnpackThreadContext: hr=0x%08x\r\n", hr));
    return hr;
}


HRESULT GetStruct (OSAXS_GETOSSTRUCT *pStruct, void *pvDestination, DWORD *pcb)
{
    HRESULT hr = E_FAIL;

    switch (pStruct->dwStructType)
    {
        case OSAXS_STRUCT_MODULE:
            if (*pcb >= sizeof (OSAXS_PORTABLE_MODULE))
            {
                *pcb = sizeof (OSAXS_PORTABLE_MODULE);
                if (pStruct->StructAddr)
                {
                    if (pStruct->StructAddr >= (DWORD) &ProcArray[0] && pStruct->StructAddr < (DWORD) &ProcArray[MAX_PROCESSES])
                        hr = PackModule ((PROCESS *) pStruct->StructAddr, (OSAXS_PORTABLE_MODULE *) pvDestination);
                    else
                        hr = PackModule ((MODULE *) pStruct->StructAddr, (OSAXS_PORTABLE_MODULE *) pvDestination);
                }
                else if (pStruct->dwStructHandle)
                {
                    hr = PackModule ((MODULE *) pStruct->dwStructHandle, (OSAXS_PORTABLE_MODULE *) pvDestination);
                }
            }
            else
            {
                hr = E_OUTOFMEMORY;
                *pcb = 0;
            }
            break;

        case OSAXS_STRUCT_PROCESS:
            if (*pcb >= sizeof(OSAXS_PORTABLE_PROCESS))
            {
                *pcb = sizeof(OSAXS_PORTABLE_PROCESS);
                if (pStruct->StructAddr)
                {
                    hr = PackProcess(reinterpret_cast<PROCESS*>(pStruct->StructAddr),
                                     reinterpret_cast<OSAXS_PORTABLE_PROCESS*>(pvDestination));
                }
                else if (pStruct->dwStructHandle)
                {
                    DWORD iProc;
                    hr = E_FAIL;
                    for (iProc = 0; iProc < MAX_PROCESSES; iProc++)
                    {
                        if (ProcArray[iProc].dwVMBase &&
                              reinterpret_cast<DWORD>(ProcArray[iProc].hProc) == pStruct->dwStructHandle)
                        {
                            hr = PackProcess(&ProcArray[iProc],
                                             reinterpret_cast<OSAXS_PORTABLE_PROCESS*>(pvDestination));
                            break;
                        }
                    }
                }
            }
            else
            {
                hr = E_OUTOFMEMORY;
                *pcb = 0;
            }
            break;

        case OSAXS_STRUCT_THREAD:
            if (*pcb >= sizeof (OSAXS_PORTABLE_THREAD))
            {
                *pcb = sizeof (OSAXS_PORTABLE_THREAD);
                if (pStruct->StructAddr)
                {
                    hr = PackThread (reinterpret_cast <THREAD *> (pStruct->StructAddr),
                            reinterpret_cast <OSAXS_PORTABLE_THREAD *> (pvDestination));
                }
                else if (pStruct->dwStructHandle)
                {
                    hr = E_FAIL;
                }
            }
            else
            {
                hr = E_OUTOFMEMORY;
                *pcb = 0;
            }
            break;

        default:
            hr = E_FAIL;
            break;
    }
    return hr;
}


HRESULT GetModuleO32Data (DWORD dwAddrModule, DWORD *pdwNumO32Data, void *pvResult, DWORD *pcbResult)
{
    HRESULT hr = S_OK;
    o32_lite *o32_ptr = NULL;
    DWORD co32 = 0;

    DEBUGGERMSG (OXZONE_PACKDATA, (L"++GetModuleO32Data: 0x%08x\r\n", dwAddrModule));
    __try
    {
        if ((dwAddrModule >= reinterpret_cast <DWORD> (&g_OsaxsData.pProcArray [0])) && 
                (dwAddrModule < reinterpret_cast <DWORD> (&g_OsaxsData.pProcArray [MAX_PROCESSES])))
        {
            PROCESS *pProcess = reinterpret_cast <PROCESS *> (dwAddrModule);
            PMODULE pCoreDll = (PMODULE)hCoreDll;
            DWORD dwInUse = (1 << pProcess->procnum);

            if (!pCoreDll || !(dwInUse & pCoreDll->inuse))
            {
                DBGRETAILMSG (1, (L"  GetModuleO32Data: Bad process struct @0x%08x\r\n", pProcess));
                hr = E_FAIL;
            }
            else
            {
                co32 = pProcess->e32.e32_objcnt;
                o32_ptr = pProcess->o32_ptr;
                DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetModuleO32Data: Process data.\r\n"));
            }
        }
        else
        {
            Module *pMod = reinterpret_cast <MODULE *> (dwAddrModule);
            if (pMod && pMod->lpSelf == pMod)
            {
                if (pMod->inuse)
                {
                    co32 = pMod->e32.e32_objcnt;
                    o32_ptr = pMod->o32_ptr;

                    DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetModuleO32Data: Module data.\r\n"));
                }
                else
                {
                    DBGRETAILMSG (1, (L"  GetModuleO32Data: Module is not being used, inuse=0\r\n"));
                    hr = E_FAIL;
                }
            }
            else
            {
                DEBUGGERMSG (1, (L"  GetModuleO32Data: Not a module 0x%08x\r\n", dwAddrModule));
                hr = E_FAIL;
            }
        }

        if (SUCCEEDED (hr))
        {
            // copy out the o32_ptr data.
            size_t cbO32Data = sizeof (o32_lite) * co32;

            DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetModuleO32Data: num o32_lite=%d, addr o32_lite=0x%08x\r\n", co32, o32_ptr));

            *pdwNumO32Data = co32;
            if (cbO32Data)
            {
                if (*pcbResult >= cbO32Data)
                {
                    if (o32_ptr)
                    {
                        SafeMoveMemory (pCurProc, pvResult, o32_ptr, cbO32Data);
                    }
                    else
                    {
                        DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetModuleO32Data: o32_ptr is null?\r\n"));
                        cbO32Data = 0;
                        *pdwNumO32Data = 0;
                    }
                }
                else
                {
                    DBGRETAILMSG (1, (L"  GetModuleO32Data: Not enough room in the result buffer!\r\n"));
                    hr = E_OUTOFMEMORY;
                }
            }

            if (SUCCEEDED (hr))
            {
                *pcbResult = cbO32Data;
            }
            else
            {
                *pcbResult = 0;
            }
        }
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        DBGRETAILMSG (1, (L"  GetModuleO32Data: Unexpected exception.\r\n"));
        hr = E_FAIL;
    }
    DBGRETAILMSG (OXZONE_PACKDATA || FAILED (hr), (L"--GetModuleO32Data: hr=0x%08x, pmod=0x%08x\r\n", hr, dwAddrModule));
    return hr;
}

#if defined(x86)
PVOID __inline GetRegistrationHead(void)
{
    __asm mov eax, dword ptr fs:[0];
}

HRESULT GetExceptionRegistration(DWORD *pdwBuff)
{
    DEBUGGERMSG (OXZONE_PACKDATA, (L"++GetExceptionRegistration\r\n"));
    HRESULT hr = E_FAIL;

    // This is only valid for x86.  It is used by the debugger for unwinding through exception handlers.
    if (pdwBuff)
    {
        CALLSTACK* pStack = NULL;
        PVOID pRegistration = NULL;
        PVOID pvCallStack = pdwBuff + sizeof(DWORD);

        memcpy(&pStack, pvCallStack, sizeof(VOID*));
        if (pStack)
        {
            // We are at a PSL boundary and need to look up the next registration
            // pointer -- don't trust the pointer we got from the host
            pRegistration = (VOID*)pStack->extra;
            pStack = pStack->pcstkNext;
        }
        else
        {
            // Request for the registration head pointer
            pRegistration = GetRegistrationHead();
            pStack = pCurThread->pcstkTop;
        }

        memcpy(pdwBuff, &pRegistration, sizeof(VOID*));
        memcpy(pvCallStack, &pStack, sizeof(VOID*));
        DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetExceptionRegistration:  Registration Ptr: %8.8lx pCallStack: %8.8lx\r\n", (DWORD)pRegistration, (DWORD)pStack));
        hr = S_OK;
    }
    else
    {
        DEBUGGERMSG (OXZONE_PACKDATA, (L"  GetExceptionRegistration:  Invalid parameter\r\n", hr));
    }

    DEBUGGERMSG (OXZONE_PACKDATA, (L"--GetExceptionRegistration:  hr=0x%08x\r\n", hr));
    return hr;
}
#endif

⌨️ 快捷键说明

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