Skip to content

Commit

Permalink
Check for leading space chars in the asm text and remove them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Nov 9, 2023
1 parent 7bd3683 commit 1f32e60
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,35 @@ static int str_replace(char *result, char *target, const char *str1, char *str2)
return -1;
}

/// The asm string sometimes has a leading space or tab.
/// Here we remove it.
static void fixup_asm_string(char *asm_str) {
if (!asm_str) {
return;
}
int i = 0;
int k = 0;
bool text_reached = (asm_str[0] != ' ' && asm_str[0] != '\t');
while (asm_str[i]) {
if (!text_reached && (asm_str[i] == ' ' || asm_str[i] == '\t')) {
++i;
text_reached = true;
continue;
}
asm_str[k] = asm_str[i];
++k, ++i;
}
asm_str[k] = '\0';
}

// fill insn with mnemonic & operands info
static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCInst *mci,
PostPrinter_t postprinter, const uint8_t *code)
{
#ifndef CAPSTONE_DIET
char *sp, *mnem;
#endif
fixup_asm_string(buffer);
uint16_t copy_size = MIN(sizeof(insn->bytes), insn->size);

// fill the instruction bytes.
Expand Down

0 comments on commit 1f32e60

Please sign in to comment.