| 702 | |
| 703 | CAPSTONE_EXPORT |
| 704 | cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value) |
| 705 | { |
| 706 | struct cs_struct *handle; |
| 707 | cs_opt_mnem *opt; |
| 708 | |
| 709 | // cs_option() can be called with NULL handle just for CS_OPT_MEM |
| 710 | // This is supposed to be executed before all other APIs (even cs_open()) |
| 711 | if (type == CS_OPT_MEM) { |
| 712 | cs_opt_mem *mem = (cs_opt_mem *)value; |
| 713 | |
| 714 | cs_mem_malloc = mem->malloc; |
| 715 | cs_mem_calloc = mem->calloc; |
| 716 | cs_mem_realloc = mem->realloc; |
| 717 | cs_mem_free = mem->free; |
| 718 | cs_vsnprintf = mem->vsnprintf; |
| 719 | |
| 720 | return CS_ERR_OK; |
| 721 | } |
| 722 | |
| 723 | handle = (struct cs_struct *)(uintptr_t)ud; |
| 724 | if (!handle) |
| 725 | return CS_ERR_CSH; |
| 726 | |
| 727 | switch(type) { |
| 728 | default: |
| 729 | break; |
| 730 | |
| 731 | case CS_OPT_UNSIGNED: |
| 732 | handle->imm_unsigned = (cs_opt_value)value; |
| 733 | return CS_ERR_OK; |
| 734 | |
| 735 | case CS_OPT_DETAIL: |
| 736 | handle->detail = (cs_opt_value)value; |
| 737 | return CS_ERR_OK; |
| 738 | |
| 739 | case CS_OPT_SKIPDATA: |
| 740 | handle->skipdata = (value == CS_OPT_ON); |
| 741 | if (handle->skipdata) { |
| 742 | if (handle->skipdata_size == 0) { |
| 743 | // set the default skipdata size |
| 744 | handle->skipdata_size = skipdata_size(handle); |
| 745 | } |
| 746 | } |
| 747 | return CS_ERR_OK; |
| 748 | |
| 749 | case CS_OPT_SKIPDATA_SETUP: |
| 750 | if (value) { |
| 751 | handle->skipdata_setup = *((cs_opt_skipdata *)value); |
| 752 | if (handle->skipdata_setup.mnemonic == NULL) { |
| 753 | handle->skipdata_setup.mnemonic = SKIPDATA_MNEM; |
| 754 | } |
| 755 | } |
| 756 | return CS_ERR_OK; |
| 757 | |
| 758 | case CS_OPT_MNEMONIC: |
| 759 | opt = (cs_opt_mnem *)value; |
| 760 | if (opt->id) { |
| 761 | if (opt->mnemonic) { |
searching dependent graphs…