• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
XTAL256

Code Injection vs. Calling remote DLL function

7 posts in this topic

For my app (Window Detective) i am using code injection to obtain information from other processes.
I am currently using two different methods:
1) DLL injection using hooks - SetWindowsHookEx(WH_CALLWNDPROC, ...). I use this to monitor messages sent to windows. Functions are defined in the DLL and called by the remote process (via Window's hook mechanism).
2) Code injection using CreateRemoteThread. I use this to extract information from within the remote process. I write a function which i then inject into the process.

I was wondering if i could use the first method for both cases. That is, can i call a function from my DLL that is loaded into a remote process? It would be a whole lot easier since i don't have to deal with all the caveats mentioned here.
0

Share this post


Link to post
Share on other sites
I could do what is done here. That is, the function that is injected using CreateRemoteThread gets the module handle of my DLL (assuming it is already loaded, by the hook method), get the proc address of a function in the DLL, then call that function.
Therefore the function is generic enough to call any DLL function that is passed to it - as long as that function does not take any parameters.

I don't suppose there is a better way.
0

Share this post


Link to post
Share on other sites
Can't you just define a structure with a function pointer, use CreateRemoteThread and use a pointer to that structure as the context param, then in your thread proc, cast to pointer to structure and then you have your function pointer?

Alternatively, if you wanted to be able to call a variety of functions, then pass the module handle in the structure instead of a function pointer. This is kind of what you said, except instead of the remote thread "getting the module handle" you're giving it to the remote thread at launch.
0

Share this post


Link to post
Share on other sites
I believe what you described is what i said in my second post (which is further described in the link). I don't think either one of us described the methods very well, perhaps a code snippet would help explain things...

The limitation of that method is that all remote functions need to have the same signature. I think they can have parameters (contrary to what i said earlier) so i will need to pass a struct containing the data the function needs (similar to a struct i would pass to CreateRemoteThread).
The advantage is that by defining the function in the DLL, i do not need to pass every function address, string and any other data to the remote function.

I will think about it and see if i can get that working.
0

Share this post


Link to post
Share on other sites
Jeffrey Richter's book Advanced Windows has a chapter in which he discusses all of this stuff. It's been a while so let me google ... yeah, according to the bibliography of this Dr. Dobb's article Chapter 18 of Advanced Windows is called "Breaking Through Process Boundary Walls"; this is the chapter I'm talking about.

I'm not sure Advanced Windows is still up to date, however. It apparently has a 4th edition now titled Programming Applications for Microsoft Windows but I don't know if the stuff about crossing process boundary walls is still included; I had the old book.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by jwezorek
Jeffrey Richter's book Advanced Windows has a chapter in which he discusses all of this stuff. It's been a while so let me google ... yeah, according to the bibliography of this Dr. Dobb's article Chapter 18 of Advanced Windows is called "Breaking Through Process Boundary Walls"; this is the chapter I'm talking about.

I'm not sure Advanced Windows is still up to date, however. It apparently has a 4th edition now titled Programming Applications for Microsoft Windows but I don't know if the stuff about crossing process boundary walls is still included; I had the old book.


BTW, the newest version of that book is called "Windows via C/C++". It's basically a complete re-write of the original, which is why the naming scheme was changed. Amazing book though, must read.
0

Share this post


Link to post
Share on other sites
fyi, i have got it working now. I basically pass a function name (char*) to the injected function, which in turn gets the module handle and function address then calls it. I also found a way to pass data to that function, albeit just a single struct parameter.
0

Share this post


Link to post
Share on other sites
I don't think i'm quite understanding your dilemma because I don't see why you cant call your function directly from your code... Why do you need to get the module address and then get a pointer to the function?

When you write a function hook, its solely supposed to be used for redirecting the execution of the remote process. Sending execution from the hook function to another function in your DLL should be as simple as calling it... This is for "static" injection though, where your DLL is added to the program before it is run. "Dynamic" injection is when the remote program gets injected while it is running, but even then I think it still is possible (though i've only worked with static injection before).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0