예제 #1
0
bool InsertUrl(char * def, char * pBuf, size_t & index,
                    size_t & filelength, size_t maxlength,
                    char * pUrl)
{
    // Search for first occurrence of def in the buffer, starting at index.
    if (!FindPlaceholder(def, pBuf, index, filelength))
    {
        // No more matches found.
        return false;
    }
    // Replace the $WCURL$ string with the actual URL
    char * pBuild = pBuf + index;
    ptrdiff_t Expansion = strlen(pUrl) - strlen(def);
    if (Expansion < 0)
    {
        memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
    }
    else if (Expansion > 0)
    {
        // Check for buffer overflow
        if (maxlength < Expansion + filelength) return false;
        memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
    }
    memmove(pBuild, pUrl, strlen(pUrl));
    filelength += Expansion;
    return true;
}
예제 #2
0
int InsertBoolean(char* def, char* pBuf, size_t& index, size_t& filelength, BOOL isTrue)
{
	// Search for first occurrence of def in the buffer, starting at index.
	if (!FindPlaceholder(def, pBuf, index, filelength))
	{
		// No more matches found.
		return false;
	}
	// Look for the terminating '$' character
	char* pBuild = pBuf + index;
	char* pEnd = pBuild + 1;
	while (*pEnd != '$')
	{
		++pEnd;
		if (pEnd - pBuf >= (__int64)filelength)
			return false; // No terminator - malformed so give up.
	}

	// Look for the ':' dividing TrueText from FalseText
	char *pSplit = pBuild + 1;
	// this loop is guaranteed to terminate due to test above.
	while (*pSplit != ':' && *pSplit != '$')
		pSplit++;

	if (*pSplit == '$')
		return false; // No split - malformed so give up.

	if (isTrue)
	{
		// Replace $WCxxx?TrueText:FalseText$ with TrueText
		// Remove :FalseText$
		memmove(pSplit, pEnd + 1, filelength - (pEnd + 1 - pBuf));
		filelength -= (pEnd + 1 - pSplit);
		// Remove $WCxxx?
		size_t deflen = strlen(def);
		memmove(pBuild, pBuild + deflen, filelength - (pBuild + deflen - pBuf));
		filelength -= deflen;
	}
	else
	{
		// Replace $WCxxx?TrueText:FalseText$ with FalseText
		// Remove terminating $
		memmove(pEnd, pEnd + 1, filelength - (pEnd + 1 - pBuf));
		filelength--;
		// Remove $WCxxx?TrueText:
		memmove(pBuild, pSplit + 1, filelength - (pSplit + 1 - pBuf));
		filelength -= (pSplit + 1 - pBuild);
	}
	return true;
}
예제 #3
0
bool InsertRevision(char* def, char* pBuf, size_t& index, size_t& filelength, size_t maxlength, GitWCRev_t* GitStat)
{
	// Search for first occurrence of def in the buffer, starting at index.
	if (!FindPlaceholder(def, pBuf, index, filelength))
	{
		// No more matches found.
		return false;
	}
	size_t hashlen = strlen(GitStat->HeadHashReadable);
	ptrdiff_t exp = 0;
	if ((strcmp(def, VERDEFSHORT) == 0))
	{
		char format[1024] = { 0 };
		char* pStart = pBuf + index + strlen(def);
		char* pEnd = pStart;

		while (*pEnd != '$')
		{
			++pEnd;
			if (pEnd - pBuf >= (__int64)filelength)
				return false; // No terminator - malformed so give up.
		}
		if ((pEnd - pStart) > 1024)
			return false; // value specifier too big
		exp = pEnd - pStart + 1;
		memcpy(format, pStart, pEnd - pStart);
		unsigned long number = strtoul(format, nullptr, 0);
		if (strcmp(def, VERDEFSHORT) == 0 && number < hashlen)
			hashlen = number;
	}
	// Replace the $WCxxx$ string with the actual revision number
	char* pBuild = pBuf + index;
	ptrdiff_t Expansion = hashlen - exp - strlen(def);
	if (Expansion < 0)
		memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
	else if (Expansion > 0)
	{
		// Check for buffer overflow
		if (maxlength < Expansion + filelength)
			return false;
		memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
	}
	memmove(pBuild, GitStat->HeadHashReadable, hashlen);
	filelength += Expansion;
	return true;
}
예제 #4
0
bool InsertText(char* def, char* pBuf, size_t& index, size_t& filelength, size_t maxlength, const std::string& Value)
{
	// Search for first occurrence of def in the buffer, starting at index.
	if (!FindPlaceholder(def, pBuf, index, filelength))
	{
		// No more matches found.
		return false;
	}
	// Replace the $WCxxx$ string with the actual value
	char* pBuild = pBuf + index;
	ptrdiff_t Expansion = Value.length() - strlen(def);
	if (Expansion < 0)
		memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
	else if (Expansion > 0)
	{
		// Check for buffer overflow
		if (maxlength < Expansion + filelength)
			return false;
		memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
	}
	memmove(pBuild, Value.c_str(), Value.length());
	filelength += Expansion;
	return true;
}
예제 #5
0
bool InsertDate(char* def, char* pBuf, size_t& index, size_t& filelength, size_t maxlength, __time64_t ttime)
{
	// Search for first occurrence of def in the buffer, starting at index.
	if (!FindPlaceholder(def, pBuf, index, filelength))
	{
		// No more matches found.
		return false;
	}
	// Format the text to insert at the placeholder
	if (ttime == USE_TIME_NOW)
		_time64(&ttime);

	struct tm newtime;
	if (strstr(def, "UTC"))
	{
		if (_gmtime64_s(&newtime, &ttime))
			return false;
	}
	else
	{
		if (_localtime64_s(&newtime, &ttime))
			return false;
	}
	char destbuf[1024] = { 0 };
	char* pBuild = pBuf + index;
	ptrdiff_t Expansion;
	if ((strcmp(def,DATEWFMTDEF) == 0) || (strcmp(def,NOWWFMTDEF) == 0) || (strcmp(def,DATEWFMTDEFUTC) == 0) || (strcmp(def,NOWWFMTDEFUTC) == 0))
	{
		// Format the date/time according to the supplied strftime format string
		char format[1024] = { 0 };
		char* pStart = pBuf + index + strlen(def);
		char* pEnd = pStart;

		while (*pEnd != '$')
		{
			++pEnd;
			if (pEnd - pBuf >= (__int64)filelength)
				return false; // No terminator - malformed so give up.
		}
		if ((pEnd - pStart) > 1024)
			return false; // Format specifier too big
		memcpy(format,pStart,pEnd - pStart);

		// to avoid wcsftime aborting if the user specified an invalid time format,
		// we set a custom invalid parameter handler that does nothing at all:
		// that makes wcsftime do nothing and set errno to EINVAL.
		// we restore the invalid parameter handler right after
		_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(_invalid_parameter_donothing);

		if (strftime(destbuf,1024,format,&newtime) == 0)
		{
			if (errno == EINVAL)
				strcpy_s(destbuf, "Invalid Time Format Specified");
		}
		_set_invalid_parameter_handler(oldHandler);
		Expansion = strlen(destbuf) - (strlen(def) + pEnd - pStart + 1);
	}
	else
	{
		// Format the date/time in international format as yyyy/mm/dd hh:mm:ss
		sprintf_s(destbuf, "%04d/%02d/%02d %02d:%02d:%02d", newtime.tm_year + 1900, newtime.tm_mon + 1, newtime.tm_mday, newtime.tm_hour, newtime.tm_min, newtime.tm_sec);
		Expansion = strlen(destbuf) - strlen(def);
	}
	// Replace the def string with the actual commit date
	if (Expansion < 0)
		memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
	else if (Expansion > 0)
	{
		// Check for buffer overflow
		if (maxlength < Expansion + filelength)
			return false;
		memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
	}
	memmove(pBuild, destbuf, strlen(destbuf));
	filelength += Expansion;
	return true;
}
예제 #6
0
bool InsertNumber(char* def, char* pBuf, size_t& index, size_t& filelength, size_t maxlength, size_t Value)
{
	// Search for first occurrence of def in the buffer, starting at index.
	if (!FindPlaceholder(def, pBuf, index, filelength))
	{
		// No more matches found.
		return false;
	}
	ptrdiff_t exp = 0;
	if ((strcmp(def, VALDEFAND) == 0) || (strcmp(def, VALDEFOFFSET1) == 0) || (strcmp(def, VALDEFOFFSET2) == 0))
	{
		char format[1024] = { 0 };
		char* pStart = pBuf + index + strlen(def);
		char* pEnd = pStart;

		while (*pEnd != '$')
		{
			++pEnd;
			if (pEnd - pBuf >= (__int64)filelength)
				return false; // No terminator - malformed so give up.
		}
		if ((pEnd - pStart) > 1024)
			return false; // value specifier too big

		exp = pEnd - pStart + 1;
		memcpy(format, pStart, pEnd - pStart);
		unsigned long number = strtoul(format, NULL, 0);
		if (strcmp(def, VALDEFAND) == 0)
		{
			if (Value != -1)
				Value &= number;
		}
		if (strcmp(def, VALDEFOFFSET1) == 0)
		{
			if (Value != -1)
				Value -= number;
		}
		if (strcmp(def, VALDEFOFFSET2) == 0)
		{
			if (Value != -1)
				Value += number;
		}
	}
	// Format the text to insert at the placeholder
	char destbuf[1024] = { 0 };
	sprintf_s(destbuf, "%lld", Value);

	// Replace the $WCxxx$ string with the actual revision number
	char* pBuild = pBuf + index;
	ptrdiff_t Expansion = strlen(destbuf) - exp - strlen(def);
	if (Expansion < 0)
		memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
	else if (Expansion > 0)
	{
		// Check for buffer overflow
		if (maxlength < Expansion + filelength)
			return false;
		memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
	}
	memmove(pBuild, destbuf, strlen(destbuf));
	filelength += Expansion;
	return true;
}
예제 #7
0
bool InsertRevision(char * def, char * pBuf, size_t & index,
                    size_t & filelength, size_t maxlength,
                    long MinRev, long MaxRev, SubWCRev_t * SubStat)
{
    // Search for first occurrence of def in the buffer, starting at index.
    if (!FindPlaceholder(def, pBuf, index, filelength))
    {
        // No more matches found.
        return false;
    }
    ptrdiff_t exp = 0;
    if ((strcmp(def,VERDEFAND) == 0) || (strcmp(def,VERDEFOFFSET1) == 0) || (strcmp(def,VERDEFOFFSET2) == 0))
    {
        char format[1024] = { 0 };
        char * pStart = pBuf + index + strlen(def);
        char * pEnd = pStart;

        while (*pEnd != '$')
        {
            pEnd++;
            if (pEnd - pBuf >= (__int64)filelength)
                return false;   // No terminator - malformed so give up.
        }
        if ((pEnd - pStart) > 1024)
        {
            return false; // value specifier too big
        }
        exp = pEnd - pStart + 1;
        SecureZeroMemory(format, sizeof(format));
        memcpy(format,pStart,pEnd - pStart);
        unsigned long number = strtoul(format, NULL, 0);
        if (strcmp(def,VERDEFAND) == 0)
        {
            if (MinRev != -1)
                MinRev &= number;
            MaxRev &= number;
        }
        if (strcmp(def,VERDEFOFFSET1) == 0)
        {
            if (MinRev != -1)
                MinRev -= number;
            MaxRev -= number;
        }
        if (strcmp(def,VERDEFOFFSET2) == 0)
        {
            if (MinRev != -1)
                MinRev += number;
            MaxRev += number;
        }
    }
    // Format the text to insert at the placeholder
    char destbuf[40] = { 0 };
    if (MinRev == -1 || MinRev == MaxRev)
    {
        if ((SubStat)&&(SubStat->bHexPlain))
            sprintf_s(destbuf, "%lX", MaxRev);
        else if ((SubStat)&&(SubStat->bHexX))
            sprintf_s(destbuf, "%#lX", MaxRev);
        else
            sprintf_s(destbuf, "%ld", MaxRev);
    }
    else
    {
        if ((SubStat)&&(SubStat->bHexPlain))
            sprintf_s(destbuf, "%lX:%lX", MinRev, MaxRev);
        else if ((SubStat)&&(SubStat->bHexX))
            sprintf_s(destbuf, "%#lX:%#lX", MinRev, MaxRev);
        else
            sprintf_s(destbuf, "%ld:%ld", MinRev, MaxRev);
    }
    // Replace the $WCxxx$ string with the actual revision number
    char * pBuild = pBuf + index;
    ptrdiff_t Expansion = strlen(destbuf) - exp - strlen(def);
    if (Expansion < 0)
    {
        memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
    }
    else if (Expansion > 0)
    {
        // Check for buffer overflow
        if (maxlength < Expansion + filelength) return false;
        memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf));
    }
    memmove(pBuild, destbuf, strlen(destbuf));
    filelength += Expansion;
    return true;
}