Replace `to{lower,upper}` with custom func

This commit is contained in:
Joel Höner 2017-09-30 01:04:52 +02:00
parent ded9d0e513
commit 90e4626d11
2 changed files with 38 additions and 13 deletions

View File

@ -2,7 +2,7 @@
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
Original Author : Florian Bernd, Joel Höner
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -292,27 +292,43 @@ ZydisStatus ZydisPrintStr(char** buffer, size_t bufferLen, const char* text,
{
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
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_LOWER:
for (size_t i = 0; i < strLen; ++i)
{
(*buffer)[i] = (char)tolower((*buffer)[i]);
}
rewriteRangeStart = 'A';
rewriteRangeEnd = 'Z';
rebase = 'a' - 'A';
break;
case ZYDIS_LETTER_CASE_UPPER:
for (size_t i = 0; i < strLen; ++i)
{
(*buffer)[i] = (char)toupper((*buffer)[i]);
}
rewriteRangeStart = 'a';
rewriteRangeEnd = 'z';
rebase = 'A' - 'a';
break;
default:
break;
return;
}
*buffer += strLen;
return ZYDIS_STATUS_SUCCESS;
for (size_t i; i < bufferLen; ++i)
{
char* c = buffer + i;
if (*c >= rewriteRangeStart && *c <= rewriteRangeEnd)
{
*c += rebase;
}
}
}
ZydisStatus ZydisPrintDecU(char** buffer, size_t bufferLen, uint64_t value, uint8_t paddingLength)

View File

@ -2,7 +2,7 @@
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
Original Author : Florian Bernd, Joel Höner
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -94,6 +94,15 @@ 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 */
/* ---------------------------------------------------------------------------------------------- */