mirror of https://github.com/x64dbg/zydis
Minor refactorings
This commit is contained in:
parent
e4cc39d195
commit
ea3e9b648a
|
@ -67,6 +67,38 @@ static const char* decimalLookup =
|
||||||
/* Internal Functions */
|
/* 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
|
#ifdef ZYDIS_X86
|
||||||
ZydisStatus ZydisPrintDecU32(char** buffer, size_t bufferLen, uint32_t value, uint8_t paddingLength)
|
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);
|
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)
|
switch (letterCase)
|
||||||
{
|
{
|
||||||
|
case ZYDIS_LETTER_CASE_DEFAULT:
|
||||||
|
break;
|
||||||
case ZYDIS_LETTER_CASE_LOWER:
|
case ZYDIS_LETTER_CASE_LOWER:
|
||||||
rewriteRangeStart = 'A';
|
ZydisToLowerCase(*buffer, strLen);
|
||||||
rewriteRangeEnd = 'Z';
|
|
||||||
rebase = 'a' - 'A';
|
|
||||||
break;
|
|
||||||
case ZYDIS_LETTER_CASE_UPPER:
|
case ZYDIS_LETTER_CASE_UPPER:
|
||||||
rewriteRangeStart = 'a';
|
ZydisToUpperCase(*buffer, strLen);
|
||||||
rewriteRangeEnd = 'z';
|
|
||||||
rebase = 'A' - 'a';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return;
|
ZYDIS_UNREACHABLE;
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bufferLen; ++i)
|
|
||||||
{
|
|
||||||
char* c = buffer + i;
|
|
||||||
if (*c >= rewriteRangeStart && *c <= rewriteRangeEnd)
|
|
||||||
{
|
|
||||||
*c += rebase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*buffer += strLen;
|
||||||
|
return ZYDIS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZydisStatus ZydisPrintDecU(char** buffer, size_t bufferLen, uint64_t value, uint8_t paddingLength)
|
ZydisStatus ZydisPrintDecU(char** buffer, size_t bufferLen, uint64_t value, uint8_t paddingLength)
|
||||||
|
|
|
@ -94,15 +94,6 @@ enum ZydisLetterCases
|
||||||
ZYDIS_NO_EXPORT ZydisStatus ZydisPrintStr(char** buffer, size_t bufferLen, const char* text,
|
ZYDIS_NO_EXPORT ZydisStatus ZydisPrintStr(char** buffer, size_t bufferLen, const char* text,
|
||||||
ZydisLetterCase letterCase);
|
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 */
|
/* Decimal values */
|
||||||
/* ---------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
Loading…
Reference in New Issue