capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.57k stars 1.55k forks source link

Possibility to recalculate `op_str` when changing for example the displacement #921

Open koemeet opened 7 years ago

koemeet commented 7 years ago

It would be nice if it was possible to alter the disp member of a cs_x86 object and calculate a new operands string for that instruction. Is it maybe already possible to rebuild the operands string, given some cs_insn or cs_x86 object?

Example

insn.op_str; // returns `call qword ptr [rip + 0x1058]`
insn.detail->x86.disp = 0x1060;

insn.recalculate(); // pseudo call to imaginary function

insn.op_str; // returns `call qword ptr [rip + 0x1060]`

This would be very useful when you use Capstone to change some instructions around and you need to re-locate certain instructions so they match with the correct offsets again.

aquynh commented 7 years ago

Yes, i am going to add a new API for this, then you can feed the newly generated code to Keystone, for example.

koemeet commented 7 years ago

@aquynh Awesome!