Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write an RDP client that dumps the pixels of the screen

Tags:

c++

rdp

freerdp

I would like to implement a RDP client in C++ that is able to get the color value of all pixels of the screen and dump them to a file. I know this is conceptually different from how RDP works but I need it for my application. I am trying to make use of freerdp but I am not sure how can I efficiently write a client that simply dumps all pixels in a file.

So far my best attempt is making use of the function gdi_GetPixel_32bpp but of course calling this function for each pixel in turn is far from efficient.

A solution that makes use of another library will also be greatly appreciated.

like image 496
Ivaylo Strandjev Avatar asked Jan 03 '14 14:01

Ivaylo Strandjev


2 Answers

This should be fairly easy to do in a very efficient way using libfreerdp-gdi. FreeRDP can render everything to a software buffer which you can then dump to a file, and you can do this entirely in memory, without an X11 environment, if you wish. Since Linux is mentioned, one quick way to get started would be to use xfreerdp with the /gdi:sw option to make use of libfreerdp-gdi (the default is to use an X11-based implementation) and to then dump the pixels as updates come in. You can hook yourself in xf_sw_end_paint, which is called at the end of an array of updates. You have access to the invalid region and the pixel buffer (all under the rdpGdi* gdi structure). Important fields are gdi->primary_buffer, gdi->dstBpp, gdi->bytesPerPixel, gdi->width and gdi->height. In most cases you will get an XRGB32 buffer, which is easy to deal with. In doubt, take a look at gdi_init() for the initialization of the internal buffer.

like image 165
awakecoding Avatar answered Nov 15 '22 06:11

awakecoding


Well you could try to this (disclaimer untested pseudo code):

HGDI_DC memDC = gdi_CreateCompatibleDC ( hDC );
HGDI_BITMAP memBM = gdi_CreateCompatibleBitmap ( hDC, screenWidth, screenHeight );
gdi_SelectObject ( memDC, memBM );
gdi_BitBlt(memDC, 0, 0, screenWidth, screenHeight, hDC, 0, 0, GDI_SRCCOPY);

Now you should have in memBM->data the complete array of pixel data. memBM->data has the following size: memBM->width * memBM->height * memBM->bytesPerPixel

Hope that this helps you at least somewhat.

like image 37
Vinzenz Avatar answered Nov 15 '22 06:11

Vinzenz