简体   繁体   English

使用python 2.7进行劫持,重定向和显示输出

[英]Hijacking, redirecting, display output with Python 2.7

I am a new programmer with little experience but I am in the process of learning Python 2.7. 我是一位经验不足的新程序员,但我正在学习Python 2.7。 I use Python(x,y) or Spydar as the programs are called on Windows 7. 我使用Python(x,y)或Spydar,因为在Windows 7上调用了程序。

The main packages I'm using are numpy , pil and potentially win32gui . 我使用的主要软件包是numpypil和可能的win32gui

I am currently trying to write a program to mine information from a 3rd-party software. 我目前正在尝试编写一个程序来从第三方软件中挖掘信息。 This is against their wishes and they have made it difficult. 这违背了他们的意愿,使他们感到困难。 I'm using ImageGrab and then numpy to get some results. 我正在使用ImageGrab ,然后使用numpy获得一些结果。 This however, or so i belive, forces me to keep the window I want to read in focus, which is not optimal. 但是,这大概让我相信,这迫使我将要阅读的窗口保持在焦点上,这不是最佳选择。

I'm wondering if there is any way to hijack the whole window and redirect the output directly into a "virtual" copy, just so I can have it running in the background? 我想知道是否有任何方法可以劫持整个窗口并将输出直接重定向到“虚拟”副本,以便让它在后台运行?

When looking at the demos for win32api , there is a script called desktopmanager . 查看win32api的演示时,有一个名为desktopmanager的脚本。 I never got it to work, probably since I'm running Windows 7, that's supposed to create new desktops. 我从来没有运行过它,大概是因为我正在运行Windows 7,所以应该创建新的桌面。 I don't really know how multiple desktops work but if they run in parallel, there may be a way to create a new desktop around a current window. 我真的不知道多个桌面如何工作,但是如果它们并行运行,则可能存在一种在当前窗口周围创建新桌面的方法。 I don't know how, it's just a thought so far. 我不知道如何,到目前为止只是一个想法。

The reason it's not working for me is not that it's not creating a new desktop, it's that once it's been created, I can't return from it. 它对我不起作用的原因不是不是在创建新的桌面,而是一旦创建了它,我就无法从它返回。 The taskbar icon nor the taskbar itself ever appears. 任务栏图标或任务栏本身都不会出现。

One approach that might work would be to do something like so: 一种可行的方法是执行以下操作:

  • get the window handle (FindWindow() or something similar, there are a few ways to do this) 获取窗口句柄(FindWindow()或类似的东西,有几种方法可以做到这一点)
  • get the window dimensions (GetClientRect() or GetWindowRect()) 获取窗口尺寸(GetClientRect()或GetWindowRect())
  • get the device context for the window (GetWindowDC()) 获取窗口的设备上下文(GetWindowDC())
  • get the image data from the window (BitBlt() or similar) 从窗口获取图像数据(BitBlt()或类似图像)

It is possible that you will need elevated privelages to access another processes window dc, if so you may need to inject code/dll into the target process space to do this. 可能需要提升特权才能访问另一个进程窗口dc,如果这样做,则可能需要将代码/ dll注入目标进程空间中才能执行此操作。

HTH. HTH。

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

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