• 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
TheChubu

How do injectors work?

3 posts in this topic

Well, that's the question. How injectors like ENB work?

I've seen quite a few, the popular ENBSeries and a few injectors for Skyrim:

One that replaced some functions with ones optimized in ASM (later got ported to C and extended in Skyboost) Others that added scripting functionality, more graphical "enhancers" like FXAA Injector, SMAA Injector, etc.

The only thing I can think of is to track where exe is allocated in memory and do some hackery to point to another subrutine that contains the code to be injected. It sounds awfully low level though (ie, manipulating actual ram adresses and machine code stored in ram).
0

Share this post


Link to post
Share on other sites
If I understand correctly what ENB injector does, it's only just injecting a DLL (some kind of D9D wrapper?) into another process' address space.

That can be done rather easily, for example by installing a global hook procedure (from which you load that DLL) or using [font=courier new,courier,monospace]CreateRemoteThread[/font] or simply by either setting the AppInit_DLLs key in the registry or by placing a wrapper DLL into the executable's directory.

All that assumes proper access rights of course, but this is usually the case, given that you own, and have physical access to your computer. Reading and writing another process' memory as you've suggested in your last paragraph is of course possible too, if you have proper access right (running a mini-debugger is a certain way of having rights). Oh, speaking of mini-debugger... a debugger is notified of every DLL being loaded or unloaded. You can probably use that to trivially exchange (or inject) DLLs too.

Now of course, doing it and doing it without triggering an anti-exploit mechanism may be slightly different things (you have to assume that the developers of a game title are not complete idiots and know all the obvious tricks too). Also, doing it and doing it without breaking the law are again different things.
1

Share this post


Link to post
Share on other sites
[url="http://www.gamedev.net/topic/582251-code-injection-vs-calling-remote-dll-function/"]See this old thread for more discussion.[/url]
1

Share this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1355923316' post='5012426']
If I understand correctly what ENB injector does, it's only just injecting a DLL (some kind of D9D wrapper?) into another process' address space.[/quote]Boris differentiates between both in its files. It has an "Injector version" and a "Wrapper version"

Originally, it had a d3d9.dll that got loaded by the game, probably because it has the same name as the actual Windows library. That means that the game would load the "fake" d3d9.dll and then that dll would call the proper library?

[quote name='samoth' timestamp='1355923316' post='5012426']That can be done rather easily, for example by installing a global hook procedure (from which you load that DLL) or using [font=courier new,courier,monospace]CreateRemoteThread[/font] or simply by either setting the AppInit_DLLs key in the registry or by placing a wrapper DLL into the executable's directory.[/quote]So, with those methods one could load a dll, but how that dll would interact with the process? Can the dll call functions in the .exe?

[quote name='samoth' timestamp='1355923316' post='5012426']All that assumes proper access rights of course, but this is usually the case, given that you own, and have physical access to your computer. Reading and writing another process' memory as you've suggested in your last paragraph is of course possible too, if you have proper access right (running a mini-debugger is a certain way of having rights). Oh, speaking of mini-debugger... a debugger is notified of every DLL being loaded or unloaded. You can probably use that to trivially exchange (or inject) DLLs too.[/quote]Interesting. The debugger would need to be compiled into the exe or its just another dll that can be injected?

[quote name='samoth' timestamp='1355923316' post='5012426']Now of course, doing it and doing it without triggering an anti-exploit mechanism may be slightly different things (you have to assume that the developers of a game title are not complete idiots and know all the obvious tricks too). Also, doing it and doing it without breaking the law are again different things.[/quote]Of course, dealing with copy protection and all that.

In particular what made me curious is the Skyboost project. It goes like this: Skyrim for PC's executable code was compiled pretty much without optimization flags, thus some very critical code wasn't taking advantage of compiler optimizations neither modern instruction sets (ie, SSE2) and the game was severely CPU limited.

