VirtualBox

Changeset 100542 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jul 12, 2023 11:23:07 AM (21 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158356
Message:

DevFwCommon: Add an experimental way for using the DmiSystemUuid (with fallback to HW UUID) in strings. Could make sense with constructing unique serial numbers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevFwCommon.cpp

    r98103 r100542  
    4646#include <iprt/system.h>
    4747#include <iprt/cdefs.h>
     48#include <iprt/alloca.h>
    4849
    4950#include "VBoxDD.h"
     
    435436
    436437/**
     438 * Replace the DmiSystemUuid placeholder with the actual value.
     439 *
     440 * @param   pszBuf              Buffer
     441 * @param   cbBuf               Size of buffer
     442 * @param   pcszPlaceholder     Pointer to placeholder, must be in pszBuf
     443 * @param   cbPlaceholder       Length of placeholder
     444 * @param   pcszDmiSystemUuid   DmiSystemUuid value
     445 */
     446static void fwUseDmiSystemUuidInString(char *pszBuf, size_t cbBuf,
     447                                       const char *pcszPlaceholder, size_t cbPlaceholder,
     448                                       const char *pcszDmiSystemUuid)
     449{
     450    size_t const cbPrefix = pcszPlaceholder - pszBuf;
     451    size_t const cbUuid = strlen(pcszDmiSystemUuid);
     452    size_t const cbSuffix = strlen(pcszPlaceholder + cbPlaceholder);
     453    if (cbPrefix + cbUuid + cbSuffix < cbBuf)
     454    {
     455        /* Everything fits, no truncation. */
     456        memmove(pszBuf + cbPrefix + cbUuid, pcszPlaceholder + cbPlaceholder, cbSuffix + 1); \
     457        memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbUuid); \
     458    }
     459    else if (cbPrefix + cbUuid < cbBuf)
     460    {
     461        /* Prefix + DmiSystemUuid fits, truncate suffix. */
     462        memmove(pszBuf + cbPrefix + cbUuid, pcszPlaceholder + cbPlaceholder, cbBuf - cbPrefix - cbUuid - 1); \
     463        memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbUuid); \
     464        pszBuf[cbBuf] = '\0';
     465    }
     466    else
     467    {
     468        /* Prefix fits, truncate DmiSystemUuid. */
     469        memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbBuf - cbPrefix - 1); \
     470        pszBuf[cbBuf] = '\0';
     471    }
     472}
     473
     474/**
    437475 * Construct the DMI table.
    438476 *
     
    501539            if (!strcmp(szBuf, "<EMPTY>")) \
    502540                pszTmp = ""; \
     541            else if ((pszTmp = RTStrStr(szBuf, "<DmiSystemUuid>"))) \
     542            { \
     543                char *pszUuid = pszDmiSystemUuid; \
     544                if (!pszUuid) \
     545                { \
     546                    pszUuid = (char *)alloca(RTUUID_STR_LENGTH); \
     547                    RTUuidToStr(pUuid, pszUuid, RTUUID_STR_LENGTH); \
     548                } \
     549                fwUseDmiSystemUuidInString(szBuf, sizeof(szBuf), pszTmp, 15, pszUuid); \
     550                pszTmp = szBuf; \
     551            } \
    503552            else \
    504553                pszTmp = szBuf; \
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette