Author Topic: my program and an online program  (Read 469 times)

shankle

  • Member
  • ****
  • Posts: 754
my program and an online program
« on: August 14, 2017, 09:53:18 AM »
             
          8-13-2017

I want to call an online program(B) from my program(A) and pass
some data from the online program(B) to my program(A) repeatedly.

Been trying this for months and getting nowhere. Yes I know 3rd
party programs can capture the data and pass it to the clipboard
but this is way to slow for the process I need to do. As an example
Fastcapture does this very nice but it is way to slow.

What my program(A) needs to do is call the online program(B) and
capture a small rectangle from program(B) and pass that data back
to my program(A) many times.

Since other programs can capture data from an online program screen,
there must be a way to do it in GoAsm. Tried dozens of ways to do it
with bitblt but none work.
Thanks for any suggestions.
          

Yuri

  • Member
  • **
  • Posts: 155
Re: my program and an online program
« Reply #1 on: August 15, 2017, 11:19:06 PM »
Look at this function, for example. It takes the window handle, the (client area) coordinates, width and height of the rectangle and returns in EAX a pointer to a buffer containing in each DWORD the color of a pixel in BGR format: the low byte is for blue, the next for green, the third for red. The fourth byte is probably not guaranteed to always contain 0, so it's better to mask it somehow.

If the function fails, it sets the carry flag and returns an error code in EAX.

The buffer is allocated each time the function is called, which is not an optimal solution, of course.

Code: [Select]
captureRect: FRAME hWnd, x, y, w, h
             USES rbx,rdi,rsi
             LOCALS bih:BITMAPINFOHEADER, pBmp, err

    lea rdi,[bih]
    mov ecx,sizeof BITMAPINFOHEADER / 4
    xor eax,eax
    mov [err],rax
    rep stosd
    invoke GetDC, [hWnd]
    mov rsi,rax
    test rax,rax
    jnz >
        mov D[err],1
        jmp >>.error
    :
    invoke CreateCompatibleDC, rsi
    mov rdi,rax
    test rax,rax
    jnz >
        mov D[err],2
        jmp >>.error
    :
    invoke CreateCompatibleBitmap, rsi, [w], [h]
    mov rbx,rax
    test rax,rax
    jnz >
        mov D[err],3
        jmp >>.error
    :
    invoke SelectObject, rdi, rbx
    test rax,rax
    jnz >
        mov D[err],4
        jmp >>.error
    :
    invoke BitBlt, rdi, 0, 0, [w], [h], rsi, [x], [y], SRCCOPY
    test eax,eax
    jnz >
        mov D[err],5
        jmp >>.error
    :
    mov eax,[w]
    shl eax,2
    mul D[h]
    invoke GlobalAlloc, GMEM_ZEROINIT, rax
    mov [pBmp],rax
    mov D[bih.biSize],sizeof BITMAPINFOHEADER
    mov edx,[w]
    mov ecx,[h]
    neg ecx
    mov [bih.biWidth],edx
    mov [bih.biHeight],ecx
    neg ecx
    mov W[bih.biPlanes],1
    mov W[bih.biBitCount],32
    mov D[bih.biCompression],BI_RGB
    invoke GetDIBits, rdi, rbx, 0, ecx, [pBmp], addr bih, DIB_RGB_COLORS
    test eax,eax
    jnz >
        mov D[err],6
        jmp >>.error
    :
    invoke DeleteDC, rdi
    invoke DeleteObject, rbx
    invoke ReleaseDC, [hWnd], rsi
    mov rax,[pBmp]
    clc
.exit
    ret
.error
    cmp D[err],6
    jb >
        invoke GlobalFree, [pBmp]
    :
    cmp D[err],4
    jb >
        invoke DeleteObject, rbx
    :
    cmp D[err],3
    jb >
        invoke DeleteDC, rdi
    :
    cmp D[err],2
    jb >
        invoke ReleaseDC, [hWnd], rsi
    :
    mov eax,[err]
    stc
    jmp .exit

ENDF
« Last Edit: August 16, 2017, 02:39:16 PM by Yuri »

Yuri

  • Member
  • **
  • Posts: 155
Re: my program and an online program
« Reply #2 on: August 16, 2017, 02:43:27 PM »
Added another "neg ecx" to make the height positive again for GetDIBits. It seemed to work OK without that, though.

shankle

  • Member
  • ****
  • Posts: 754
Re: my program and an online program
« Reply #3 on: August 16, 2017, 08:42:28 PM »
Thank you Yuri for responding.
It is not exactly what I want to do but I will use it as a guide.

HSE

  • Member
  • ****
  • Posts: 553
  • <AMD>< 7-32>
Re: my program and an online program
« Reply #4 on: August 18, 2017, 12:03:44 AM »
It's what I was searching last week (what a coincidence!). There is very few examples of GetDIBits, and my translation to assembly was failing  8) (or those example were incorrect, or even win32 help is wrong).

