 |
[Source] InjectDLL function (ripped from my old MSBot src)
| C / C++ Discuss, [Source] InjectDLL function (ripped from my old MSBot src) at Programmers Lounge forum; So I was going through my GMail and I found the source to an old build of MSBot (0.1.4) that ... |
| Notices | Welcome to the Gamerz Needs forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |  | | 
08-08-2008, 07:06 AM
|  | T3H Team Pro Coder | | | Last Online: 10-22-2008 06:57 PM Join Date: Mar 2006 Location: Florida, USA Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6 Points: 7,440.46 Bank: 1,497.16 Total Points: 8,937.62 | | | [Source] InjectDLL function (ripped from my old MSBot src)
So I was going through my GMail and I found the source to an old build of MSBot (0.1.4) that I sent to TiMBuS. So here's some useful code from the injector, to get all you DLL injection kiddies going. Code: bool InjectDLL(DWORD dwPID, const char *szDLL)
{
HANDLE hProcess, hThread, hFile;
void* pLibRemote;
DWORD dwOldProtect;
DWORD dwExitCode;
hFile = CreateFile(szDLL, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return false;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
pLibRemote = VirtualAllocEx(hProcess, NULL, strlen(szDLL), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!VirtualProtectEx(hProcess, pLibRemote, strlen(szDLL), PAGE_EXECUTE_READWRITE, &dwOldProtect))
return false;
if (!WriteProcessMemory(hProcess, pLibRemote, (void*)szDLL, strlen(szDLL), 0))
return false;
VirtualProtectEx(hProcess, pLibRemote, strlen(szDLL), dwOldProtect, &dwOldProtect);
hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryA"), pLibRemote, 0, NULL);
if (hThread == NULL)
return false;
WaitForSingleObject(hThread, INFINITE);
GetExitCodeThread(hThread, &dwExitCode);
VirtualFreeEx(hProcess, pLibRemote, strlen(szDLL), MEM_RELEASE);
CloseHandle(hProcess);
CloseHandle(hThread);
return true;
}
Usage: Code: InjectDLL(dwProcessIDOfTargetProcess, "C:\mycode\mydll.dll");
Enjoy.
-d
Last edited by dveloper; 08-08-2008 at 07:22 AM..
Reason: Fixed a small typo.
| | The Following 4 Users Say Thank You to dveloper For This Useful Post: | | 
08-08-2008, 07:08 AM
|  | <span style="color: red;"><span style="color: red;">Mustache Mucho</span></span> | | | Last Online: Today 12:35 PM Join Date: Sep 2007 Location: 46°21′50.14″N, 15°3′28.69″E Age: 14
Posts: 1,385
Thanks: 123
Thanked 397 Times in 150 Posts
Nominated 8 Times in 6 Posts TOTW/F/M Award(s): 0
Latest Blog: My info
Rep Power: 7 Points: 10,365.10 Bank: 510,492.30 Total Points: 520,857.40 | | |
Wow! Nice! i'll try to make something outta that!
| 
08-08-2008, 07:14 AM
|  | T3H Team Pro Coder | | | Last Online: 10-22-2008 06:57 PM Join Date: Mar 2006 Location: Florida, USA Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6 Points: 7,440.46 Bank: 1,497.16 Total Points: 8,937.62 | | |
No problem, I'm looking through the source for some other gems. Stay tuned.
| 
08-08-2008, 08:05 AM
|  | Registered Users + | | | Last Online: Today 12:03 PM Join Date: Nov 2006 Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11 Points: 1,091.40 Bank: 110,398.61 Total Points: 111,490.01 | |
what does Alloc mean?
btw nice source, very useful! I might make it a DLL in C++ and use it for my Delphi thanks
__________________ Ha I'm back whatever | 
08-08-2008, 08:25 AM
|  | T3H Team Pro Coder | | | Last Online: 10-22-2008 06:57 PM Join Date: Mar 2006 Location: Florida, USA Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6 Points: 7,440.46 Bank: 1,497.16 Total Points: 8,937.62 | | |
Allocate. That line allocates memory in the target process to hold the DLL's filename.
| 
08-08-2008, 09:46 AM
|  | Registered Users + | | | Last Online: Today 12:03 PM Join Date: Nov 2006 Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11 Points: 1,091.40 Bank: 110,398.61 Total Points: 111,490.01 | | |
lul can you try to explain a word without it in the explaination xD
anyway, I'll go search it up
__________________ Ha I'm back whatever | 
08-08-2008, 10:52 AM
|  | Diamond Hole | | | Last Online: Today 04:40 PM Join Date: Jan 2007 Location: California
Posts: 756
Thanks: 144
Thanked 99 Times in 50 Posts
Nominated 6 Times in 3 Posts TOTW/F/M Award(s): 0
Latest Blog: blahh!!!
Rep Power: 6 Points: 1,600.90 Bank: 95,830.04 Total Points: 97,430.94 | |
would it still work if we took this out? Code: WaitForSingleObject(hThread, INFINITE);
GetExitCodeThread(hThread, &dwExitCode);
does that code make the program wait until the thread finished?
| 
08-08-2008, 04:37 PM
|  | Gunbound UnderGround Level 3 | | | Last Online: Today 02:00 AM Join Date: Aug 2005 Age: 20
Posts: 4,402
Thanks: 2
Thanked 8,568 Times in 794 Posts
Nominated 33 Times in 17 Posts  TOTW/F/M Award(s): 1
Latest Blog:
Rep Power: 23 Points: 41,574.96 Bank: 259,569.03 Total Points: 301,143.99 | | Quote:
Originally Posted by kaswar lul can you try to explain a word without it in the explaination xD
anyway, I'll go search it up | ...how can you not know what allocation means >.>
ok look, when a process is created, it takes up a certain amount of space in the memory of your computer. by allocating, you can "make" space within the space of that process for you to use for yourself. In this case, we are making space in that process so that we can write the path for the dll there. Next we are making more space which will be a thread that calls loadlibrary when it's created.
create remote thread is a very public injection method and doesn't work for all games - on rakion, gameguard hooks it and thus detects if its used.
__________________ Hacks of mine that you can get if you buy premium:- Gunz Multi Hack (IJJI)
- Wolfteam Multi Hack (WIS, WLS)
- Gunbound Multi Hack (GBNA, GIS, GBEU)
- Rakion Legit Hack (RIS, RLS, RSS)
So support GzN, buy premium, and start hacking today! | | The Following User Says Thank You to Sean For This Useful Post: | | 
08-08-2008, 11:38 PM
|  | T3H Team Pro Coder | | | Last Online: 10-22-2008 06:57 PM Join Date: Mar 2006 Location: Florida, USA Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6 Points: 7,440.46 Bank: 1,497.16 Total Points: 8,937.62 | | |
It all depends on when you inject, which is why I posted just the bare injection function. You can CreateProcess with CREATE_SUSPENDED if you like, inject, and then resume the process. I know there are multiple injection methods, this being the simplest.
| 
08-21-2008, 07:07 PM
|  | Registered Users + | | | Last Online: Today 12:03 PM Join Date: Nov 2006 Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11 Points: 1,091.40 Bank: 110,398.61 Total Points: 111,490.01 | | |
Can you create this in a DLL so i can call it with my Dephi?
__________________ Ha I'm back whatever
Last edited by kaswar; 08-23-2008 at 11:21 AM..
|  | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |