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

📄 dwdmpgen.cpp

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

    pTOC = FetchTOC();
    if (NULL == pTOC )
    {
        DEBUGGERMSG(OXZONE_ALERT,(L"  DwDmpGen!MemoryAddAllPhysical: FetchTOC returned NULL\r\n"));
        hRes = E_FAIL;
        goto Exit;
    }

    pMemoryInfo = FetchMemoryInfo();
    if (NULL == pMemoryInfo)
    {
        DEBUGGERMSG(OXZONE_ALERT,(L"  DwDmpGen!MemoryAddAllPhysical: FetchMemoryInfo returned NULL\r\n"));
        hRes = E_FAIL;
        goto Exit;
    }

    pLogPtr = FetchLogPtr();
    if (NULL == pLogPtr)
    {
        DEBUGGERMSG(OXZONE_ALERT,(L"  DwDmpGen!MemoryAddAllPhysical: FetchLogPtr returned NULL\r\n"));
        hRes = E_FAIL;
        goto Exit;
    }

#if defined(ARM)
    // Dump Arm FirstPT memory
    dwMemoryStart = (DWORD)ArmHigh->firstPT;
    dwMemorySize  = sizeof(ArmHigh->firstPT);

    DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddAllPhysical: Adding Arm FirstPT memory block\r\n"));
    
    hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, PHYSICAL_MEMORY, fWrite);
    if (FAILED(hRes))
    {
        DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddAllPhysical: MemoryBlocksAdd failed adding Arm FirstPT memory block, hRes=0x%08X\r\n", hRes));
        goto Exit;
    }
#endif

    // Dump KData memory
    dwMemoryStart = (DWORD)pKData;
    dwMemorySize  = sizeof(KDataStruct);

    DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddAllPhysical: Adding KData memory block\r\n"));
    
    hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, PHYSICAL_MEMORY, fWrite);
    if (FAILED(hRes))
    {
        DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddAllPhysical: MemoryBlocksAdd failed adding KData memory block, hRes=0x%08X\r\n", hRes));
        goto Exit;
    }

    // Dump Nk.bin Code memory
    dwMemoryStart = pTOC->physfirst;
    dwMemorySize  = pTOC->physlast - pTOC->physfirst;

    DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddAllPhysical: Adding nk.bin memory block\r\n"));
    
    hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, PHYSICAL_MEMORY, fWrite);
    if (FAILED(hRes))
    {
        DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddAllPhysical: MemoryBlocksAdd failed adding nk.bin memory block, hRes=0x%08X\r\n", hRes));
        goto Exit;
    }

    // Dump base RAM section
    KD_ASSERT(pLogPtr->fsmemblk[0].startptr == PAGEALIGN_UP(pTOC->ulRAMFree+MemForPT) + 4096);
    KD_ASSERT((pTOC->ulRAMStart <= pTOC->ulRAMFree) && (pTOC->ulRAMFree < pTOC->ulRAMEnd));
   
    MainMemoryEndAddress = pLogPtr->fsmemblk[0].startptr + pLogPtr->fsmemblk[0].extension + pLogPtr->fsmemblk[0].length;
    dwMemoryStart = pTOC->ulRAMStart;
    dwMemorySize  = MainMemoryEndAddress - pTOC->ulRAMStart;

    DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddAllPhysical: Adding base RAM memory block\r\n"));
    
    hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, PHYSICAL_MEMORY, fWrite);
    if (FAILED(hRes))
    {
        DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddAllPhysical: MemoryBlocksAdd failed adding base RAM memory block, hRes=0x%08X\r\n", hRes));
        goto Exit;
    }

    // Dump any extension RAM sections    
    for (dwSection = 1; dwSection < pMemoryInfo->cFi; ++ dwSection)
    {
        dwMemoryStart = (DWORD) (pLogPtr->fsmemblk[dwSection].startptr);
        dwMemorySize  = (DWORD) (pLogPtr->fsmemblk[dwSection].extension + pLogPtr->fsmemblk[dwSection].length);
        if (dwMemorySize > 0)
        {
            DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddAllPhysical: Adding extension RAM memory block%u\r\n", dwSection));
            
            hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, PHYSICAL_MEMORY, fWrite);
            if (FAILED(hRes))
            {
                DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddAllPhysical: MemoryBlocksAdd failed adding extension RAM memory block%u, hRes=0x%08X\r\n", dwSection, hRes));
                goto Exit;
            }
        }
    }        

    hRes = S_OK;

