MCPcopy Create free account
hub / github.com/HyperDbg/HyperDbg / ScriptEngineFunctionMemcpyPa

Function ScriptEngineFunctionMemcpyPa

hyperdbg/script-eval/code/Functions.c:452–543  ·  view source on GitHub ↗

* @brief A VMX-compatible equivalent of memcpy function in C for physical memory * * @param Destination * @param Source * @param Num * @param HasError * @return VOID */

Source from the content-addressed store, hash-verified

450 * @return VOID
451 */
452VOID
453ScriptEngineFunctionMemcpyPa(UINT64 Destination, UINT64 Source, UINT32 Num, BOOL * HasError)
454{
455 UINT64 PrevReadLen = 0;
456 BYTE MovingBuffer[DebuggerScriptEngineMemcpyMovingBufferSize] = {0};
457
458#ifdef SCRIPT_ENGINE_USER_MODE
459
460 //
461 // Show an error message in user-mode
462 //
463 ShowMessages("err, using physical address functions (memcpy_pa) is not possible in user-mode\n");
464 return;
465
466#endif // SCRIPT_ENGINE_USER_MODE
467
468#ifdef SCRIPT_ENGINE_KERNEL_MODE
469
470 //
471 // Check the destination address (physical)
472 //
473 if (!CheckAddressPhysical(Destination))
474 {
475 *HasError = TRUE;
476 return;
477 }
478
479 //
480 // Check the source address (physical)
481 //
482 if (!CheckAddressPhysical(Source))
483 {
484 *HasError = TRUE;
485 return;
486 }
487
488 //
489 // Address is valid, perform the memcpy in kernel-mode (VMX-root mode)
490 //
491 while (Num > 0)
492 {
493 //
494 // Check the target buffer size
495 //
496 if (Num > DebuggerScriptEngineMemcpyMovingBufferSize)
497 {
498 //
499 // *** The size of read buffer is greater to maximum the moving buffer size ***
500 //
501
502 //
503 // Read memory into the buffer
504 //
505 MemoryMapperReadMemorySafeByPhysicalAddress(Source + PrevReadLen, (UINT64)MovingBuffer, DebuggerScriptEngineMemcpyMovingBufferSize);
506
507 //
508 // Write the moving buffer into the target buffer
509 //

Callers 1

ScriptEngineExecuteFunction · 0.85

Tested by

no test coverage detected