Thank you Yuri!  :t


Yuri

  • Member
  • **
  • Posts: 155
Re: my program and an online program
« Reply #5 on: August 18, 2017, 01:43:55 AM »
You are welcome. :icon_cool:

shankle

  • Member
  • ****
  • Posts: 754
Re: my program and an online program
« Reply #6 on: September 29, 2017, 12:26:20 AM »
                9-28-2017

    This message is intended for Yuri.
    If you would be so kind as to give your comments please.
    Two programs are involved here. 1. my program 2. an online program
    My program retrieves a small portion of the online program screen.
    Two bytes of rax are cleared. How do the other 2 bytes get created?
    This code compiled clean and is to be executed 12 times.
    The changes I have made to your code have comments after them.
   

    FRAME  hdc,iMsg,wParam,lParam,hPen,hWnd2,hWnd,xx,yy,ww,hh
    uses rbx,rdi,rsi
    LOCAL  ps:PAINTSTRUCT,pt:POINT,RR:RECT,rrrect:RECT
    LOCAL  bih:BITMAPINFOHEADER,pBmp,err


   lea rdi,[bih]
   mov ecx,sizeof BITMAPINFOHEADER / 4
   xor eax,eax
   mov [err],rax     ; how did the other 2 bytes of rax get loaded
   rep stosd
   invoke GetDC, NULL    ; this should get the handle of the online program
                                    ; which is unknown to me
   mov rsi,rax
   test rax,rax
    jnz >
     mov d[err],1
     jmp >>.error
:
     mov [hWnd2],rax   ; put online program handle info in this field
     invoke CreateCompatibleDC,rsi
     mov rdi,rax
     test rax,rax
      jnz >
   mov d[err],2
   jmp >>.error
:
     invoke CreateCompatibleBitmap, rsi,[ww],[hh]
     mov rbx,rax
     test rax,rax
      jnz >
    mov d[err],3
    jmp >>.error
:
     invoke SelectObject,rdi,rbx
     test rax,rax
       jnz >
         mov d[err],4
    jmp >>.error
:
     invoke BitBlt, [hWnd],0,0,[ww],[hh],rsi,[xx],[yy],SRCCOPY
                        ; hWnd is the handle to my program
     test eax,eax 
       jnz >
    mov d[err],5
    jmp >>.error
:
     invoke GlobalAlloc, GMEM_ZEROINIT,rax
     mov [pBmp],rax
     mov d[bih.biSize],sizeof BITMAPINFOHEADER
     mov edx,[ww]
     mov ecx,[hh]
     neg ecx
     mov [bih.biWidth],edx
     mov [bih.biHeight],ecx
     neg ecx
     mov w[bih.biPlanes],1
     mov w[bih.biBitCount],32
     mov d[bih.biCompression],BI_RGB
     invoke GetDIBits,rdi,rbx,0,ecx,[pBmp],addr bih,DIB_RGB_COLORS
     test eax,eax
       jnz >
    mov d[err],6
    jmp >>.error
:
     invoke DeleteDC, rdi
     invoke DeleteObject,rbx
     invoke ReleaseDC,[hWnd2],rsi   ; handle to the online program
     mov rax,[pBmp]
     clc
.exit            ; not necessary - more code to execute
    ret          ; this code has to be executed 12 times
.error
     cmp d[err],6
       jb >
      invoke GlobalFree,[pBmp]
:
     cmp d[err],4
        jb >
     invoke DeleteObject,rbx
:
     cmp d[err],3
   jb >
      invoke DeleteDC,rdi
:
     cmp d[err],2
   jb >
     invoke ReleaseDC,[hWnd2],rsi
:
     mov eax,[err]
     stc
     jmp .exit     ;this should fall through for more processing


Yuri

  • Member
  • **
  • Posts: 155
Re: my program and an online program
« Reply #7 on: September 29, 2017, 01:36:42 AM »
Actually, four bytes of RAX are cleared. The other four bytes are cleared by the processor automatically.

I don't quite understand the changes you made.

Code: [Select]
mov [hWnd2],rax   ; put online program handle info in this field
What is the point of doing this? hWnd2 is a parameter of your function.

Code: [Select]
invoke BitBlt, [hWnd],0,0,[ww],[hh],rsi,[xx],[yy],SRCCOPY
                        ; hWnd is the handle to my program
What is a handle to a program? The first argument should be a handle to a compatible DC that was created earlier and stored in RDI. It's a memory DC and doesn't belong to any window.

Code: [Select]
invoke GlobalAlloc, GMEM_ZEROINIT,rax
You removed the code before this call that calculated the size of the buffer passed in RAX. Now RAX contains the return value of BitBlt, which has nothing to do with the size.