So, this guy comes ahead with a profiler, catches up the issue and codes in ASM a replacement for some critical functions in Skyrim's exe and calls it "TESVAL". Massive performance improvements ensue (ie, +20% to +40% perf increase) but with a big big drawback, the injector had to be updated every time Skyrim was updated (in contrast with other injector i've seen, probably because this one replaced .exe code instead of adding functions).

Since TESVAL author didn't had enough time, Alexander Blade (pretty experienced guy from what i've seen) picks up the project, ports it to C, calls it "Skyboost" and starts experimenting with more optimizations. After a few updates Bethesda updated Skyrim with a properly compiled exe and the patch was made irrelevant.
[quote name='jwezorek' timestamp='1355960206' post='5012633']
See this old thread for more discussion.
[/quote]Thanks! I'll check the links mentioned on that thread. Edited by TheChubu
0

Share this post


Link to post
Share on other sites
[quote]Originally, it had a d3d9.dll that got loaded by the game, probably because it has the same name as the actual Windows library. That means that the game would load the "fake" d3d9.dll and then that dll would call the proper library?[/quote]Yes, something like that. That's a typical wrapper.
[quote]So, with those methods one could load a dll, but how that dll would interact with the process? Can the dll call functions in the .exe?[/quote]Yes and no. A DLL as such does not call functions in a program, it is just a PE image that is loaded into the address space of a process. However, a [i]thread [/i]running the executable code in a DLL could certainly call functions in the program, presumed that you are able to determine the function's address and know what it does (and what parameter it takes, etc.).

Usually, it works the other way around. Normally, the injected DLL replaces some original functionality, and it's a thread from the original process that calls (without realizing) a function in the DLL.
[quote]The debugger would need to be compiled into the exe or its just another dll that can be injected?[/quote]A small program using [tt]CreateProcess[/tt], [tt]DebugActiveProcess[/tt], and [tt]WaitForDebugEvent[/tt] to launch the "real" program.
Of course most non-trivial titles will take more or less sophisticated anti-debugger measures.

Also, note that you are [i]almost certainly[/i] breaking the EULA (read as: using a good without permission, thus becoming a criminal in most countries) with that.

[quote]So, this guy comes ahead with a profiler, catches up the issue and codes in ASM a replacement for some critical functions in Skyrim's exe[/quote]That's all nice and good, but it's almost certainly a breach of EULA. Most probably nobody will care, but in the worst case that guy could find himself in a $50M tortious interference lawsuit.

It is highly unlikely that Skyrim for PC shipped as a debug build. The likely reason why the developers of Skyrim didn't do the same optimizations in the first place (you have to assume they're not complete idiots either!) is that performance was deemed "good enough" on the targeted hardware and that spending extra time on optimizing (and delaying the product) was therefore economically not viable.
Two years ago, one might have added "or maybe they didn't want to depend on SSE2 or have an extra code path", but this is unlikely now, seeing how no modern version of Windows works without SSE2 at all anyway. Edited by samoth
1

Share this post


Link to post
Share on other sites

 

Quoting isn't working well it seems...

 

Well. It actually appeared on the official Bethesda forums, and script extenders have been the norm for TES titles since long ago. No one complained about it. Beth is fairly lenient on that respect, as long as you're not porting content from their games (ie, Morrowind content to Skyrim) or porting content from their DLCs its all good.

 

That said, I'm inclined to believe the guys who made the injector since they seem to know a fair bit about the subject and they think it was just that some flags in the compiler hadn't been set up properly. And believe me, if a 2500K overclocked to 4Ghz was "good enough performance" for Beth developers, that doesn't speaks good of them either.

 

Even so, since part of the game did use SSE2, it didn't worked on old processors anyway. So it is likely, believe it or not, that someone screwed it up in the build process. Maybe some incremental compilation issue or something like that. You must assume they're humans too, it can happen.

 

Anyway, thanks a lot for the info. Now I'm out to break some EULAs! Nah I'm joking tongue.png I'm still pretty clueless about C++, Windows API, threading and such. And I don't think there is a game out there that could benefit of my limited 8085 assembler knowledge anyway biggrin.png

Edited by TheChubu
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