2017-09-14 06:59:23 +08:00
|
|
|
/***************************************************************************************************
|
|
|
|
|
|
|
|
Zyan Disassembler Library (Zydis)
|
|
|
|
|
2017-09-30 07:04:52 +08:00
|
|
|
Original Author : Florian Bernd, Joel Höner
|
2017-09-14 06:59:23 +08:00
|
|
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
|
|
|
|
***************************************************************************************************/
|
|
|
|
|
|
|
|
#include <FormatHelper.h>
|
2017-11-25 02:25:48 +08:00
|
|
|
#include <LibC.h>
|
2017-09-14 06:59:23 +08:00
|
|
|
|
|
|
|
/* ============================================================================================== */
|
|
|
|
/* Constants */
|
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Defines */
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define ZYDIS_MAXCHARS_DEC_32 10
|
|
|
|
#define ZYDIS_MAXCHARS_DEC_64 20
|
|
|
|
#define ZYDIS_MAXCHARS_HEX_32 8
|
|
|
|
#define ZYDIS_MAXCHARS_HEX_64 16
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Lookup Tables */
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2017-09-14 08:59:20 +08:00
|
|
|
static const char* decimalLookup =
|
|
|
|
"00010203040506070809"
|
|
|
|
"10111213141516171819"
|
|
|
|
"20212223242526272829"
|
|
|
|
"30313233343536373839"
|
|
|
|
"40414243444546474849"
|
|
|
|
"50515253545556575859"
|
|
|
|
"60616263646566676869"
|
|
|
|
"70717273747576777879"
|
|
|
|
"80818283848586878889"
|
|
|
|
"90919293949596979899";
|
2017-09-14 06:59:23 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* ============================================================================================== */
|
|
|
|
/* Functions */
|
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2017-09-14 08:59:20 +08:00
|
|
|
/* Internal Functions */
|
2017-09-14 06:59:23 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
void ZydisToLowerCase(char* buffer, ZydisUSize bufferLen)
|
2017-10-15 00:10:53 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen);
|
|
|
|
|
|
|
|
const signed char rebase = 'a' - 'A';
|
2017-11-25 08:35:22 +08:00
|
|
|
for (ZydisUSize i = 0; i < bufferLen; ++i)
|
2017-10-15 00:10:53 +08:00
|
|
|
{
|
|
|
|
char* c = buffer + i;
|
|
|
|
if ((*c >= 'A') && (*c <= 'Z'))
|
|
|
|
{
|
|
|
|
*c += rebase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
void ZydisToUpperCase(char* buffer, ZydisUSize bufferLen)
|
2017-10-15 00:10:53 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen);
|
|
|
|
|
|
|
|
const signed char rebase = 'A' - 'a';
|
2017-11-25 08:35:22 +08:00
|
|
|
for (ZydisUSize i = 0; i < bufferLen; ++i)
|
2017-10-15 00:10:53 +08:00
|
|
|
{
|
|
|
|
char* c = buffer + i;
|
|
|
|
if ((*c >= 'a') && (*c <= 'z'))
|
|
|
|
{
|
|
|
|
*c += rebase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-14 08:59:20 +08:00
|
|
|
#ifdef ZYDIS_X86
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintDecU32(char** buffer, ZydisUSize bufferLen, ZydisU32 value, ZydisU8 paddingLength)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen > 0);
|
|
|
|
|
|
|
|
char temp[ZYDIS_MAXCHARS_DEC_32 + 1];
|
|
|
|
char *p = &temp[ZYDIS_MAXCHARS_DEC_32];
|
|
|
|
*p = '\0';
|
2017-09-20 21:46:51 +08:00
|
|
|
while (value >= 100)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisU32 const old = value;
|
2017-09-14 06:59:23 +08:00
|
|
|
p -= 2;
|
|
|
|
value /= 100;
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisMemoryCopy(p, &decimalLookup[(old - (value * 100)) * 2], sizeof(ZydisU16));
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
p -= 2;
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisMemoryCopy(p, &decimalLookup[value * 2], sizeof(ZydisU16));
|
2017-09-14 06:59:23 +08:00
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisUSize n = &temp[ZYDIS_MAXCHARS_DEC_32] - p;
|
|
|
|
if ((bufferLen < (ZydisUSize)(n + 1)) || (bufferLen < (ZydisUSize)(paddingLength + 1)))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisUSize offset = 0;
|
2017-09-14 06:59:23 +08:00
|
|
|
if (n <= paddingLength)
|
|
|
|
{
|
|
|
|
offset = paddingLength - n + 1;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', offset);
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemoryCopy(&(*buffer)[offset], &p[value < 10], n + 1);
|
2017-11-25 08:35:22 +08:00
|
|
|
*buffer += n + offset - (ZydisU8)(value < 10);
|
2017-09-14 06:59:23 +08:00
|
|
|
|
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintHexU32(char** buffer, ZydisUSize bufferLen, ZydisU32 value, ZydisU8 paddingLength,
|
2017-11-13 20:52:02 +08:00
|
|
|
ZydisBool uppercase, const char* prefix, const char* suffix)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen);
|
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
2017-11-13 20:52:02 +08:00
|
|
|
const char* bufEnd = *buffer + bufferLen;
|
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, prefix, ZYDIS_LETTER_CASE_DEFAULT));
|
|
|
|
bufferLen = bufEnd - *buffer;
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen < (ZydisUSize)(paddingLength + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisU8 n = (paddingLength ? paddingLength : 1);
|
2017-09-14 06:59:23 +08:00
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen < (ZydisUSize)(n + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', n);
|
2017-09-14 06:59:23 +08:00
|
|
|
(*buffer)[n] = '\0';
|
|
|
|
*buffer += n;
|
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisU8 n = 0;
|
|
|
|
for (ZydisI8 i = ZYDIS_MAXCHARS_HEX_32 - 1; i >= 0; --i)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisU8 v = (value >> i * 4) & 0x0F;
|
2017-09-14 06:59:23 +08:00
|
|
|
if (!n)
|
|
|
|
{
|
|
|
|
if (!v)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen <= (ZydisU8)(i + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
2017-09-16 23:37:14 +08:00
|
|
|
}
|
|
|
|
if (paddingLength > i)
|
|
|
|
{
|
|
|
|
n = paddingLength - i - 1;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', n);
|
2017-09-16 23:37:14 +08:00
|
|
|
}
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
if (uppercase)
|
|
|
|
{
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n++] = "0123456789ABCDEF"[v];
|
2017-09-14 06:59:23 +08:00
|
|
|
} else
|
|
|
|
{
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n++] = "0123456789abcdef"[v];
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n] = '\0';
|
|
|
|
*buffer += n;
|
2017-09-14 06:59:23 +08:00
|
|
|
|
2017-11-13 20:52:02 +08:00
|
|
|
if (suffix)
|
|
|
|
{
|
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen - n, suffix, ZYDIS_LETTER_CASE_DEFAULT));
|
|
|
|
}
|
|
|
|
|
2017-09-14 06:59:23 +08:00
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
2017-09-14 08:59:20 +08:00
|
|
|
}
|
2017-09-14 06:59:23 +08:00
|
|
|
#endif
|
2017-09-14 08:59:20 +08:00
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintDecU64(char** buffer, ZydisUSize bufferLen, ZydisU64 value, ZydisU8 paddingLength)
|
2017-09-14 08:59:20 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen > 0);
|
|
|
|
|
|
|
|
char temp[ZYDIS_MAXCHARS_DEC_64 + 1];
|
|
|
|
char *p = &temp[ZYDIS_MAXCHARS_DEC_64];
|
|
|
|
*p = '\0';
|
2017-09-20 21:46:51 +08:00
|
|
|
while (value >= 100)
|
2017-09-14 08:59:20 +08:00
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisU64 const old = value;
|
2017-09-14 08:59:20 +08:00
|
|
|
p -= 2;
|
|
|
|
value /= 100;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemoryCopy(p, &decimalLookup[(old - (value * 100)) * 2], 2);
|
2017-09-14 08:59:20 +08:00
|
|
|
}
|
|
|
|
p -= 2;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemoryCopy(p, &decimalLookup[value * 2], 2);
|
2017-09-14 08:59:20 +08:00
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisUSize n = &temp[ZYDIS_MAXCHARS_DEC_64] - p;
|
|
|
|
if ((bufferLen < (ZydisUSize)(n + 1)) || (bufferLen < (ZydisUSize)(paddingLength + 1)))
|
2017-09-14 08:59:20 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisUSize offset = 0;
|
2017-09-14 08:59:20 +08:00
|
|
|
if (n <= paddingLength)
|
|
|
|
{
|
|
|
|
offset = paddingLength - n + 1;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', offset);
|
2017-09-14 08:59:20 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemoryCopy(&(*buffer)[offset], &p[value < 10], n + 1);
|
2017-11-25 08:35:22 +08:00
|
|
|
*buffer += n + offset - (ZydisU8)(value < 10);
|
2017-09-14 08:59:20 +08:00
|
|
|
|
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintHexU64(char** buffer, ZydisUSize bufferLen, ZydisU64 value, ZydisU8 paddingLength,
|
2017-11-13 20:52:02 +08:00
|
|
|
ZydisBool uppercase, const char* prefix, const char* suffix)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen);
|
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
2017-11-13 20:52:02 +08:00
|
|
|
const char* bufEnd = *buffer + bufferLen;
|
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, prefix, ZYDIS_LETTER_CASE_DEFAULT));
|
|
|
|
bufferLen = bufEnd - *buffer;
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen < (ZydisUSize)(paddingLength + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisU8 n = (paddingLength ? paddingLength : 1);
|
2017-09-14 06:59:23 +08:00
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen < (ZydisUSize)(n + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', n);
|
2017-09-14 06:59:23 +08:00
|
|
|
(*buffer)[n] = '\0';
|
|
|
|
*buffer += n;
|
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisU8 n = 0;
|
|
|
|
const ZydisU8 c = ((value & 0xFFFFFFFF00000000) ? ZYDIS_MAXCHARS_HEX_64 : ZYDIS_MAXCHARS_HEX_32);
|
|
|
|
for (ZydisI8 i = c - 1; i >= 0; --i)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisU8 v = (value >> i * 4) & 0x0F;
|
2017-09-14 06:59:23 +08:00
|
|
|
if (!n)
|
|
|
|
{
|
|
|
|
if (!v)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-25 08:35:22 +08:00
|
|
|
if (bufferLen <= (ZydisU8)(i + 1))
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
2017-09-16 23:37:14 +08:00
|
|
|
}
|
|
|
|
if (paddingLength > i)
|
|
|
|
{
|
|
|
|
n = paddingLength - i - 1;
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemorySet(*buffer, '0', n);
|
2017-09-16 23:37:14 +08:00
|
|
|
}
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
if (uppercase)
|
|
|
|
{
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n++] = "0123456789ABCDEF"[v];
|
2017-09-14 06:59:23 +08:00
|
|
|
} else
|
|
|
|
{
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n++] = "0123456789abcdef"[v];
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-16 23:37:14 +08:00
|
|
|
(*buffer)[n] = '\0';
|
|
|
|
*buffer += n;
|
2017-09-14 06:59:23 +08:00
|
|
|
|
2017-11-13 20:52:02 +08:00
|
|
|
if (suffix)
|
|
|
|
{
|
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen - n, suffix, ZYDIS_LETTER_CASE_DEFAULT));
|
|
|
|
}
|
|
|
|
|
2017-09-14 06:59:23 +08:00
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-09-14 08:59:20 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Public Functions */
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintStr(char** buffer, ZydisUSize bufferLen, const char* text,
|
2017-09-14 08:59:20 +08:00
|
|
|
ZydisLetterCase letterCase)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-09-14 08:59:20 +08:00
|
|
|
ZYDIS_ASSERT(buffer);
|
|
|
|
ZYDIS_ASSERT(bufferLen > 0);
|
|
|
|
ZYDIS_ASSERT(text);
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisUSize strLen = ZydisStrLen(text);
|
2017-09-14 08:59:20 +08:00
|
|
|
if (strLen >= bufferLen)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-09-14 08:59:20 +08:00
|
|
|
return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE;
|
|
|
|
}
|
2017-09-30 07:04:52 +08:00
|
|
|
|
2017-11-25 02:25:48 +08:00
|
|
|
ZydisMemoryCopy(*buffer, text, strLen + 1);
|
2017-09-14 08:59:20 +08:00
|
|
|
switch (letterCase)
|
|
|
|
{
|
2017-10-15 00:10:53 +08:00
|
|
|
case ZYDIS_LETTER_CASE_DEFAULT:
|
2017-09-14 08:59:20 +08:00
|
|
|
break;
|
2017-10-15 00:10:53 +08:00
|
|
|
case ZYDIS_LETTER_CASE_LOWER:
|
|
|
|
ZydisToLowerCase(*buffer, strLen);
|
2017-10-17 23:44:19 +08:00
|
|
|
break;
|
2017-09-14 08:59:20 +08:00
|
|
|
case ZYDIS_LETTER_CASE_UPPER:
|
2017-10-15 00:10:53 +08:00
|
|
|
ZydisToUpperCase(*buffer, strLen);
|
2017-10-17 23:44:19 +08:00
|
|
|
break;
|
2017-09-14 08:59:20 +08:00
|
|
|
default:
|
2017-10-15 00:10:53 +08:00
|
|
|
ZYDIS_UNREACHABLE;
|
2017-09-30 07:04:52 +08:00
|
|
|
}
|
2017-10-15 00:10:53 +08:00
|
|
|
*buffer += strLen;
|
|
|
|
return ZYDIS_STATUS_SUCCESS;
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintDecU(char** buffer, ZydisUSize bufferLen, ZydisU64 value, ZydisU8 paddingLength)
|
2017-09-14 08:59:20 +08:00
|
|
|
{
|
|
|
|
#ifdef ZYDIS_X64
|
|
|
|
return ZydisPrintDecU64(buffer, bufferLen, value, paddingLength);
|
|
|
|
#else
|
|
|
|
if (value & 0xFFFFFFFF00000000)
|
|
|
|
{
|
|
|
|
return ZydisPrintDecU64(buffer, bufferLen, value, paddingLength);
|
|
|
|
} else
|
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
return ZydisPrintDecU32(buffer, bufferLen, (ZydisU32)value, paddingLength);
|
2017-09-14 08:59:20 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintDecS(char** buffer, ZydisUSize bufferLen, ZydisI64 value, ZydisU8 paddingLength)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
if (value < 0)
|
|
|
|
{
|
2017-09-14 08:59:20 +08:00
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, "-", ZYDIS_LETTER_CASE_DEFAULT));
|
|
|
|
return ZydisPrintDecU(buffer, bufferLen - 1, -value, paddingLength);
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
2017-09-14 08:59:20 +08:00
|
|
|
return ZydisPrintDecU(buffer, bufferLen, value, paddingLength);
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintHexU(char** buffer, ZydisUSize bufferLen, ZydisU64 value, ZydisU8 paddingLength,
|
2017-11-13 20:52:02 +08:00
|
|
|
ZydisBool uppercase, const char* prefix, const char* suffix)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
2017-09-14 08:59:20 +08:00
|
|
|
#ifdef ZYDIS_X64
|
2017-11-13 20:52:02 +08:00
|
|
|
return ZydisPrintHexU64(buffer, bufferLen, value, paddingLength, uppercase, prefix, suffix);
|
2017-09-14 08:59:20 +08:00
|
|
|
#else
|
|
|
|
if (value & 0xFFFFFFFF00000000)
|
|
|
|
{
|
2017-11-13 20:52:02 +08:00
|
|
|
return ZydisPrintHexU64(buffer, bufferLen, value, paddingLength, uppercase, prefix, suffix);
|
2017-09-14 08:59:20 +08:00
|
|
|
} else
|
|
|
|
{
|
2017-11-25 08:35:22 +08:00
|
|
|
return ZydisPrintHexU32(buffer, bufferLen, (ZydisU32)value, paddingLength, uppercase,
|
2017-11-13 20:52:02 +08:00
|
|
|
prefix, suffix);
|
2017-09-14 08:59:20 +08:00
|
|
|
}
|
|
|
|
#endif
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisStatus ZydisPrintHexS(char** buffer, ZydisUSize bufferLen, ZydisI64 value, ZydisU8 paddingLength,
|
2017-11-13 20:52:02 +08:00
|
|
|
ZydisBool uppercase, const char* prefix, const char* suffix)
|
2017-09-14 06:59:23 +08:00
|
|
|
{
|
|
|
|
if (value < 0)
|
|
|
|
{
|
2017-11-13 20:52:02 +08:00
|
|
|
const char* bufEnd = *buffer + bufferLen;
|
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, "-", ZYDIS_LETTER_CASE_DEFAULT));
|
2017-09-14 06:59:23 +08:00
|
|
|
if (prefix)
|
|
|
|
{
|
2017-11-13 20:52:02 +08:00
|
|
|
ZYDIS_CHECK(ZydisPrintStr(buffer, bufEnd - *buffer, prefix, ZYDIS_LETTER_CASE_DEFAULT));
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
2017-11-13 20:52:02 +08:00
|
|
|
return ZydisPrintHexU(buffer, bufEnd - *buffer, -value, paddingLength, uppercase,
|
2017-11-25 10:18:08 +08:00
|
|
|
ZYDIS_NULL, suffix);
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
2017-11-13 20:52:02 +08:00
|
|
|
return ZydisPrintHexU(buffer, bufferLen, value, paddingLength, uppercase, prefix, suffix);
|
2017-09-14 06:59:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* ============================================================================================== */
|