keystone-engine / keypatch

Multi-architecture assembler for IDA Pro. Powered by Keystone Engine.
http://www.keystone-engine.org/keypatch
GNU General Public License v2.0
1.47k stars 355 forks source link

How to assemble instruction like "mov x0, <VariableValue>" ? #84

Open Katana-O opened 2 years ago

Katana-O commented 2 years ago

Hi there. Normally in arm64 if we assemble an instruction like "mov x0, x1" or "mov x0, #0x100". it would be easily done. But in my case, "mov x0, Varaible" , the second operand is not fixed, its value will change. So, when I use ks_asm(&ks, ???, ......., ...., .... ) this API, what string I should input for the second argument?

Below is an example of my code, as you can see, each loop will increase the value of ucRun. So the value of ucRun is definitely not fixed here. So, could you give me some useful advise so I can make it work?

for(int i = 0; i < 10; ++i) { static size_t ucRun = 0x1000; ucRun = ucRun + 0x100; size_t ksAsmRet = ks_asm(ptrKS, "mov x9, ucRun", 0, &encodeBuf, &encodeSz, &encodeCount); }