简体   繁体   English

从OpenGL应用程序中提取颜色/深度缓冲区

[英]Extract color/depth buffer from OpenGL applications

I was thinking about a project for quiet a while that would require the extraction of the color and depth buffer from OpenGL applications, in particular games. 我在考虑一个安静的项目,这需要从OpenGL应用程序(尤其是游戏)中提取颜色和深度缓冲区。 It has absolutely nothing to do with modding, in terms of manipulating the game itself or is intended for "cheating" purposes but more just for data gathering. 从操纵游戏本身或旨在“作弊”的目的而言,它与修改毫无关系,而仅仅是为了收集数据。

So now I'm trying to figure out possible ways to accomplish it. 因此,现在我正在尝试找出实现此目标的可能方法。 Of course being able to do it with Direct3D under Windows would even lead to more available applications but as I'm pretty familar with OpenGL under Linux, I would start this way. 当然,在Windows下使用Direct3D能够做到这一点甚至会导致更多可用的应用程序,但是由于我对Linux下的OpenGL非常熟悉,因此我将以这种方式开始。

As there are many modding/cheating applications that actually manipulate the color/depth buffer of video games in different kinds (eg wallhacks in ego shooters), it seems that this definitely has to be possible somehow. 由于实际上有许多改装/作弊应用程序可以操纵视频游戏的不同颜色/深度缓冲区(例如,自我射击游戏中的墙面骇客),因此看来这肯定是有可能的。

Now the question is, what would be the best way to accomplish this? 现在的问题是,实现这一目标的最佳方法是什么? Reading out the GPU memory directly would most probably not work according to this thread as memory mapping in OpenGL is completely dependent on vendor implementation and there is no trivial way to get the VRAM addresses of the corresponding data. 根据该线程 ,直接读取GPU内存很可能无法正常工作因为OpenGL中的内存映射完全取决于供应商的实现,并且没有简单的方法来获取相应数据的VRAM地址。

Alternative approaches I can think of might now be categorized as extravenous or intravenous ones: 我可以想到的替代方法现在可以归类为静脉内或静脉内:

  • Extravenous : extract the OpenGL context from a process and access buffers, shaders, etc. from a third application without really manipulating the target applications binary directly. Extravenous :从进程中提取OpenGL上下文并从第三个应用程序访问缓冲区,着色器等,而无需真正地直接操作目标应用程序二进制文件。
  • Intravenous : manipulate the target applications binary/code in such a way, that it writes the correspondings buffers/data either to a specific place in the memory or directly saves it somewhere. 静脉注射 :以这种方式操作目标应用程序的二进制/代码 ,即将相应的缓冲区/数据写入内存中的特定位置或直接将其保存在某个位置。

Latter approach should definitely work, but might be associated with a larger effort and would need to be done per application. 后一种方法肯定可以工作,但是可能需要付出更大的努力,并且需要针对每个应用程序进行。 Hence first would be definitely preferred, but is the described way even applicable at all? 因此,首先肯定是首选,但是所描述的方法是否完全适用? Is it just possible to access OpenGL ressources from different processes when you have the OpenGL context value of another? 当您拥有另一个OpenGL上下文值时,是否可以从不同进程访问OpenGL资源? Does anyone has experience with this? 有人对此有经验吗?

Update: 更新:

After some research I found out that what I was looking for is pretty common and called " Hooking " or "Interception" in general. 经过一番研究,我发现我要找的东西很普通,通常被称为“ 挂钩 ”或“拦截”。

For OpenGL and Direct3D there are many different libraries and programs to do this: 对于OpenGL和Direct3D,有许多不同的库和程序可以做到这一点:

and many others. 还有很多其他

The de facto standard way of doing this would be to hook yourself into the process and redirect the graphics API calls the application (game) makes to your own code. 这样做的事实上的标准方法是将您自己吸引到过程中,并将应用程序(游戏)进行的图形API调用重定向到您自己的代码。 Your hook can then record whatever data it needs and perform whatever action it wants before passing on the call to the actual API implementation. 然后,您的钩子可以记录所需的任何数据,并在将调用传递给实际的API实现之前执行所需的任何操作。 There are many ways of doing this with different pros and cons, ranging from building a fake library with the same interface and tricking the game into loading that one instead of the actual graphics library ( DLL injection ) to modifying the machine code in the loaded process image to make function calls jump into your code. 这样做有很多利弊,从建立具有相同接口的伪造库并欺骗游戏以加载该库而不是实际的图形库( DLL注入 ),到在加载的过程中修改机器代码。进行函数调用的图像跳入您的代码。 Which approaches are applicable and best for your case will highly depend on many factors such as target platform, target applications, the API you want to hook into, and so on. 哪种方法适用和最适合您的情况将在很大程度上取决于许多因素,例如目标平台,目标应用程序,您希望使用的API等。

The main issue with any such approach, however, is that that's exactly how many cheats work. 但是,任何这种方法的主要问题在于,这实际上是多少作弊方法。 Thus, many video games will come with built-in protection to prevent precisely this kind of stuff from working. 因此,许多视频游戏都将带有内置保护功能,以防止此类事情的发生。 With many online games, you might even risk having your account suspended for suspected cheating by trying to do stuff like this. 在许多在线游戏中,您甚至可能尝试进行此类操作,从而冒着涉嫌作弊行为而被暂停帐户的风险。 But that's just something to be aware of. 但这只是要注意的事情。 In my experience, it will still work with many games, particularly single-player games. 以我的经验,它仍可用于许多游戏,尤其是单人游戏。

"Extracting the OpenGL context from another process" will not work, at least not on any proper operating system. “从另一个进程中提取OpenGL上下文”将不起作用,至少在任何适当的操作系统上均不起作用。 The whole point of having the process abstraction in the first place is to isolate applications from each other… 首先,将流程抽象的全部目的是将应用程序彼此隔离开...

Since I don't have enough reputation to ask this in a comment, let me ask you here what exactly your goal is. 由于我没有足够的声誉在评论中提出这个问题,因此在这里让我问您您的确切目标是什么。 Do you want to get this information once for a single frame or do you want to record this for many frames over a period of time? 您是否想在一帧中获取一次此信息,还是要在一段时间内记录多帧? Do you need an automated solution in form of a custom application? 您是否需要定制应用程序形式的自动化解决方案? If neither of those, you might be able to just use a graphics debugging tool like Nsight Graphics to capture and export the frame you want… 如果两者都不行,您也许可以仅使用Nsight Graphics之类的图形调试工具来捕获和导出所需的帧…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM