SSpoke
SSpoke

Reputation: 5836

Calling ASM Function in C++

I asked a question yesterday, how to call a __fastcall function, it worked great.

Now my final function i got to call is having some difficulties.

Here is the ASM function.

seg000:0043671F                 push    0AA2BAD1Bh
seg000:00436724                 lea     ecx, [ebp+var_14]
seg000:00436727                 call    sub_458E90

IDA PRO labels it as.

int __thiscall sub_458E90(void *this, int a2)

It's called like this

sub_458E90(&v9, -1439978213);

Now here is the code I tried and it just gives me a Exception at runtime

   int addr = 0x458E90;

    __declspec(naked) void sub_458E90(int buffer, int key)
    {
        __asm{
            push key
            mov ecx, buffer
            call [addr]
             retn
        }
    }

Also tried

__declspec(naked) void sub_458E90_1(int buffer, int key)
{
    __asm{
        push key
        mov ecx, buffer
        jmp [addr]
    }
}

Both give me

Application Error The instruction at "0x00458e93" refenced memory at "0x00000000". The memory could not be "read".

Upvotes: 0

Views: 767

Answers (1)

SSpoke
SSpoke

Reputation: 5836

Solved ebx must of been used for key. Simple as that.

void also must of been changed to int forgot about that. (most likely not to important)

Upvotes: 1

Related Questions