capstone icon indicating copy to clipboard operation
capstone copied to clipboard

Very inefficient patching of Capstone register alias.

Open Rot127 opened this issue 8 months ago • 0 comments

Capstone used different ARM register alias than the one from LLVM. Back then I implemented some lazy patching if a flag was set in ARMMapping.c::patch_cs_reg_alias(). This one uses a lot of strstr() and has a best case runtime of O(|asm_text| * 7) (yes I feel bad about this in retrospect).

This is only called if the CS_OPT_SYNTAX_CS_REG_ALIAS flag is set. Which many people probably use, if they switched to v6, the tests break by default since Capstone no longer defaults to the old alias. So people probably use the flag to have less trouble.

This function must be made more efficient before the Beta.

Two options:

  • Intermediate option: Check the details for any of the effected registers and only patch if they are present.
  • The actual solution: Add the Capstone alias in the td files. The key words to search for are: RegAltNameIndices and more generally AltName in ARMRegisterInfo.td. And go from there to see how other alias are implemented.

Rot127 avatar Mar 27 '25 11:03 Rot127