add new API: cs_strerror() return a string describing a given error code. this should be used together with cs_errno()
This commit is contained in:
parent
ee143c8c6c
commit
34f96389a9
|
@ -196,6 +196,7 @@ _setup_prototype(_cs, "cs_errno", ctypes.c_int, ctypes.c_size_t)
|
|||
_setup_prototype(_cs, "cs_option", ctypes.c_int, ctypes.c_size_t, ctypes.c_int, ctypes.c_size_t)
|
||||
_setup_prototype(_cs, "cs_version", ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
|
||||
_setup_prototype(_cs, "cs_support", ctypes.c_bool, ctypes.c_int)
|
||||
_setup_prototype(_cs, "cs_strerror", ctypes.c_char_p, ctypes.c_int)
|
||||
|
||||
|
||||
# access to error code via @errno of CsError
|
||||
|
@ -204,16 +205,7 @@ class CsError(Exception):
|
|||
self.errno = errno
|
||||
|
||||
def __str__(self):
|
||||
messages = { \
|
||||
CS_ERR_MEM: "Out of memory (CsError)",
|
||||
CS_ERR_ARCH: "Invalid architecture (CsError)",
|
||||
CS_ERR_HANDLE: "Invalid handle (CsError)",
|
||||
CS_ERR_CSH: "Invalid csh (CsError)",
|
||||
CS_ERR_MODE: "Invalid mode (CsError)",
|
||||
CS_ERR_OPTION: "Invalid option (CsError)",
|
||||
CS_ERR_DETAIL: "Details are unavailable (CsError)",
|
||||
}
|
||||
return messages[self.errno]
|
||||
return _cs.cs_strerror(self.errno)
|
||||
|
||||
|
||||
def cs_version():
|
||||
|
|
24
cs.c
24
cs.c
|
@ -50,6 +50,30 @@ cs_err cs_errno(csh handle)
|
|||
return ud->errnum;
|
||||
}
|
||||
|
||||
const char *cs_strerror(cs_err code)
|
||||
{
|
||||
switch(code) {
|
||||
default:
|
||||
return "Unknown error code";
|
||||
case CS_ERR_OK:
|
||||
return "OK (CS_ERR_OK)";
|
||||
case CS_ERR_MEM:
|
||||
return "Out of memory (CS_ERR_MEM)";
|
||||
case CS_ERR_ARCH:
|
||||
return "Invalid architecture (CS_ERR_ARCH)";
|
||||
case CS_ERR_HANDLE:
|
||||
return "Invalid handle (CS_ERR_HANDLE)";
|
||||
case CS_ERR_CSH:
|
||||
return "Invalid csh (CS_ERR_CSH)";
|
||||
case CS_ERR_MODE:
|
||||
return "Invalid mode (CS_ERR_MODE)";
|
||||
case CS_ERR_OPTION:
|
||||
return "Invalid option (CS_ERR_OPTION)";
|
||||
case CS_ERR_DETAIL:
|
||||
return "Details are unavailable (CS_ERR_DETAIL)";
|
||||
}
|
||||
}
|
||||
|
||||
cs_err cs_open(cs_arch arch, cs_mode mode, csh *handle)
|
||||
{
|
||||
cs_struct *ud;
|
||||
|
|
|
@ -224,6 +224,17 @@ cs_err cs_option(csh handle, cs_opt_type type, size_t value);
|
|||
*/
|
||||
cs_err cs_errno(csh handle);
|
||||
|
||||
|
||||
/*
|
||||
Return a string describing given error code.
|
||||
|
||||
@code: error code (see CS_ERR_* above)
|
||||
|
||||
@return: returns a pointer to a string that describes the error code
|
||||
passed in the argument @code
|
||||
*/
|
||||
const char *cs_strerror(cs_err code);
|
||||
|
||||
/*
|
||||
Dynamicly allocate memory to contain disasm insn
|
||||
Disassembled instructions will be put into @*insn
|
||||
|
|
Loading…
Reference in New Issue