Exit:
    
    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"--DwDmpGen!MemoryAddAllPhysical: Leave, hRes=0x%08X\r\n", hRes));
    return hRes;
}

/*----------------------------------------------------------------------------
    MemoryAddProcessHeap

    Add all R/W sections for passed in process.
----------------------------------------------------------------------------*/
HRESULT MemoryAddProcessHeap(PPROCESS pProcess, BOOL fWrite)
{
    HRESULT hRes = E_FAIL;
    DWORD dwMemoryStart = 0;
    DWORD dwMemorySize = 0;
    DWORD ixSection, ixBlock, ixPage;
    PSECTION pscn;
    MEMBLOCK *pmb;
    DWORD    ulPTE;

    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"++DwDmpGen!MemoryAddProcessHeap: Enter\r\n"));

    KD_ASSERT(NULL != pProcess);
    if (NULL == pProcess)
    {
        hRes = E_INVALIDARG;
        goto Exit;
    }

    if (pProcess->dwVMBase)
    {
        if (pProcess->procnum)
        {
            ixSection = pProcess->procnum + RESERVED_SECTIONS;
            pscn = SectionTable[ixSection];
            KD_ASSERT(pscn != &NKSection);
        }
        else
        {
            // Special case for nk.exe 
            pscn = &NKSection;
            ixSection = SECURE_SECTION;
        }

        KD_ASSERT(pscn != NULL_SECTION);

        for (ixBlock = 0 ; ixBlock < BLOCK_MASK+1 ; ++ixBlock)
        {
            if (((pmb = (*pscn)[ixBlock]) != NULL_BLOCK) && (RESERVED_BLOCK != pmb))
            {
                for (ixPage = 0 ; ixPage < PAGES_PER_BLOCK ; ++ixPage)
                {
                    ulPTE = pmb->aPages[ixPage];
                    if ((ulPTE & PG_VALID_MASK)                     // valid page
                        && IsPageWritable (ulPTE))                  // R/W
                    {
                        // Found a writable memory page, assume it is part of the heap (or globals)
                        dwMemoryStart = (DWORD) (ixSection << VA_SECTION) | (ixBlock << VA_BLOCK) | (ixPage << VA_PAGE);
                        dwMemorySize = PAGE_SIZE;
                        DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddProcessHeap: Adding '%s' heap memory -> ProcessID=0x%08X\r\n", 
                                                     pProcess->lpszProcName, pProcess->hProc));
                        
                        hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, VIRTUAL_MEMORY, fWrite);
                        if (FAILED(hRes))
                        {
                            DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddProcessHeap: MemoryBlocksAdd failed adding '%s' heap memory, ProcessID=0x%08X, hRes=0x%08X\r\n", 
                                                      pProcess->lpszProcName, pProcess->hProc, hRes));
                            goto Exit;
                        }
                    }
                }
            }
        }
    }

    hRes = S_OK;

Exit:
    
    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"--DwDmpGen!MemoryAddProcessHeap: Leave, hRes=0x%08X\r\n", hRes));
    return hRes;
}

