mirror of https://github.com/x64dbg/zydis
Minor refactorings and bugfixes
This commit is contained in:
parent
71b21c4301
commit
217d5cc9af
|
@ -108,8 +108,9 @@ target_sources("Zydis"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/String.h"
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/String.h"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Utils.h"
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Utils.h"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Zydis.h"
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Zydis.h"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/LibC.h"
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"src/LibC.h"
|
"src/InternalTypes.h"
|
||||||
"src/MetaInfo.c"
|
"src/MetaInfo.c"
|
||||||
"src/Mnemonic.c"
|
"src/Mnemonic.c"
|
||||||
"src/Register.c"
|
"src/Register.c"
|
||||||
|
@ -126,8 +127,8 @@ if (ZYDIS_FEATURE_DECODER)
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h"
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Formatter.h"
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Formatter.h"
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"src/DecoderData.h"
|
|
||||||
"src/Decoder.c"
|
"src/Decoder.c"
|
||||||
|
"src/DecoderData.h"
|
||||||
"src/DecoderData.c"
|
"src/DecoderData.c"
|
||||||
"src/Formatter.c")
|
"src/Formatter.c")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/***************************************************************************************************
|
||||||
|
|
||||||
|
Zyan Disassembler Library (Zydis)
|
||||||
|
|
||||||
|
Original Author : Florian Bernd
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
|
***************************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef ZYDIS_INTERNALTYPES_H
|
||||||
|
#define ZYDIS_INTERNALTYPES_H
|
||||||
|
|
||||||
|
#include <Zydis/CommonTypes.h>
|
||||||
|
#include <Zydis/Defines.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ============================================================================================== */
|
||||||
|
/* Generated Strings */
|
||||||
|
/* ============================================================================================== */
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
/* Enums and types */
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines the `ZydisGeneratedString` struct.
|
||||||
|
*/
|
||||||
|
typedef struct ZydisGeneratedString_
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Contains the actual string.
|
||||||
|
*/
|
||||||
|
char* buffer;
|
||||||
|
/**
|
||||||
|
* @brief The length of the string (without 0-termination).
|
||||||
|
*/
|
||||||
|
ZydisU8 length;
|
||||||
|
} ZydisGeneratedString;
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
/* Helper functions */
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes a `ZydisString` struct with the values from a `ZydisGeneratedString`.
|
||||||
|
*
|
||||||
|
* @param target A pointer to the target string.
|
||||||
|
* @param source A pointer to the source string.
|
||||||
|
*/
|
||||||
|
ZYDIS_NO_EXPORT ZYDIS_INLINE void ZydisStringInitWithGeneratedString(ZydisString* target,
|
||||||
|
const ZydisGeneratedString* source)
|
||||||
|
{
|
||||||
|
ZYDIS_ASSERT(target);
|
||||||
|
ZYDIS_ASSERT(source);
|
||||||
|
|
||||||
|
target->buffer = source->buffer;
|
||||||
|
target->length = source->length;
|
||||||
|
target->capacity = source->length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* ============================================================================================== */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZYDIS_INTERNALTYPES_H */
|
|
@ -25,39 +25,17 @@
|
||||||
***************************************************************************************************/
|
***************************************************************************************************/
|
||||||
|
|
||||||
#include <Zydis/Mnemonic.h>
|
#include <Zydis/Mnemonic.h>
|
||||||
|
#include <InternalTypes.h>
|
||||||
/* ============================================================================================== */
|
|
||||||
/* Mnemonic strings */
|
|
||||||
/* ============================================================================================== */
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Defines the `ZydisGeneratedString` struct.
|
|
||||||
*/
|
|
||||||
typedef struct ZydisGeneratedString_
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief Contains the actual string.
|
|
||||||
*/
|
|
||||||
char* buffer;
|
|
||||||
/**
|
|
||||||
* @brief The length of the string (without 0-termination).
|
|
||||||
*/
|
|
||||||
ZydisU8 length;
|
|
||||||
} ZydisGeneratedString;
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
#include <Generated/EnumMnemonic.inc>
|
#include <Generated/EnumMnemonic.inc>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Contains all strings that were accessed by `ZydisMnemonicGetStringEx`.
|
* @brief Caches all strings that were accessed by `ZydisMnemonicGetStringEx`.
|
||||||
*
|
*
|
||||||
* We could store `ZydisString` structs instead of `ZydisInternalString` ones in the
|
* We could store `ZydisString` structs instead of `ZydisGeneratedString` ones in the
|
||||||
* `zydisMnemonicStrings` array, but this would significantly increase the table-size.
|
* `zydisMnemonicStrings` array, but this would significantly increase the table-size.
|
||||||
*/
|
*/
|
||||||
static ZydisString stringTable[ZYDIS_MNEMONIC_MAX_VALUE + 1];
|
static ZydisString zydisMnemonicStringCache[ZYDIS_MNEMONIC_MAX_VALUE + 1];
|
||||||
|
|
||||||
/* ============================================================================================== */
|
/* ============================================================================================== */
|
||||||
/* Exported functions */
|
/* Exported functions */
|
||||||
|
@ -78,13 +56,12 @@ const ZydisString* ZydisMnemonicGetStringEx(ZydisMnemonic mnemonic)
|
||||||
{
|
{
|
||||||
return ZYDIS_NULL;
|
return ZYDIS_NULL;
|
||||||
}
|
}
|
||||||
if (!stringTable[mnemonic].buffer)
|
if (!zydisMnemonicStringCache[mnemonic].buffer)
|
||||||
{
|
{
|
||||||
stringTable[mnemonic].buffer = zydisMnemonicStrings[mnemonic].buffer;
|
ZydisStringInitWithGeneratedString(&zydisMnemonicStringCache[mnemonic],
|
||||||
stringTable[mnemonic].length = zydisMnemonicStrings[mnemonic].length;
|
&zydisMnemonicStrings[mnemonic]);
|
||||||
stringTable[mnemonic].capacity = zydisMnemonicStrings[mnemonic].length;
|
|
||||||
}
|
}
|
||||||
return &stringTable[mnemonic];
|
return &zydisMnemonicStringCache[mnemonic];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============================================================================================== */
|
/* ============================================================================================== */
|
||||||
|
|
Loading…
Reference in New Issue