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

Function ApplyStringFormatSpecifier

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

* @brief Apply string format specifiers (%s, %ws, etc.) * * @param CurrentSpecifier * @param FinalBuffer * @param CurrentProcessedPositionFromStartOfFormat * @param CurrentPositionInFinalBuffer * @param Val * @param IsWstring * @param SizeOfFinalBuffer * @return BOOLEAN */

Source from the content-addressed store, hash-verified

1408 * @return BOOLEAN
1409 */
1410BOOLEAN
1411ApplyStringFormatSpecifier(const CHAR * CurrentSpecifier, CHAR * FinalBuffer, PUINT32 CurrentProcessedPositionFromStartOfFormat, PUINT32 CurrentPositionInFinalBuffer, UINT64 Val, BOOLEAN IsWstring, UINT32 SizeOfFinalBuffer)
1412{
1413 UINT32 StringSize;
1414 wchar_t WstrBuffer[50];
1415 CHAR AsciiBuffer[sizeof(WstrBuffer) / 2];
1416 UINT32 StringSizeInByte; /* because of wide-char */
1417 UINT32 CountOfBlocks;
1418 UINT32 CopiedBlockLen;
1419
1420 //
1421 // First we have to check if string is valid or not
1422 //
1423 if (!CheckIfStringIsSafe(Val, IsWstring))
1424 {
1425 return FALSE;
1426 }
1427
1428 //
1429 // get the length of the string (format) identifier
1430 //
1431 *CurrentProcessedPositionFromStartOfFormat += (UINT32)strlen(CurrentSpecifier);
1432
1433 //
1434 // Get string len
1435 //
1436 StringSize = CustomStrlen(Val, IsWstring);
1437
1438 //
1439 // Check final buffer capacity
1440 //
1441 if (*CurrentPositionInFinalBuffer + StringSize > SizeOfFinalBuffer)
1442 {
1443 //
1444 // Over passed buffer
1445 //
1446 return TRUE;
1447 }
1448
1449 //
1450 // Move the buffer string into the target buffer
1451 //
1452 if (IsWstring)
1453 {
1454 //
1455 // Parse wstring
1456 //
1457 StringSizeInByte = StringSize * 2; /* because of wide-char */
1458
1459 //
1460 // compute the ceiling
1461 //
1462 if (StringSizeInByte % sizeof(WstrBuffer) == 0)
1463 {
1464 CountOfBlocks = StringSizeInByte / sizeof(WstrBuffer);
1465 }
1466 else
1467 {

Callers 1

Calls 5

CheckIfStringIsSafeFunction · 0.85
CustomStrlenFunction · 0.85
WcharToCharFunction · 0.85
PlatformZeroMemoryFunction · 0.50

Tested by

no test coverage detected