Results 1 to 4 of 4

Thread: A framework to take the tedium out of code-injection in C++

  1. #1

    A framework to take the tedium out of code-injection in C++


    I know I’ve been banging on about injection a lot recently, but I figured a good way to pinch off would be to present some code. After searching and failing, I took it upon myself to write a reusable C++ class to do most of the leg-work for Windows XP/2000/Vista32 DLL injection and hooking. The source is available on the project page.

    The process of remote function hooking via a DLL is notoriously messy, so I’ve tried to encapsulate as much of the mess as possible into a C++ class. Here’s an example of some client code that injects a DLL into Windows Calculator, then installs two hooks (one by name and another by address):

    Code:
    // Create the injection objectDLLInjection injection("E:/Temp/HookDLL.dll");
    // Find Calc.exe by its window
    DWORD process_id = injection.GetProcessIDFromWindow(    "SciCalc",    "Calculator");
    // Inject the DLL
    HMODULE remote_module = injection.InjectDLL(process_id);
    // Hook a DLL function
    (User32!SetWindowTextW)HDLLHOOK swtw_hook = injection.InstallDLLHook(    "C:/Windows/System32/User32.dll",    "SetWindowTextW",    "SetWindowTextHookW");
    // Hook a function manually
    (Calc!0100F3CF)HDLLHOOK manual_hook = injection.InstallCodeHook(    reinterpret_cast<void*> (00100F3CF),    “SomeOtherHook”);
    // Remove the hooks
    injection.RemoveHook(swtw_hook);
    injection.RemoveHook(manual_hook);
    Testing has been limited so don’t be surprised to find bugs. If you do find any, please report them via email or comment.



    http://www.ring3circus.com/gameprogramming/a-framework-to-take-the-tedium-out-of-code-injection-in-c/

  2. #2
    Administrator dELTA's Avatar
    Join Date
    Oct 2000
    Location
    Ring -1
    Posts
    4,206
    Blog Entries
    5
    Cool, nice work.
    "Give a man a quote from the FAQ, and he'll ignore it. Print the FAQ, shove it up his ass, kick him in the balls, DDoS his ass and kick/ban him, and the point usually gets through eventually."

  3. #3
    Interesting project. Should be useful to our readers as well!

    Regards,
    JMI

  4. #4
    Very interesting. After all, it's C++ Great...

Similar Threads

  1. code injection
    By Vigual in forum The Newbie Forum
    Replies: 7
    Last Post: February 16th, 2010, 23:32
  2. MUL code injection
    By Uridium in forum The Newbie Forum
    Replies: 1
    Last Post: October 8th, 2009, 02:09
  3. Trying out code injection and in need of help
    By fump in forum The Newbie Forum
    Replies: 3
    Last Post: June 17th, 2009, 22:28
  4. code injection problem
    By razzytaz in forum The Newbie Forum
    Replies: 3
    Last Post: September 19th, 2004, 19:15
  5. More on code injection
    By garph0 in forum Advanced Reversing and Programming
    Replies: 6
    Last Post: December 4th, 2000, 14:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •