C
flenders schrieb:
Zeig mal deinen Code, wie du das ganze jetzt aufrufst
Hi flenders!
Ja der Code steht unten (leider etwas vermackt, weil ich da soviel dran rumgetestet habe). Naja, ich lege die Parameter ganz einfach fest, indem ich dem programm sage, ob der Parameter numerisch (long) oder ein string (char*) ist (also n oder s eingeben) und kann dann noch einen Wert eingeben. Naja probier's aus
#include <windows.h>
#include <string.h>
#include <fstream.h>
#include <conio.h>
#pragma hdrstop
#include <condefs.h>
#include <commctrl.h>
typedef struct { void *dwARG[10]; } STACK;
//typedef struct { void *dwARG[10]; } STACK;
typedef DWORD (*PFDLL) (STACK);
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
char dllpath[MAXPATH+1];
char funcname[1024+1];
char type[1+1];
char ftype[1+1];
char tmpdata_str[10][255];
int maxval = 0;
//STACK* args = new STACK;
STACK args;
/*
int x = 5;
char* bla = "hallo";
int* ptr_x = &x;
args->dwARG[0] = (int*) ptr_x;
args->dwARG[0] = (char*) bla;
*/
memset(&args, 0, sizeof(STACK));
DWORD dwRet;
printf("DLL Tester\n\n");
printf("Enter DLL filename: ");
gets(dllpath);
if(strcmp(dllpath, "") == 0)
{
strcpy(dllpath, "c:\\winnt\\system32\\kernel32.dll");
//strcpy(dllpath, "c:\\winnt\\system32\\advapi32.dll");
//strcpy(dllpath, "c:\\winnt\\system32\\user32.dll");
//return -1;
}
printf("Enter function to call: ");
gets(funcname);
if(strcmp(funcname, "") == 0)
{
strcpy(funcname, "GetComputerNameA");
//strcpy(funcname, "GetCurrentDirectoryA");
//strcpy(funcname, "CopyFileA");
//strcpy(funcname, "MessageBoxA");
//return -1;
}
while(1)
{
printf("Return value of the function (n/s): ");
gets(ftype);
if(strcmp(ftype, "n") == 0 || strcmp(ftype, "s") == 0) break;
}
for(int i=0;i<10;i++)
{
printf("Data type %i (n/s): ", i);
gets(type);
if(strcmp(type, "") == 0) break;
maxval++;
if(strcmp(type, "n") == 0)
{
printf("Numerical value: ");
gets(tmpdata_str[i]);
args.dwARG[i] = (long*) atoi(tmpdata_str[i]);
//printf ("\t%d\n", bla);
//int bin_doof = atoi(tmpdata_str[i]);
//int* ptr_int = (int*) args->dwARG;
//args[i] = (DWORD) atoi(tmpdata_str[i]);
}
else if(strcmp(type, "s") == 0)
{
printf("String value: ");
gets(tmpdata_str[i]);
args.dwARG[i] = (char*) tmpdata_str[i];
//memcpy(&(args->dwARG[i]), tmpdata_str[i], sizeof(DWORD));
//args.dwARG[i] = (DWORD) tmpdata_str[i];
//args[i] = (DWORD) tmpdata_str[i];
}
else
{
printf("Unknown type, try again.\n");
i--;
maxval--;
}
}
/*
printf("Values of stack:\n");
for(int i=0;i<maxval-1;i++)
{
printf("\n%d => %s %d", i, (char*) args.dwARG[i], (int) args.dwARG[i]);
}
*/
printf("\nOk, ready to run, press any key...\n");
getch();
/*
strcpy(ftype, "n");
strcpy(dllpath, "c:\\winnt\\system32\\advapi32.dll");
strcpy(funcname, "GetUserNameA");
DWORD test = (DWORD) "Hello World";
args.dwARG[0] = &test ;
args.dwARG[1] = (DWORD*) 255;
*/
/*
strcpy(dllpath, "c:\\winnt\\system32\\user32.dll");
strcpy(funcname, "MessageBoxA");
char *test = "Hello World";
int n1 = 0;
int n2 = 48;
args.dwARG[0] = (DWORD) 0 ;
args.dwARG[1] = (DWORD*) test;
args.dwARG[2] = (DWORD*) test;
args.dwARG[3] = (DWORD*) 48;
*/
printf("Loading the DLL...\n");
HINSTANCE hDll = LoadLibrary(dllpath);
if(hDll == NULL)
{
printf("ERROR: DLL not found!\n");
getch();
return -1;
}
printf("Loading the Procedure...\n");
PFDLL pfFunc = (PFDLL) GetProcAddress(hDll, funcname);
if(pfFunc == NULL)
{
printf("ERROR: Function not found!\n");
getch();
return -1;
}
printf("Okay. Initializing the parameters NOW...");
/*
char szBuf1[] = "hello world jajaja";
char szBuf2[] = "das ist ein test";
args.dwARG[0] = 0;
args.dwARG[1] = (DWORD) szBuf1;
args.dwARG[2] = (DWORD) szBuf2;
args.dwARG[3] = 68;
*/
printf("Done\n");
printf("Executing...");
dwRet = 0;
if(strcmp(ftype, "n") == 0)
{
dwRet = (pfFunc) (args);
printf("Done\n\n");
printf("Return value: %d", (int) dwRet);
}
else
{
dwRet = (pfFunc) (args);
printf("Done\n\n");
printf("Return value: %s", (char*) dwRet);
}
/*
printf("Values of stack:\n");
for(int i=0;i<maxval;i++)
{
printf("\n%d => %s %d", i, (char*) &args.dwARG[i], (int) args.dwARG[i]);
}
*/
maxval=2;
printf("Values of stack:\n");
for(int i=0;i<10;i++)
{
printf("%s\n", tmpdata_str[i]);
}
getch();
printf("\nGoodbye ;)...\n\n");
return 0;
}