2014-10-25 05:11:16 +08:00
|
|
|
/**************************************************************************************************
|
|
|
|
|
|
|
|
Verteron Disassembler Engine
|
|
|
|
Version 1.0
|
|
|
|
|
|
|
|
Remarks : Freeware, Copyright must be included
|
|
|
|
|
|
|
|
Original Author : Florian Bernd
|
2015-03-16 23:37:15 +08:00
|
|
|
Modifications : athre0z
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
Last change : 14. March 2015
|
2014-10-25 05:11:16 +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.
|
|
|
|
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
#ifndef _VDE_ZyDisINSTRUCTIONFORMATTERC_H_
|
|
|
|
#define _VDE_ZyDisINSTRUCTIONFORMATTERC_H_
|
2015-03-16 23:37:15 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
#include "ZyDisDisassemblerTypes.h"
|
|
|
|
#include "ZyDisDisassemblerUtils.h"
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
2014-10-25 05:11:16 +08:00
|
|
|
{
|
2015-03-16 23:37:15 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
/* ZyDisBaseSymbolResolver ======================================================================== */
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
typedef struct _ZyDisBaseSymbolResolverContext
|
2015-03-16 23:37:15 +08:00
|
|
|
{
|
2015-05-12 09:42:25 +08:00
|
|
|
ZyDisContextDescriptor d;
|
|
|
|
} ZyDisBaseSymbolResolverContext;
|
2014-11-03 22:15:48 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-16 23:37:15 +08:00
|
|
|
* @brief Releases a symbol resolver.
|
|
|
|
* @param ctx The context of the symbol resolver to free.
|
|
|
|
* The context may no longer used after it was released.
|
2014-11-03 22:15:48 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT void ZyDisBaseSymbolResolver_Release(
|
|
|
|
ZyDisBaseSymbolResolverContext *ctx);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-16 23:37:15 +08:00
|
|
|
* @brief Resolves a symbol.
|
|
|
|
* @param ctx The symbol resolver context.
|
|
|
|
* @param info The instruction info.
|
|
|
|
* @param address The address.
|
|
|
|
* @param offset Pointer to an unsigned 64 bit integer that receives an offset relative to
|
|
|
|
* the base address of the symbol.
|
|
|
|
* @return The name of the symbol if the symbol was found, else @c NULL.
|
2014-10-25 05:11:16 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT const char* ZyDisBaseSymbolResolver_ResolveSymbol(
|
|
|
|
ZyDisBaseSymbolResolverContext *ctx,
|
|
|
|
const ZyDisInstructionInfo *info,
|
2015-03-16 23:37:15 +08:00
|
|
|
uint64_t address,
|
|
|
|
uint64_t *offset);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
/* ZyDisCustomSymbolResolver ====================================================================== */
|
2014-10-30 23:36:25 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
typedef const char* (*ZyDisCustomSymbolResolver_ResolveSymbolCallback)(
|
|
|
|
const ZyDisInstructionInfo *info,
|
2015-03-16 23:37:15 +08:00
|
|
|
uint64_t address,
|
|
|
|
uint64_t *offset,
|
|
|
|
void *userData);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
/**
|
|
|
|
* @brief Creates a custom symbol resolver.
|
|
|
|
* @param resolverCb The resolver callback consulted when symbols need to be resolved.
|
|
|
|
* @param userData A pointer to arbitrary data passed to the resolver callback.
|
|
|
|
* May also be @c NULL.
|
|
|
|
* @return @c NULL if it fails, else a symbol resolver context.
|
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT ZyDisBaseSymbolResolverContext* ZyDisCustomSymbolResolver_Create(
|
|
|
|
ZyDisCustomSymbolResolver_ResolveSymbolCallback resolverCb,
|
2015-03-16 23:37:15 +08:00
|
|
|
void *userData);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
/* ZyDisBaseInstructionFormatter ================================================================== */
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
typedef struct _ZyDisBaseInstructionFormatterContext
|
2014-10-25 05:11:16 +08:00
|
|
|
{
|
2015-05-12 09:42:25 +08:00
|
|
|
ZyDisContextDescriptor d;
|
|
|
|
} ZyDisBaseInstructionFormatterContext;
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
typedef void(*ZyDisBaseInstructionFormatter_InternalFormatInstructionCallback)(
|
|
|
|
ZyDisBaseInstructionFormatterContext *ctx, const ZyDisInstructionInfo *info);
|
2015-03-20 04:05:14 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats a decoded instruction.
|
|
|
|
* @param ctx The instruction formatter context.
|
|
|
|
* @param info The instruction info.
|
|
|
|
* @return Pointer to the formatted instruction string. This pointer remains valid until
|
|
|
|
* this function is called again or the context is released.
|
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT const char* ZyDisBaseInstructionFormatter_FormatInstruction(
|
|
|
|
ZyDisBaseInstructionFormatterContext *ctx,
|
|
|
|
const ZyDisInstructionInfo *info);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-16 23:37:15 +08:00
|
|
|
* @brief Returns a pointer to the current symbol resolver.
|
|
|
|
* @param ctx The instruction formatter context.
|
|
|
|
* @return Pointer to the current symbol resolver or @c NULL if no symbol resolver is used.
|
2014-10-25 05:11:16 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT ZyDisBaseSymbolResolverContext* ZyDisBaseInstructionFormatter_GetSymbolResolver(
|
|
|
|
const ZyDisBaseInstructionFormatterContext *ctx);
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
/**
|
|
|
|
* @brief Sets a new symbol resolver.
|
|
|
|
* @param ctx The instruction formatter context.
|
|
|
|
* @param symbolResolver Pointer to a symbol resolver instance or @c NULL, if no smybol
|
|
|
|
* resolver should be used.
|
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT void ZyDisBaseInstructionFormatter_SetSymbolResolver(
|
|
|
|
ZyDisBaseInstructionFormatterContext *ctx,
|
|
|
|
ZyDisBaseSymbolResolverContext *resolver);
|
2014-11-03 22:15:48 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-16 23:37:15 +08:00
|
|
|
* @brief Releases an instruction formatter.
|
|
|
|
* @param ctx The context of the instruction formatter to release.
|
|
|
|
* The context may no longer used after it has been released.
|
2014-11-03 22:15:48 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT void ZyDisBaseInstructionFormatter_Release(
|
|
|
|
ZyDisBaseInstructionFormatterContext *ctx);
|
2014-11-03 22:15:48 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
/* ZyDisIntelInstructionFormatter ================================================================= */
|
2014-10-25 05:11:16 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
/**
|
|
|
|
* @brief Creates an Intel-syntax instruction formatter.
|
|
|
|
* @return @c NULL if it fails, else an Intel instruction formatter context.
|
2015-05-12 09:42:25 +08:00
|
|
|
* @see ZyDisBaseInstructionFormatter_Release
|
2015-03-16 23:37:15 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT ZyDisBaseInstructionFormatterContext* ZyDisIntelInstructionFormatter_Create(void);
|
2015-03-16 23:37:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creates an Intel-syntax instruction formatter.
|
|
|
|
* @param resolver The symbol resolver consulted to resolve symbols on formatting.
|
|
|
|
* @return @c NULL if it fails, else an Intel instruction formatter context.
|
2015-05-12 09:42:25 +08:00
|
|
|
* @see ZyDisBaseInstructionFormatter_Release
|
2015-03-16 23:37:15 +08:00
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT ZyDisBaseInstructionFormatterContext* ZyDisIntelInstructionFormatter_CreateEx(
|
|
|
|
ZyDisBaseSymbolResolverContext *resolver);
|
2015-03-16 23:37:15 +08:00
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
/* ZyDisCustomInstructionFormatter ================================================================ */
|
2015-03-20 04:05:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creats a custom instruction formatter.
|
|
|
|
* @param formatInsnCb The callback formatting the instruction.
|
|
|
|
* @return @c NULL if it fails, else a custom instruction formatter context.
|
|
|
|
*/
|
2015-05-12 09:42:25 +08:00
|
|
|
ZYDIS_EXPORT ZyDisBaseInstructionFormatterContext* ZyDisCustomInstructionFormatter_Create(
|
|
|
|
ZyDisBaseInstructionFormatter_InternalFormatInstructionCallback formatInsnCb);
|
2015-03-20 04:05:14 +08:00
|
|
|
|
2015-03-16 23:37:15 +08:00
|
|
|
/* ============================================================================================= */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2014-10-25 05:11:16 +08:00
|
|
|
}
|
2015-03-16 23:37:15 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-12 09:42:25 +08:00
|
|
|
#endif /* _VDE_ZyDisINSTRUCTIONFORMATTERC_H_ */
|