| 42 | } |
| 43 | |
| 44 | static void test() |
| 45 | { |
| 46 | csh handle; |
| 47 | cs_err err; |
| 48 | // Customize mnemonic JNE to "jnz" |
| 49 | cs_opt_mnem my_mnem = { X86_INS_JNE, "jnz" }; |
| 50 | // Set .mnemonic to NULL to reset to default mnemonic |
| 51 | cs_opt_mnem default_mnem = { X86_INS_JNE, NULL }; |
| 52 | |
| 53 | err = cs_open(CS_ARCH_X86, CS_MODE_32, &handle); |
| 54 | if (err) { |
| 55 | if (cs_support(CS_ARCH_X86)) { |
| 56 | printf("Failed on cs_open() with error returned: %u\n", err); |
| 57 | abort(); |
| 58 | } else |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | // 1. Print out the instruction in default setup. |
| 63 | printf("Disassemble X86 code with default instruction mnemonic\n"); |
| 64 | print_insn(handle); |
| 65 | |
| 66 | // Customized mnemonic JNE to JNZ using CS_OPT_MNEMONIC option |
| 67 | printf("\nNow customize engine to change mnemonic from 'JNE' to 'JNZ'\n"); |
| 68 | cs_option(handle, CS_OPT_MNEMONIC, (size_t)&my_mnem); |
| 69 | |
| 70 | // 2. Now print out the instruction in newly customized setup. |
| 71 | print_insn(handle); |
| 72 | |
| 73 | // Reset engine to use the default mnemonic of JNE |
| 74 | printf("\nReset engine to use the default mnemonic\n"); |
| 75 | cs_option(handle, CS_OPT_MNEMONIC, (size_t)&default_mnem); |
| 76 | |
| 77 | // 3. Now print out the instruction in default setup. |
| 78 | print_insn(handle); |
| 79 | |
| 80 | // Done |
| 81 | cs_close(&handle); |
| 82 | } |
| 83 | |
| 84 | int main() |
| 85 | { |
no test coverage detected
searching dependent graphs…