Check for leading space chars in the asm text and remove them. (#2192)
This commit is contained in:
parent
f8b7ae7c2a
commit
b87cf06209
22
cs.c
22
cs.c
|
@ -562,6 +562,27 @@ static int str_replace(char *result, char *target, const char *str1, char *str2)
|
||||||
return -1;
|
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
|
// fill insn with mnemonic & operands info
|
||||||
static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCInst *mci,
|
static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCInst *mci,
|
||||||
PostPrinter_t postprinter, const uint8_t *code)
|
PostPrinter_t postprinter, const uint8_t *code)
|
||||||
|
@ -569,6 +590,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI
|
||||||
#ifndef CAPSTONE_DIET
|
#ifndef CAPSTONE_DIET
|
||||||
char *sp, *mnem;
|
char *sp, *mnem;
|
||||||
#endif
|
#endif
|
||||||
|
fixup_asm_string(buffer);
|
||||||
uint16_t copy_size = MIN(sizeof(insn->bytes), insn->size);
|
uint16_t copy_size = MIN(sizeof(insn->bytes), insn->size);
|
||||||
|
|
||||||
// fill the instruction bytes.
|
// fill the instruction bytes.
|
||||||
|
|
Loading…
Reference in New Issue