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

Function ScriptEngineFunctionPrintf

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

* @brief Implementation of printf function * * @param GuestRegs * @param ActionDetail * @param ScriptGeneralRegisters * @param Tag * @param ImmediateMessagePassing * @param Format * @param ArgCount * @param FirstArg * @param HasError * @return VOID */

Source from the content-addressed store, hash-verified

1568 * @return VOID
1569 */
1570VOID
1571ScriptEngineFunctionPrintf(PGUEST_REGS GuestRegs,
1572 ACTION_BUFFER * ActionDetail,
1573 SCRIPT_ENGINE_GENERAL_REGISTERS * ScriptGeneralRegisters,
1574 UINT64 Tag,
1575 BOOLEAN ImmediateMessagePassing,
1576 char * Format,
1577 UINT64 ArgCount,
1578 PSYMBOL FirstArg,
1579 BOOLEAN * HasError)
1580{
1581 //
1582 // *** The printf function ***
1583 //
1584
1585 char FinalBuffer[PacketChunkSize] = {0};
1586 UINT32 CurrentPositionInFinalBuffer = 0;
1587 UINT32 CurrentProcessedPositionFromStartOfFormat = 0;
1588 BOOLEAN WithoutAnyFormatSpecifier = TRUE;
1589
1590 UINT64 Val;
1591 UINT32 Position;
1592 UINT32 LenOfFormats = (UINT32)strlen(Format) + 1;
1593 PSYMBOL Symbol;
1594
1595 *HasError = FALSE;
1596
1597 for (int i = 0; i < ArgCount; i++)
1598 {
1599 WithoutAnyFormatSpecifier = FALSE;
1600 Symbol = FirstArg + i;
1601
1602 //
1603 // Address is either wstring (%ws) or string (%s)
1604 //
1605
1606 Position = (Symbol->Type >> 32) + 1;
1607
1608 SYMBOL TempSymbol = {0};
1609 memcpy(&TempSymbol, Symbol, sizeof(SYMBOL));
1610 TempSymbol.Type &= 0x7fffffff;
1611
1612 Val = GetValue(GuestRegs, ActionDetail, ScriptGeneralRegisters, &TempSymbol, FALSE);
1613
1614 CHAR PercentageChar = Format[Position];
1615
1616 // printf("position = %d is %c%c \n", Position, PercentageChar, IndicatorChar1);
1617
1618 if (CurrentProcessedPositionFromStartOfFormat != Position)
1619 {
1620 //
1621 // There is some strings before this format specifier
1622 // we should move it to the buffer
1623 //
1624 UINT32 StringLen = Position - CurrentProcessedPositionFromStartOfFormat;
1625
1626 //
1627 // Check final buffer capacity

Callers 1

ScriptEngineExecuteFunction · 0.85

Calls 3

GetValueFunction · 0.85
ApplyFormatSpecifierFunction · 0.85

Tested by

no test coverage detected