Finished C-bindings export implementations

This commit is contained in:
flobernd 2015-05-18 16:37:31 +02:00
parent 2ffca64bcd
commit c4cb49faa7
2 changed files with 85 additions and 18 deletions

View File

@ -398,24 +398,91 @@ bool ZydisFreeInstructionFormatter(const ZydisInstructionFormatterContext* forma
/* SymbolResolver =============================================================================== */
ZYDIS_EXPORT ZydisSymbolResolverContext* ZydisCreateCustomSymbolResolver(/*TODO*/);
ZydisSymbolResolverContext* ZydisCreateCustomSymbolResolver(/*TODO*/)
{
return nullptr;
}
ZYDIS_EXPORT ZydisSymbolResolverContext* ZydisCreateExactSymbolResolver();
ZydisSymbolResolverContext* ZydisCreateExactSymbolResolver()
{
return ZydisCreateContextInplace<ZydisSymbolResolverContext, Zydis::ExactSymbolResolver>(
ZYDIS_CONTEXT_SYMBOLRESOLVER | ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT);
}
ZYDIS_EXPORT bool ZydisResolveSymbol(const ZydisSymbolResolverContext* resolver,
const ZydisInstructionInfo* info, uint64_t address, const char** symbol, uint64_t* offset);
bool ZydisResolveSymbol(const ZydisSymbolResolverContext* resolver,
const ZydisInstructionInfo* info, uint64_t address, const char** symbol, uint64_t* offset)
{
Zydis::BaseSymbolResolver* instance =
ZydisCast<ZydisSymbolResolverContext,
Zydis::BaseSymbolResolver>(resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER);
if (!instance)
{
return false;
}
*symbol = instance->resolveSymbol(*reinterpret_cast<const Zydis::InstructionInfo*>(info),
address, *offset);
return true;
}
ZYDIS_EXPORT bool ZydisExactSymbolResolverContainsSymbol(
const ZydisSymbolResolverContext* resolver, uint64_t address, bool* containsSymbol);
bool ZydisExactSymbolResolverContainsSymbol(
const ZydisSymbolResolverContext* resolver, uint64_t address, bool* containsSymbol)
{
Zydis::ExactSymbolResolver* instance =
ZydisCast<ZydisSymbolResolverContext,
Zydis::ExactSymbolResolver>(resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT);
if (!instance)
{
return false;
}
*containsSymbol = instance->containsSymbol(address);
return true;
}
ZYDIS_EXPORT bool ZydisExactSymbolResolverSetSymbol(const ZydisSymbolResolverContext* resolver,
uint64_t address, const char* symbol);
bool ZydisExactSymbolResolverSetSymbol(const ZydisSymbolResolverContext* resolver,
uint64_t address, const char* name)
{
Zydis::ExactSymbolResolver* instance =
ZydisCast<ZydisSymbolResolverContext,
Zydis::ExactSymbolResolver>(resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT);
if (!instance)
{
return false;
}
instance->setSymbol(address, name);
return true;
}
ZYDIS_EXPORT bool ZydisExactSymbolResolverRemoveSymbol(const ZydisSymbolResolverContext* resolver,
uint64_t address);
bool ZydisExactSymbolResolverRemoveSymbol(const ZydisSymbolResolverContext* resolver,
uint64_t address)
{
Zydis::ExactSymbolResolver* instance =
ZydisCast<ZydisSymbolResolverContext,
Zydis::ExactSymbolResolver>(resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT);
if (!instance)
{
return false;
}
instance->removeSymbol(address);
return true;
}
ZYDIS_EXPORT bool ZydisExactSymbolResolverClear(const ZydisSymbolResolverContext* resolver);
bool ZydisExactSymbolResolverClear(const ZydisSymbolResolverContext* resolver)
{
Zydis::ExactSymbolResolver* instance =
ZydisCast<ZydisSymbolResolverContext,
Zydis::ExactSymbolResolver>(resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT);
if (!instance)
{
return false;
}
instance->clear();
return true;
}
ZYDIS_EXPORT bool ZydisFreeSymbolResolver(const ZydisSymbolResolverContext* resolver);
bool ZydisFreeSymbolResolver(const ZydisSymbolResolverContext* resolver)
{
return ZydisFreeContext<ZydisSymbolResolverContext, Zydis::BaseSymbolResolver>(
resolver, ZYDIS_CONTEXT_SYMBOLRESOLVER);
}
/* ============================================================================================== */

View File

@ -548,15 +548,15 @@ typedef struct _ZydisInstructionInfo
typedef enum _ZydisContextType
{
ZYDIS_CONTEXT_INPUT = 0x0080,
ZYDIS_CONTEXT_INPUT_CUSTOM = 0x0001,
ZYDIS_CONTEXT_INPUT_MEMORY = 0x0002,
ZYDIS_CONTEXT_INPUT_CUSTOM = ZYDIS_CONTEXT_INPUT | 0x0001,
ZYDIS_CONTEXT_INPUT_MEMORY = ZYDIS_CONTEXT_INPUT | 0x0002,
ZYDIS_CONTEXT_INSTRUCTIONDECODER = 0x0040,
ZYDIS_CONTEXT_INSTRUCTIONFORMATTER = 0x0020,
ZYDIS_CONTEXT_INSTRUCTIONFORMATTER_CUSTOM = 0x0001,
ZYDIS_CONTEXT_INSTRUCTIONFORMATTER_INTEL = 0x0002,
ZYDIS_CONTEXT_INSTRUCTIONFORMATTER_CUSTOM = ZYDIS_CONTEXT_INSTRUCTIONFORMATTER | 0x0001,
ZYDIS_CONTEXT_INSTRUCTIONFORMATTER_INTEL = ZYDIS_CONTEXT_INSTRUCTIONFORMATTER | 0x0002,
ZYDIS_CONTEXT_SYMBOLRESOLVER = 0x0010,
ZYDIS_CONTEXT_SYMBOLRESOLVER_CUSTOM = 0x0001,
ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT = 0x0002
ZYDIS_CONTEXT_SYMBOLRESOLVER_CUSTOM = ZYDIS_CONTEXT_SYMBOLRESOLVER | 0x0001,
ZYDIS_CONTEXT_SYMBOLRESOLVER_EXACT = ZYDIS_CONTEXT_SYMBOLRESOLVER | 0x0002
} ZydisContextType;
typedef struct _ZydisInputContext