/*----------------------------------------------------------------------------
    MemoryAddProcessGlobals

    Add the global memory sections for passed in process.
----------------------------------------------------------------------------*/
HRESULT MemoryAddProcessGlobals(PPROCESS pProcess, BOOL fWrite)
{
    HRESULT hRes = E_FAIL;
    DWORD dwO32count;
    DWORD dwMemoryStart;
    DWORD dwMemorySize;
    ROMHDR *pTOC;
    COPYentry *pce;

    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"++DwDmpGen!MemoryAddProcessGlobals: Enter\r\n"));

    KD_ASSERT(NULL != pProcess);
    if (NULL == pProcess)
    {
        hRes = E_INVALIDARG;
        goto Exit;
    }

    if (0 == pProcess->procnum)
    {
        // Special case for nk.exe
        if (TRUE == g_fDumpNkGlobals)
        {
            pTOC = FetchTOC();
            if (NULL != pTOC)
            {
                pce = FetchCopyEntry (pTOC->ulCopyOffset);
                if (NULL != pce)
                {
                    // Indicate that nk.exe globals dumped (optimization needs to know)
                    g_fNkGlobalsDumped = TRUE;
                    
                    dwMemoryStart = pce->ulDest;
                    dwMemorySize = pce->ulDestLen;
                    DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddProcessGlobals: Adding '%s' global variable memory -> ProcessID=0x%08X\r\n", 
                                                 pProcess->lpszProcName, pProcess->hProc));
                    
                    hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, VIRTUAL_MEMORY, fWrite);
                    if (FAILED(hRes))
                    {
                        DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddProcessGlobals: MemoryBlocksAdd failed adding '%s' global variable memory -> ProcessID=0x%08X, hRes=0x%08X\r\n", 
                                                  pProcess->lpszProcName, pProcess->hProc, hRes));
                        goto Exit;
                    }
                }
            }
        }
    }
    else
    {
        // All other processes
        for (dwO32count=0; dwO32count < pProcess->e32.e32_objcnt; dwO32count++)
        {
            if (pProcess->o32_ptr && (pProcess->o32_ptr[dwO32count].o32_flags & IMAGE_SCN_MEM_WRITE))
            {
                // Found a writable memory section
                dwMemoryStart = (DWORD) MapPtrProc(pProcess->o32_ptr[dwO32count].o32_realaddr, pProcess);
                dwMemorySize = pProcess->o32_ptr[dwO32count].o32_vsize;
                DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddProcessGlobals: Adding '%s' global variable memory%u -> ProcessID=0x%08X\r\n", 
                                             pProcess->lpszProcName, dwO32count, pProcess->hProc));
                
                hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, VIRTUAL_MEMORY, fWrite);
                if (FAILED(hRes))
                {
                    DEBUGGERMSG(OXZONE_ALERT, (L"  DwDmpGen!MemoryAddProcessGlobals: MemoryBlocksAdd failed adding '%s' global variable memory%u -> ProcessID=0x%08X, hRes=0x%08X\r\n", 
                                              pProcess->lpszProcName, dwO32count, pProcess->hProc, hRes));
                    goto Exit;
                }
            }
        }
    }

    hRes = S_OK;

Exit:
    
    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"--DwDmpGen!MemoryAddProcessGlobals: Leave, hRes=0x%08X\r\n", hRes));
    return hRes;
}

/*----------------------------------------------------------------------------
    MemoryAddModuleGlobals

    Add the global memory sections for passed in process.
----------------------------------------------------------------------------*/
HRESULT MemoryAddModuleGlobals(PMODULE pMod, HPROCESS hFrameProcess, BOOL fWrite)
{
    HRESULT hRes = E_FAIL;
    DWORD dwO32count = 0;
    DWORD dwMemoryStart = 0;
    DWORD dwMemorySize = 0;
    PPROCESS pProcess = NULL;

    DEBUGGERMSG(OXZONE_DWDMPGEN,(L"++DwDmpGen!MemoryAddModuleGlobals: Enter\r\n"));

    KD_ASSERT(NULL != pMod);
    if (NULL == pMod)
    {
        hRes = E_INVALIDARG;
        goto Exit;
    }

    pProcess = HandleToProc(hFrameProcess);
    if (NULL == pProcess)
    {
        DEBUGGERMSG(OXZONE_ALERT,(L"  DwDmpGen!MemoryAddModuleGlobals: HandleToProc returned NULL\r\n"));
        hRes = E_FAIL;
        goto Exit;
    }

    if (pMod->rwLow >= pMod->rwHigh)
    {
        for (dwO32count=0; dwO32count < pMod->e32.e32_objcnt; dwO32count++)
        {
            if (pMod->o32_ptr && (pMod->o32_ptr[dwO32count].o32_flags & IMAGE_SCN_MEM_WRITE))
            {
                // Found a writable memory section
                dwMemoryStart = (DWORD) MapPtrProc(ZeroPtr(pMod->o32_ptr[dwO32count].o32_realaddr), pProcess);
                dwMemorySize = pMod->o32_ptr[dwO32count].o32_vsize;
                DEBUGGERMSG(OXZONE_DWDMPGEN, (L"  DwDmpGen!MemoryAddModuleGlobals: Adding '%s' global variable memory%u for '%s'\r\n", 
                                             pMod->lpszModName, dwO32count, pProcess->lpszProcName));
                
                hRes = MemoryBlocksAdd(dwMemoryStart, dwMemorySize, VIRTUAL_MEMORY, fWrite);
                if (FAILED(hRes))
                {
                    DEBUGGERMSG(OXZONE_ALERT,(L"  DwDmpGen!MemoryAddModuleGlobals: MemoryBlocksAdd failed adding '%s' global variable memory%u for '%s', hRes=0x%08X\r\n", 
                                              pMod->lpszModName, dwO32count, pProcess->lpszProcName, hRes));
                    goto Exit;
                }
            }
        }
    }
   

⌨️ 快捷键说明

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