Advertisement
IVDZ

Dll Injector

Jul 26th, 2014
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. //##############################################
  2. //######### Dll Injector , Coded By IVDZ #########
  3. //##############################################
  4. #include <Windows.h>
  5. #include <tlhelp32.h>
  6. #include <comdef.h>
  7. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  8. bool Inject(char* Dll ,char* Process);
  9. HWND button,TXT1,TXT2;
  10. int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil)
  11. {
  12.     //Create Window with Controls :
  13.     WNDCLASS Form1;
  14.     Form1.cbClsExtra = 0;
  15.     Form1.cbWndExtra = 0;
  16.     Form1.hbrBackground = (HBRUSH)5;
  17.     Form1.hCursor = LoadCursor(0,IDC_ARROW);
  18.     Form1.hIcon = LoadIcon(0,IDI_APPLICATION);
  19.     Form1.hInstance = hThisInstance;
  20.     Form1.lpfnWndProc = WndProc;//-------------------------
  21.     Form1.lpszClassName = TEXT("Form1");
  22.     Form1.lpszMenuName = 0;
  23.     Form1.style= 0;
  24.     RegisterClass(&Form1);
  25.     HWND a =CreateWindow(TEXT("Form1"),TEXT("Injector By IVDZ"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,400,200,0,0,0,0);
  26.     button = CreateWindowEx(0,TEXT("Button"),TEXT("Inject Dll"),WS_CHILD |WS_VISIBLE,160,100,100,50,a,0,0,0);
  27.     TXT1 = CreateWindowEx(0,TEXT("edit"),TEXT("c:\\MyDll.dll"),WS_CHILD |WS_VISIBLE,50,20,300,30,a,0,0,0);
  28.     TXT2 = CreateWindowEx(0,TEXT("edit"),TEXT("Example.exe"),WS_CHILD |WS_VISIBLE,50,60,300,30,a,0,0,0);
  29.     ShowWindow(a,1);
  30.     UpdateWindow(a);
  31.     MSG msg;
  32.     while (GetMessage(&msg,a,0,0))
  33.     {
  34.         TranslateMessage(&msg);
  35.         DispatchMessage(&msg);
  36.  
  37.     }
  38. }
  39. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  40. {
  41.     switch (msg)
  42.     {
  43.     case WM_CLOSE:
  44.         ExitProcess(0);
  45.     case WM_COMMAND:
  46.         if ((DWORD)lParam == (DWORD)button )
  47.         {
  48.            
  49.             char  Dll[256]  ;
  50.             char  Proc[256]  ;
  51.             GetWindowTextA(TXT1,Dll,256);
  52.             GetWindowTextA(TXT2,Proc,256);
  53.             if (CreateFile(_bstr_t(Dll),0,0,0,OPEN_EXISTING,0,0)==0)
  54.             {
  55.                 MessageBoxA(0,"Dll Not Found","Error",MB_ICONWARNING);
  56.                 return 0;
  57.             }
  58.             Inject(Dll,Proc);
  59.         }
  60.     default:
  61.         return DefWindowProc(hwnd,msg,wParam,lParam);
  62.     }
  63.     return 0;
  64. }
  65. bool Inject(char* Dll ,char* Process)
  66. {
  67.     DWORD ProcID  = NULL;
  68.     //Get Torget Process ID
  69.     HANDLE  snap =CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  70.     PROCESSENTRY32 info;
  71.     info.dwSize = sizeof(PROCESSENTRY32);
  72.     bool a = Process32First(snap,&info);
  73.     while (a)
  74.     {
  75.         if (_bstr_t(info.szExeFile) == _bstr_t(Process))
  76.         {
  77.             ProcID = info.th32ProcessID;
  78.             goto Go;
  79.         }
  80.         a = Process32Next(snap,&info);
  81.     }
  82.     MessageBoxA(0,"Torget Process Not Found","Error",MB_ICONWARNING);
  83.     return 0;
  84. Go:
  85.     //Get LoadLibraryA Address :
  86.     LPVOID LoadLibraryAddres = GetProcAddress(GetModuleHandleA("kernel32"),"LoadLibraryA");
  87.     //Write Dll Path in Torget Process Memoiry :
  88.     HANDLE pro = OpenProcess(PROCESS_ALL_ACCESS,0,ProcID);
  89.     LPVOID Address = VirtualAllocEx(pro,0,strlen(Dll),MEM_COMMIT,PAGE_EXECUTE_READWRITE);
  90.     WriteProcessMemory(pro,Address,Dll,strlen(Dll),0);
  91.     //Create New Thread in Torget Process and Load Dll in it :
  92.     DWORD crea = (DWORD)CreateRemoteThread(pro,0,0,(LPTHREAD_START_ROUTINE)LoadLibraryAddres,Address,0,0);
  93.     if (crea == 0)
  94.     {
  95.         MessageBoxA(0,"Injecting Failed , May Your Process Envermment Not Compatibilite With Injector Envoremment .  ","Error",MB_ICONERROR);
  96.         return 0;
  97.     }
  98.     MessageBoxA(0,"Dll injected Sucessfully","Sucessfully",MB_ICONINFORMATION);
  99.     return 1;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement