Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Emulating Windows __thiscall in C

Name: Anonymous 2010-09-26 3:48

Does anyone know to call a __thiscall function from C code? It's not a problem of garbled symbols (I have its address), it's a problem of passing this pointer in ecx. I thought declaring function as __stdcall and storing stuff in ecx with assembly magic would work, like this:
    __asm { mov ecx,self }
    res=sub(a2,a3,a4,a5,a6,a7);


But code generated by visual studio overwrites ecx:
dinput8.dll:66551153 mov     ecx, [esp+10h] # my code
dinput8.dll:66551157 mov     ecx, [esp+120h] # automatically generated by msvcs, thanks a lot
dinput8.dll:6655115E mov     edx, [esp+11Ch]
dinput8.dll:66551165 push    esi
dinput8.dll:66551166 push    edi
dinput8.dll:66551167 push    ebx
dinput8.dll:66551168 push    ebp
dinput8.dll:66551169 push    ecx
dinput8.dll:6655116A push    edx
dinput8.dll:6655116B call    off_66553344


Any ideas? I'd even be fine with writing some fake C++ class and calling its method, but unfortunately you can't specify an address of method of class when calling it...

Name: Anonymous 2010-09-26 5:28

>>4
Er, is this supposed to be an insult? Maybe I was doing something else at this time, or didn't post immediately after discovering this method and just went about using it for my greasy purposes instead?

Anyway, I'm struggling to eliminate that pop ebp now. From what I understand, what I popping from stack is a frame pointer (compiler generates push ebp; mov ebp, esp), so if someone enables the eliminate frame pointer optimization, it will all break, since I'll be popping something important off stack. What's strange though, is that neither __pragma(optimize( "y", off )), nor disabling frame pointer globally are removing this push ebp.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List