Jump to content
Nytro

[C++] Dynamic Dll Function Calling

Recommended Posts

O metoda "draguta" de apel dinamic. Autorul nu il stiu, cred ca e vorba de "Skillless".

#include <windows.h>

int main()
{
HINSTANCE Dll = LoadLibrary("user32.dll");
DWORD(*Func)(void) = (DWORD(*)(void))GetProcAddress(Dll, "MessageBoxA");

HWND A = 0;
LPCTSTR B = "Question?";
LPCTSTR C = "Title!";
UINT D = MB_ICONEXCLAMATION | MB_YESNO;

asm("push %0" :: "r"(D));
asm("push %0" :: "r"(C));
asm("push %0" :: "r"(B));
asm("push %0" :: "r"(A));

Func();

asm("pop %0" :: "r"(A));
asm("pop %0" :: "r"(B));
asm("pop %0" :: "r"(C));
asm("pop %0" :: "r"(D));

FreeLibrary(Dll);

return 0;
}

Va dati si voie seama ce face, ce functie apeleaza si cum.

Link to comment
Share on other sites

Presupun doar din ochi, ca e vorba de afisarea unui alert.

Da ce tare! simplu si dragut cat sa pricepi un apel de functie cu transmiterea parametrilor in stiva inainte de apelare, putina asamblare si lucrul cu un DLL = in asta chiar eram total afon.

Link to comment
Share on other sites

Daca faci chestia asta dupa ce ai apelat MessageBox ai bulit stiva si tot ce se intampla dupa o sa fie vraiste

sunt curios: de ce? nu e simplu push si pop? E vorba de vreo eliberare automata inainte de pop provocata de func, cod adaugat in compilare? Ca altfel par sa corespunda in program si sa fie ok.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...