 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 25, 2008 12:26 pm Post subject: injection keeps failing |
|
|
In my dll injector it can't inject anything. I tried making a simple apihook.dll using ferocious's tutorial. I then made a test application where it would call MessageBoxA and the dll would hook it. But I can't inject anything...
Here's my source code for my inject button, the function it calls, and the injection code.
| Code: |
case IDC_INJECT_BUTTON: {
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_DLLPATH_EDIT));
if(len > 0) {
if(GetIndexNameAndInject()) {
MessageBox(NULL, "Injection successful!", "Success", MB_OK);
}
else {
MessageBox(NULL, "Injection failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
}
|
| Code: |
BOOL GetIndexNameAndInject() {
bool success = false;
char ExeFile[255];
int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
if(index != LB_ERR) {
SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)ExeFile);
success = InjectDLL(ExeFile, path);
}
return success;
}
|
| Code: |
#include <windows.h>
#include <Tlhelp32.h>
BOOL InjectDLL(char *ExeFile, char *dllname) {
LPVOID RemoteAddress;
HANDLE hProcess, hThread;
SIZE_T size, ByteSizeRet;
bool Inject = FALSE;
size = strlen(dllname);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
MODULEENTRY32 me32;
me32.dwSize = sizeof(MODULEENTRY32);
Module32First(hSnapshot, &me32);
do {
if(strcmp(me32.szExePath, ExeFile) == 0) {
hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, me32.th32ProcessID);
CloseHandle(hSnapshot);
}
} while(Module32Next(hSnapshot, &me32));
RemoteAddress = VirtualAllocEx(hProcess, NULL, size, MEM_COMMIT, PAGE_READWRITE);
if(RemoteAddress != NULL) {
if(WriteProcessMemory(hProcess, RemoteAddress, (LPVOID)dllname, size, &ByteSizeRet)) {
if(CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "LoadLibraryA"), RemoteAddress, 0, (LPDWORD)hThread)) {
if(WaitForSingleObject(hThread, INFINITE) != WAIT_FAILED) {
LPDWORD exitcode;
if(GetExitCodeThread(hThread, exitcode)) {
Inject = (exitcode == NULL) ? FALSE : TRUE;
}
CloseHandle(hThread);
}
}
VirtualFreeEx(hProcess, RemoteAddress, size, MEM_DECOMMIT);
}
return Inject;
}
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 25, 2008 3:15 pm Post subject: |
|
|
| Quote: |
InjectDLL failed with error code 87: parameter was incorrect
|
But I'm confused now because both of my parameters had the right values passed to.
| Code: |
BOOL InjectDLL(char *ExeFile, char *dllname)
|
| Code: |
char path[MAX_PATH];
|
| Code: |
InjectDLL(ExeFile, path);
|
I mean the parameters are right. What's going on.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 25, 2008 3:38 pm Post subject: |
|
|
Here
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon May 26, 2008 1:01 am Post subject: |
|
|
| Code: |
do {
if(strcmp(me32.szExePath, ExeFile) == 0) {
hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, me32.th32ProcessID);
CloseHandle(hSnapshot);
}
} while(Module32Next(hSnapshot, &me32));
RemoteAddress = VirtualAllocEx(hProcess, NULL, size, MEM_COMMIT, PAGE_READWRITE);
[...]
|
A little thing I noticed. What if the process doesn't exist for some reason. If the do-while loop doesn't find a process, there's no 'error check' or something, and it'll go on and it would try to inject it into nothing.
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Mon May 26, 2008 2:39 am Post subject: |
|
|
My bad...Not sure, looking over your source.
OK, no.1 is you have variable "path" declared twice, remove the one that isn't global.
|
|
| Back to top |
|
 |
