fill insn with mnemonic & operands info
| 566 | |
| 567 | // fill insn with mnemonic & operands info |
| 568 | static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCInst *mci, |
| 569 | PostPrinter_t postprinter, const uint8_t *code) |
| 570 | { |
| 571 | #ifndef CAPSTONE_DIET |
| 572 | char *sp, *mnem; |
| 573 | #endif |
| 574 | uint16_t copy_size = MIN(sizeof(insn->bytes), insn->size); |
| 575 | |
| 576 | // fill the instruction bytes. |
| 577 | // we might skip some redundant bytes in front in the case of X86 |
| 578 | memcpy(insn->bytes, code + insn->size - copy_size, copy_size); |
| 579 | insn->op_str[0] = '\0'; |
| 580 | insn->size = copy_size; |
| 581 | |
| 582 | // alias instruction might have ID saved in OpcodePub |
| 583 | if (MCInst_getOpcodePub(mci)) |
| 584 | insn->id = MCInst_getOpcodePub(mci); |
| 585 | |
| 586 | // post printer handles some corner cases (hacky) |
| 587 | if (postprinter) |
| 588 | postprinter((csh)handle, insn, buffer, mci); |
| 589 | |
| 590 | #ifndef CAPSTONE_DIET |
| 591 | mnem = insn->mnemonic; |
| 592 | // memset(mnem, 0, CS_MNEMONIC_SIZE); |
| 593 | for (sp = buffer; *sp; sp++) { |
| 594 | if (*sp == ' '|| *sp == '\t') |
| 595 | break; |
| 596 | if (*sp == '|') // lock|rep prefix for x86 |
| 597 | *sp = ' '; |
| 598 | // copy to @mnemonic |
| 599 | *mnem = *sp; |
| 600 | mnem++; |
| 601 | } |
| 602 | |
| 603 | *mnem = '\0'; |
| 604 | |
| 605 | // we might have customized mnemonic |
| 606 | if (handle->mnem_list) { |
| 607 | struct insn_mnem *tmp = handle->mnem_list; |
| 608 | while(tmp) { |
| 609 | if (tmp->insn.id == insn->id) { |
| 610 | char str[CS_MNEMONIC_SIZE]; |
| 611 | |
| 612 | if (!str_replace(str, insn->mnemonic, cs_insn_name((csh)handle, insn->id), tmp->insn.mnemonic)) { |
| 613 | // copy result to mnemonic |
| 614 | (void)strncpy(insn->mnemonic, str, sizeof(insn->mnemonic) - 1); |
| 615 | insn->mnemonic[sizeof(insn->mnemonic) - 1] = '\0'; |
| 616 | } |
| 617 | |
| 618 | break; |
| 619 | } |
| 620 | tmp = tmp->next; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | // copy @op_str |
| 625 | if (*sp) { |
no test coverage detected
searching dependent graphs…