Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing C struct members in inline assembly

In the following code, rEDX, rEBX, rEBP, rESI and rEDI are the members of the structure scratch_space. scratch_space_arg is an object of the structure scratch_space.

lea eax, scratch_space_arg
mov [ecx+[eax].rEDX], edx
mov [ecx+[eax].rEBX], ebx
mov [ecx+[eax].rEBP], ebp
mov [ecx+[eax].rESI], esi
mov [ecx+[eax].rEDI], edi

This code gives me an:

error C2426: '[' : illegal operator in 'first operand'

for all the mov statements. Any idea how I can resolve this?

PS: I used this article to access the struct members.

like image 307
Shambavi Avatar asked Apr 30 '26 12:04

Shambavi


1 Answers

I recommend disassembling some C code that references the structure elements:

struct scratch_space scratch_space_arg = { 0, 0, 0, 0, 0 };
int rEDX = scratch_space_arg.rEDX;
int rEBX = scratch_space_arg.rEBX;
int rEBP = scratch_space_arg.rEBP;
int rESI = scratch_space_arg.rESI;
int rEDI = scratch_space_arg.rEDI;
printf("%d %d %d %d %d\n", rEDX, rEBX, rEBP, rESI, rEDI);

Then you'll know the correct notation to use yourself.

like image 200
Jonathan Leffler Avatar answered May 03 '26 03:05

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!