Minor refactorings

This commit is contained in:
flobernd 2017-10-14 18:10:53 +02:00
parent e4cc39d195
commit ea3e9b648a
2 changed files with 39 additions and 38 deletions

View File

@ -67,6 +67,38 @@ static const char* decimalLookup =
/* Internal Functions */
/* ---------------------------------------------------------------------------------------------- */
void ZydisToLowerCase(char* buffer, size_t bufferLen)
{
ZYDIS_ASSERT(buffer);
ZYDIS_ASSERT(bufferLen);
const signed char rebase = 'a' - 'A';
for (size_t i = 0; i < bufferLen; ++i)
{
char* c = buffer + i;
if ((*c >= 'A') && (*c <= 'Z'))
{
*c += rebase;
}
}
}
void ZydisToUpperCase(char* buffer, size_t bufferLen)
{
ZYDIS_ASSERT(buffer);
ZYDIS_ASSERT(bufferLen);
const signed char rebase = 'A' - 'a';
for (size_t i = 0; i < bufferLen; ++i)
{
char* c = buffer + i;
if ((*c >= 'a') && (*c <= 'z'))
{
*c += rebase;
}
}
}
#ifdef ZYDIS_X86
ZydisStatus ZydisPrintDecU32(char** buffer, size_t bufferLen, uint32_t value, uint8_t paddingLength)
{
@ -294,41 +326,19 @@ ZydisStatus ZydisPrintStr(char** buffer, size_t bufferLen, const char* text,
}
memcpy(*buffer, text, strLen + 1);
ZydisChangeCase(*buffer, strLen, letterCase);
*buffer += strLen;
return ZYDIS_STATUS_SUCCESS;
}
void ZydisChangeCase(char* buffer, size_t bufferLen, ZydisLetterCase letterCase)
{
char rewriteRangeStart;
char rewriteRangeEnd;
signed char rebase;
switch (letterCase)
{
case ZYDIS_LETTER_CASE_DEFAULT:
break;
case ZYDIS_LETTER_CASE_LOWER:
rewriteRangeStart = 'A';
rewriteRangeEnd = 'Z';
rebase = 'a' - 'A';
break;
ZydisToLowerCase(*buffer, strLen);
case ZYDIS_LETTER_CASE_UPPER:
rewriteRangeStart = 'a';
rewriteRangeEnd = 'z';
rebase = 'A' - 'a';
break;
ZydisToUpperCase(*buffer, strLen);
default:
return;
}
for (size_t i = 0; i < bufferLen; ++i)
{
char* c = buffer + i;
if (*c >= rewriteRangeStart && *c <= rewriteRangeEnd)
{
*c += rebase;
}
ZYDIS_UNREACHABLE;
}
*buffer += strLen;
return ZYDIS_STATUS_SUCCESS;
}
ZydisStatus ZydisPrintDecU(char** buffer, size_t bufferLen, uint64_t value, uint8_t paddingLength)

View File

@ -94,15 +94,6 @@ enum ZydisLetterCases
ZYDIS_NO_EXPORT ZydisStatus ZydisPrintStr(char** buffer, size_t bufferLen, const char* text,
ZydisLetterCase letterCase);
/**
* @brief Rewrites the letter case of a given string.
*
* @param buffer The string to rewrite.
* @param bufferLen The number of bytes in the buffer to case-rewrite.
* @param letterCase The desired letter case.
*/
ZYDIS_NO_EXPORT void ZydisChangeCase(char* buffer, size_t bufferLen, ZydisLetterCase letterCase);
/* ---------------------------------------------------------------------------------------------- */
/* Decimal values */
/* ---------------------------------------------------------------------------------------------- */