API: extend cs_support() to allow query on diet mode. add CS_SUPPORT_DIET at the same time

This commit is contained in:
Nguyen Anh Quynh 2014-02-22 23:41:16 +08:00
parent fc83a439e5
commit b2870e4c4c
2 changed files with 27 additions and 8 deletions

18
cs.c
View File

@ -74,14 +74,26 @@ unsigned int cs_version(int *major, int *minor)
return (CS_API_MAJOR << 8) + CS_API_MINOR;
}
bool cs_support(int arch)
bool cs_support(int query)
{
if (arch == CS_ARCH_ALL)
if (query == CS_ARCH_ALL)
return all_arch == ((1 << CS_ARCH_ARM) | (1 << CS_ARCH_ARM64) |
(1 << CS_ARCH_MIPS) | (1 << CS_ARCH_X86) |
(1 << CS_ARCH_PPC));
return all_arch & (1 << arch);
if (query < CS_ARCH_MAX)
return all_arch & (1 << query);
if (query == CS_SUPPORT_DIET) {
#ifdef CAPSTONE_DIET
return true;
#else
return false;
#endif
}
// unsupported query
return false;
}
cs_err cs_errno(csh handle)

View File

@ -43,6 +43,8 @@ typedef enum cs_arch {
CS_ARCH_ALL = 0xFFFF,
} cs_arch;
#define CS_SUPPORT_DIET (0xFFFF + 1)
// Mode type
typedef enum cs_mode {
CS_MODE_LITTLE_ENDIAN = 0, // little endian mode (default mode)
@ -196,14 +198,19 @@ unsigned int cs_version(int *major, int *minor);
/*
Check if a particular arch is supported by this library.
This API can be used to either ask for archs supported by this library,
or check to see if the library is in 'diet' mode.
@arch: the architecture to be checked.
To verify if this library supports everything, use CS_ARCH_ALL
To check if a particular arch is supported by this library, set @query to
arch mode (CS_ARCH_* value).
To verify if this library supports all the archs, use CS_ARCH_ALL.
@return True if this library supports the given arch.
To check if this library is in 'diet' mode, set @query to CS_SUPPORT_DIET.
This equivalent to the existence of macro CAPSTONE_DIET in include/diet.h
@return True if this library supports the given arch, or in diet mode.
*/
bool cs_support(int arch);
bool cs_support(int query);
/*
Initialize CS handle: this must be done before any usage of CS.