1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include <iostream>
using namespace std;
#include <string>
#include <windows.h>
#include <stdio.h>
template <typename type1, typename type2, typename type3, typename type4>
struct FCTX
{
typedef int (__stdcall *type)(type1, type2, type3, type4);
};
#define FUNCTION_NAME "MessageBoxA" // name of the function we want to call
#define MODULE_NAME "user32.dll" // Library where the function is
void itsAfunction(string msgBuf);
string readName(string msgBuf);
int ltr=0;
static char ModPath[255]="C:\\WINDOWS\\SYSTEM32\\"; // path to DLL
int Status;
HMODULE ModId;
string msgBuf("fMessageBoxA@193title"); // Generic message arrives, and is stocked in msgBuf
int main()
{
strcat(ModPath, MODULE_NAME); // complete path to DLL
ModId = LoadLibrary(ModPath);
switch (msgBuf[0]) //Reading of the message
{
case 'f' : // it is a function
ltr=1;
itsAfunction(msgBuf);
break;
defaut : // Not well formatted message
break;
}
FreeLibrary(ModId);
return 0;
}
void itsAfunction(string msgBuf)
{
FCTX<int, char*, char*, unsigned int>::type;
FCTX Fn_Ptr;
string funcName(readName(msgBuf));
LPCSTR funcName2="MessageBoxA";
Fn_Ptr = (FCTX)GetProcAddress(ModId, funcName2);
string paramValue;
switch (193)
{
case 193 : // it is a int IN
//paramValue=readName(msgBuf);
Status = Fn_Ptr(0, "Some text and some text again", "title", MB_OK);
break;
defaut :
break;
}
}
string readName(string msgBuf)
{
string funcName("");
while(msgBuf[ltr]!='@' && msgBuf[ltr]!='\0')
{
funcName+=msgBuf[ltr]; // We write the function name in funcName
ltr++;
}
return funcName;
} |
Partager