Error c2400

Dec 12, 2021 at 6:18pm
Why this error
error C2400: inline assembler syntax error in 'first operand';
i use [visual studio 2010]
error here [mov [offset],esi]
1
2
3
4
5
6
7
8
9
10
11
12
void __declspec(naked) ourFunct()
{
   int offset;
    __asm
    {
	//inc [esi]
	mov [offset],esi
        push edi
        mov edi, [esp + 0x14]
        jmp jmpBackAddy
    }
}


Last edited on Dec 12, 2021 at 6:18pm
Dec 12, 2021 at 6:36pm
Try renaming your local variable offset into something else, I suppose.

The keyword "offset" is reserved in assembler language:
https://docs.microsoft.com/en-us/cpp/assembler/masm/operator-offset?view=msvc-170
Last edited on Dec 12, 2021 at 6:40pm
Dec 12, 2021 at 7:33pm
Thanks so much , it's work .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void __declspec(naked) ourFunct()
{


    __asm
    {
	//inc [esi]
	mov [buffer_ptr], esi
        push edi
        mov edi, [esp + 0x14]
        jmp jmpBackAddy
    }
	
}


why return 0
i use this cout << "ESI address "<<uppercase << hex << buffer_ptr << endl;

try to use it like this but got errors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void __declspec(naked) ourFunct()
{

    DWORD  buffer_ptr;
    __asm
    {
	//inc [esi]
	mov [buffer_ptr], esi
        push edi
        mov edi, [esp + 0x14]
        jmp jmpBackAddy
    }
	return buffer_ptr;
}

error C2490: 'return' not allowed in function with 'naked' attribute

Last edited on Dec 12, 2021 at 7:37pm
Dec 12, 2021 at 9:11pm
Hawlong wrote:
error C2490: 'return' not allowed in function with 'naked' attribute


To my understanding, function declared with "naked" attribute has no (compiler-generated) prolog or epilog.

In other words, the compiler does nothing to grab the function's arguments from the stack (should they be passed on the stack rather than in registers), or to put the return value onto the stack (or into the register where the result is expected) – which explains why a "normal" return is not possible in such function. Also the compiler does nothing to save/restore "callee-saved" registers. You have to do all that in your ASM code...
Last edited on Dec 12, 2021 at 9:14pm
Dec 13, 2021 at 12:05pm
thanks so much kigar64551 .

Dec 13, 2021 at 12:10pm
Just for info. If you compile with VS as 64 bit, you can't use in-line assembler code.
Topic archived. No new replies allowed.