Ferocious Advanced Cheater
Reputation: 0
Joined: 06 Feb 2008 Posts: 54
|
Posted: Mon May 26, 2008 8:18 am Post subject: |
|
|
also, you don't write your function in your header files.
_________________
I wanna hack, but I don't know how... |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 8:51 am Post subject: |
|
|
New error. Apparently I have an invalid handle value or something like that. The debugger in VC++ is saying that hProcess is being used without being initialized.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon May 26, 2008 9:01 am Post subject: |
|
|
um... just a little guess but ur using CreateToolhelp32Snapshot with the dwFlag "TH32CS_SNAPPROCESS" when your using Module32First and Next...
so try changing it to PROCESSENTRY32 instead of MODULEENTRY32 and use Process32First and Next
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 9:08 am Post subject: |
|
|
Woah you're right. I can't believe I was using modules. I must have been blanking for a second. Thanks. My handle is still invalid though
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon May 26, 2008 9:09 am Post subject: |
|
|
You are probably getting handle issues because of PROCESS_ALL_ACCESS. Try using a variation of the bits instead of the full access flag.
For example, instead of using PROCESS_ALL_ACCESS, try using PROCESS_QUERY_INFORMATION|PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE instead.
Or, follow what the MSDN documentation says:
http://msdn.microsoft.com/en-us/library/ms684320(VS.85).aspx
To open a handle to another local process and obtain full access rights, you must enable the SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.
_________________
- Retired. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 9:30 am Post subject: |
|
|
So I would do this.
| Code: |
hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, NULL, pe32.th32ProcessID);
|
Edit:
Now it's complaining that hThread is being used without being initialized.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon May 26, 2008 9:39 am Post subject: |
|
|
Then initialize it.
| Code: | | HANDLE hThread = NULL; |
_________________
- Retired. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 9:42 am Post subject: |
|
|
I had tried that before with hProcess but it didn't work so I didn't bother with hThread, but I'll try. Yea it didn't work.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon May 26, 2008 9:49 am Post subject: |
|
|
| oib111 wrote: | | I had tried that before with hProcess but it didn't work so I didn't bother with hThread, but I'll try. Yea it didn't work. |
Paste the code it errors at.
_________________
- Retired. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 9:53 am Post subject: |
|
|
| Code: |
if(CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "LoadLibraryA"), RemoteAddress, 0, (LPDWORD)hThread)) {
|
| Quote: |
+ &ByteSizeRet 0x0013f64c unsigned long *
RemoteAddress 0x00990000 void *
+ dllname 0x00418150 "C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\apihook\Release\apihook.dll" char *
hProcess 0x00000dc4 void *
hThread 0xcccccccc void *
size 98 unsigned long
|
| Quote: |
'Dll Injector.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\Dll Injector\Debug\Dll Injector.exe', Symbols loaded.
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
'Dll Injector.exe': Loaded 'D:\WINDOWS\BricoPacks\Vista Inspirat 2\RocketDock\RocketDock.dll', Binary was not built with debug information.
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\psapi.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
'Dll Injector.exe': Loaded 'C:\Program Files\Seekmo\bin\10.0.406.0\HostOE.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\version.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\clbcatq.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\comres.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'Dll Injector.exe': Loaded 'D:\Program Files\Microsoft Office\Office12\GrooveShellExtensions.dll'
'Dll Injector.exe': Loaded 'D:\Program Files\Microsoft Office\Office12\GrooveUtil.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\wininet.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\normaliz.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\iertutil.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll'
'Dll Injector.exe': Loaded 'D:\Program Files\Microsoft Office\Office12\GrooveNew.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.ATL_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_6e805841\ATL80.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msimg32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\cscui.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\cscdll.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\cscui.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\cscdll.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\browseui.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\userenv.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\ntshrui.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\atl.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\netapi32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shdocvw.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\cryptui.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\wldap32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\riched20.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\riched20.dll'
'Dll Injector.exe': Loaded 'D:\Program Files\Microsoft Office\Office12\GrooveSystemServices.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\urlmon.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msxml3.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\browseui.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\shdocvw.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\cryptui.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\wldap32.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\wintrust.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\imagehlp.dll'
'Dll Injector.exe': Unloaded 'D:\Program Files\Microsoft Office\Office12\GrooveSystemServices.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\urlmon.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\msxml3.dll'
Run-Time Check Failure #3 - The variable 'hThread' is being used without being initialized.
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
Last edited by oib111 on Mon May 26, 2008 9:57 am; edited 1 time in total |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|