captmicro

Untitled

Jun 14th, 2010
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     apiprint(NULL, "[HotLoad Dll Test]\n");
  6.  
  7.     char dllPath[MAX_PATH] = {0};
  8.     lstrcpyA(dllPath, argv[1]);
  9.     char dllName[MAX_PATH] = {0};
  10.     lstrcpyA(dllName, argv[2]);
  11.     char dllFull[MAX_PATH] = {0};
  12.     lstrcpyA(dllFull, dllPath);
  13.     dllFull[lstrlenA(dllFull)] = '\\';
  14.     lstrcatA(dllFull, dllName);
  15.    
  16.     apiprint(NULL, "Dll Path: %s\n", dllPath);
  17.     apiprint(NULL, "Dll Name: %s\n", dllName);
  18.     apiprint(NULL, "Dll FUll: %s\n\n", dllFull);
  19.  
  20.     HMODULE dll;
  21.     math_add MathAdd;
  22.     math_sub MathSub;
  23.     math_mul MathMul;
  24.     math_div MathDiv;
  25.  
  26.     while (true)
  27.     {
  28.         dll = LoadLibraryA(dllFull);
  29.         MathAdd = (math_add)GetProcAddress(dll, "m_add");
  30.         MathSub = (math_sub)GetProcAddress(dll, "m_sub");
  31.         MathMul = (math_mul)GetProcAddress(dll, "m_mul");
  32.         MathDiv = (math_div)GetProcAddress(dll, "m_div");
  33.  
  34.         apiprint(NULL, "Dll Update! Testing functions:\n");
  35.         apiprint(NULL, "m_add(5, 10) = %d\n", MathAdd(5, 10));
  36.         apiprint(NULL, "m_sub(5, 10) = %d\n", MathSub(5, 10));
  37.         apiprint(NULL, "m_mul(5, 10) = %d\n", MathMul(5, 10));
  38.         apiprint(NULL, "m_div(5, 10) = %d\n", MathDiv(5, 10));
  39.         apiprint(NULL, "Waiting for dll to update...\n\n");
  40.  
  41.         FreeLibrary(dll);
  42.         waitForChange(dllPath);
  43.     }
  44.  
  45.     getchar();
  46.     return 0;
  47. }
  48.  
  49. void waitForChange(char *path)
  50. {
  51.     HANDLE waitHandle = FindFirstChangeNotificationA(path, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
  52.     WaitForSingleObject(waitHandle, INFINITE);
  53. }
  54.  
  55. void apiprint(int buffsize, char *fmt, ...)
  56. {
  57.     HANDLE phandle = GetStdHandle(STD_OUTPUT_HANDLE);
  58.  
  59.     char *printstring;
  60.     printstring = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (buffsize==NULL)?256:buffsize);
  61.     memset(printstring, 0, sizeof(printstring));
  62.  
  63.     va_list args;
  64.     va_start(args, fmt);
  65.     vsprintf(printstring, fmt, args);
  66.     va_end(args);
  67.  
  68.     WriteConsoleA(phandle, printstring, lstrlenA(printstring), NULL, NULL);
  69.     HeapFree(GetProcessHeap(), NULL, printstring);
  70. }
Add Comment
Please, Sign In to add comment