flat assembler
Message board for the users of flat assembler.
Index
> Windows > help converting 32 to 64 for displaying bitmaps from memory |
Author |
|
patchariadog 10 Apr 2014, 04:57
I found this bit of code from Vortex on the forum that will Displaying bitmaps from memory. http://board.flatassembler.net/topic.php?p=11521#11521
it works great for an about box with your websites logo. this is the meat of the program and the piece that I use in my templates Code: .wmcreate: invoke GetClientRect,[hwnd],client lea eax,[pBitmap+14] ; start of BITMAPINFOHEADER header invoke CreateDIBSection,0,eax,DIB_RGB_COLORS,ppvBits,0,0 mov [hBitmap],eax lea eax,[pBitmap+54] ; + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) stdcall MemCopy,eax,[ppvBits],149346-54 ; copy bitmap's bit values .wmpaint: lea eax,[ps] invoke BeginPaint,[hwnd],eax mov [hdc],eax invoke CreateCompatibleDC,eax mov [hMemDC],eax invoke SelectObject,eax,[hBitmap] invoke BitBlt,[hdc],0,0,429,80,[hMemDC],0,0,SRCCOPY invoke DeleteDC,[hMemDC] lea eax,[ps] invoke EndPaint,[hwnd],eax proc MemCopy,Source,Dest,ln ; procedure from masm32 library cld mov esi, [Source] mov edi, [Dest] mov ecx, [ln] shr ecx, 2 rep movsd mov ecx, [ln] and ecx, 3 rep movsb ret endp .data pBitmap FILE 'fish.bmp' caption db 'Bitmap from memory',0 class db 'BitmapClass',0 mainhwnd dd ? hBitmap dd ? ppvBits dd ? ps PAINTSTRUCT hdc dd ? hMemDC dd ? the problem is I am trying to figure out how to convert this code to 64 bit for my 64 bit programing template. I tired the usual eax->rax etc and changed some of the dd to dq. it compiles but does not display the image. instead it displays a black square. here is what I tried Code: .wmcreate: invoke GetClientRect,[hwnd],client lea rax,[pBitmap+14] ; start of BITMAPINFOHEADER header invoke CreateDIBSection,0,rax,DIB_RGB_COLORS,ppvBits,0,0 mov [hBitmap],rax lea rax,[pBitmap+54] ; + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) stdcall MemCopy,rax,[ppvBits],149346-54 ; copy bitmap's bit values .wmpaint: lea rax,[ps] invoke BeginPaint,[hwnd],rax mov [hdc],rax invoke CreateCompatibleDC,rax mov [hMemDC],rax invoke SelectObject,rax,[hBitmap] invoke BitBlt,[hdc],0,0,429,80,[hMemDC],0,0,SRCCOPY invoke DeleteDC,[hMemDC] lea rax,[ps] invoke EndPaint,[hwnd],rax proc MemCopy,Source,Dest,ln ; procedure from masm32 library cld mov rsi, [Source] mov rdi, [Dest] mov rcx, [ln] shr rcx, 2 rep movsd mov rcx, [ln] and rcx, 3 rep movsb ret endp .data pBitmap FILE 'fish.bmp' caption db 'Bitmap from memory',0 class db 'BitmapClass',0 mainhwnd dq ? hBitmap dq ? ppvBits dq ? ps PAINTSTRUCT hdc dq ? hMemDC dq ? there must be some small thing I missed or don't understand. Thanks everybody |
|||
10 Apr 2014, 04:57 |
|
patchariadog 10 Apr 2014, 17:36
I was able to get the program to work by removing the stdcall line and replacing it with this code
Code: cld mov rsi, rax mov rdi, [ppvBits] mov rcx, 149346-54 shr rcx, 2 rep movsd mov rcx, 149346-54 and rcx, 3 rep movsb I would however like to figure out how to use fastcall for future programs. I read at [url] http://flatassembler.net/docs.php?article=win32#1.4 [/url] that fastcall uses rcx,rdx,r8,r9 so how to I fix the proc to have it work for 64 bit, so I know how to uses proc in other 64 bit programs Also I wanted to know how did you get the info from a debugger? did use IDA or what other debugger. sorry if these are newbie questions but I have never debugged my programs before. thanks |
|||
10 Apr 2014, 17:36 |
|
revolution 10 Apr 2014, 22:22
You can use fastcall like this:
Code: proc MemCopy uses rsi rdi,Source,Dest,ln ;<--- tell the assembler which registers you are corrupting ;spill mov [Source],rcx ;<--- fill the shadow space and free the register for use mov [Dest],rdx ;<--- fill the shadow space and free the register for use mov [ln],r8 ;<--- fill the shadow space and free the register for use ;use cld mov rsi,[Source] mov rdi,[Dest] mov rcx,[ln] shr rcx,2 rep movsd mov rcx,[ln] and rcx,3 rep movsb ret endp I didn't use a disassembler or a debugger on your code because you didn't post a complete example for me to assemble. But I was suggesting that you consider using one because such a useful tool should be part of your workflow. |
|||
10 Apr 2014, 22:22 |
|
patchariadog 11 Apr 2014, 00:51
thank you revolution for explaining how to use procedures in 64 bit. this now explains why I could never get some other procedures working for 64 bit.
|
|||
11 Apr 2014, 00:51 |
|
patchariadog 11 Apr 2014, 01:00
also thanks for pointing out i needed to add corruption to my registers for any procedure I wright. I did not know this.
|
|||
11 Apr 2014, 01:00 |
|
revolution 11 Apr 2014, 01:05
stdcall, fastcall, ccall, etc. all have specs that explain which registers are to be preserved and which can be freely altered.
|
|||
11 Apr 2014, 01:05 |
|
revolution 11 Apr 2014, 07:47
BTW: In 64-bit mode you have movsq:
Code: mov rsi,[Source] mov rdi,[Dest] mov rcx,[ln] shr rcx,3 rep movsq mov rcx,[ln] and rcx,7 rep movsb |
|||
11 Apr 2014, 07:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.