- Zonehacks.com
- Forums
- Questions and Answers
- [Help] SetWindowsHookEx Dll Injection
Not logged in - Click here to login to your Account Welcome Guest!
|
[Help] SetWindowsHookEx Dll Injection
|
|
Author Info:
|
|
| iPromise Posted 10 months ago. Total XP: 257 |
Its not working, i'm testing it on notepad. What I do is do a global dll injection with my first temporary dll, this dll will go through all the hwnds through the WH_CBT hook and try to find my targets window title, and then if I found it I inject my second real dll and unhook my hook. This is my console: [code] using namespace std; void main() This is my Dll: [code] using namespace std; BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved) LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) return CallNextHookEx(0, nCode, wParam, lParam); Please help, this wont work, I keep clicking on Notepad when the dll is injected to try and get my WH_CBT callback to work. |
| boringwall Posted 10 months ago. Total XP: 84 |
Taking just a quick cursory glance at this code --
C-strings are not compared with the == operator. With Win32 using StrCmp - http://msdn.microsoft.com/en-us/library/bb759938%28VS.85%29.aspx would be the correct way to compare the two values.
If you're injecting a DLL with SetWindowsHookEx then your DLL will be in the address space of the process with the PID supplied as the dwThreadId (0 for all processes as you're trying to do) so there's no need to load an additional library. Also, you're trying to unhook a hook that doesn't exist. UnhookWindowsHookEx takes a HHOOK parameter that was obtained through calling SetWindowsHookEx -- what you're doing doesn't do anything and the function will always fail. Lastly, since you're intercepting the HCBT_ACTIVATE message, this code will also be executed each time you're about to activate a window. Since you're injecting this DLL into every process you'll be hitting this code a lot from lots of different address spaces.
On the next topic, when you do
GetProcAddress will always fail. This is because you're not exporting the CBTProc function in your DLL. Exporting functions from a DLL is done by using __declspec(dllexport) and/or a .def file. You can read about these things here -- http://msdn.microsoft.com/en-us/library/a90k134d%28VS.80%29.aspx and here http://msdn.microsoft.com/en-us/library/d91k01sh%28VS.80%29.aspx. Lastly, a more unknown issue would be the name mangling of your function. Even if you export the function it won't be exported as "CBTProc" but closer to something like "_CBTProc@12", @12 being for the arguments passed in (4 * 3). This is compiler dependent and others may export it differently depending on what you're using. This can be prevented by in combination with an exports definition file if your calling convention is __stdcall.
For example
With an Exports.def file containing
will export an unmangled version of the printMessage function. This can be verified quickly with testing
A few minor notes In your DLL:
You don't need this as you're not using any I/O routines. In your application:
The C and C++ standards both state that main should be one of
A successful return value is 0. Using two cin.get(); statements works equally well and doesn't rely on a system call. The SetWindowsHookEx method of DLL injection is pretty poor. Hooks in general are detected easily, but you're also injecting this into every process on the system. At the very least you can GetWindowThreadProcessId to obtain the PID for the window that you want to inject to (or CreateToolhelp32Snapshot -> Process32First -> (Process32Next in a loop) if the process has no windows). I'd first suggest actually learning C (or C++) before diving into the Windows API. Hopefully you'll read this and actually understand some of what was said and follow up on anything that wasn't made clear. I haven't actually compiled your code so there may be some more syntaxtical issues that I didn't spot but at least you're trying from the looks of it instead of blindly ripping off DLL injection code from somewhere. Last modified by boringwall on November 20, 2009, 1:45 am |
| iPromise Posted 10 months ago. Total XP: 257 |
I did make a .def file to export my functions, I also used StrCmp and it also didn't help.
|
| boringwall Posted 10 months ago. Total XP: 84 |
1. Check that the function is being exported, and if it is check to see that it's name is unmangled. 2. You've got an extra brace before your "if" expression 3. You're not checking the return of StrCmp properly. |
Not logged in - Click here to login to your Account
| Topic Title | Forum | Last post Info |
|---|---|---|
| Hackshield Bypass | Game Hacking | August 18, 2010, 1:44 am by iPromise |
| December 31, 1969, 5:00 pm by | ||
| Voobly notes | Reverse Engineering | November 21, 2009, 1:46 am by RANCID |
| SQL Injections | Questions and Answers | December 17, 2008, 6:24 pm by LumPY- |
| Hey guys! | Introduce Yourself | October 31, 2008, 9:09 pm by Specific |

