Why does my program SetPixel when I call SetPixel ? All call parameters seem to be correct.

  .486 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\masm32.inc include \masm32\include\gdi32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\Comctl32.inc include \masm32\include\comdlg32.inc include \masm32\include\shell32.inc include \masm32\include\oleaut32.inc include \masm32\include\msvcrt.inc include \masm32\include\dialogs.inc include \masm32\macros\macros.asm includelib \masm32\lib\masm32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\Comctl32.lib includelib \masm32\lib\comdlg32.lib includelib \masm32\lib\shell32.lib includelib \masm32\lib\oleaut32.lib includelib \masm32\lib\msvcrt.lib Main PROTO .data? hIcon Dd ? hBrush Dd ? hCursor Dd ? hImage Dd ? hInstance Dd ? .data wc WNDCLASS <?> newhwnd dd 0 szTitleName db 'Window Application',0 msg MONMSGSTRUCT <?> ; szClassName db 'ASMCLASS32',0 ps PAINTSTRUCT <?> rct RECT <?> .code start: mov hInstance, FUNC(GetModuleHandle,NULL) mov hIcon, FUNC(LoadIcon, hInstance, 100) mov hCursor, FUNC(LoadCursor,NULL,IDC_ARROW) mov hBrush, FUNC(GetSysColorBrush, COLOR_APPWORKSPACE) Mov [wc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS Mov [wc.lpfnWndProc], offset WndProc Mov [wc.cbClsExtra], 0 Mov [wc.cbWndExtra], 0 Mov eax, [hInstance] Mov [wc.hInstance], eax Invoke LoadIcon,0,IDI_APPLICATION Mov [wc.hIcon], eax Invoke LoadCursorA,0,IDC_ARROW Mov [wc.hCursor], eax Mov [wc.hbrBackground], COLOR_BTNFACE+1 Mov dword ptr [wc.lpszMenuName], 0 Mov dword ptr [wc.lpszClassName], offset szClassName Invoke RegisterClassA,offset wc Push 0 Push [hInstance] Push 0 Push 0 Push 660 Push 778 Push CW_USEDEFAULT Push CW_USEDEFAULT Push WS_OVERLAPPEDWINDOW Push offset szTitleName Push offset szClassName Push 0 Call CreateWindowEx mov [newhwnd], eax invoke ShowWindow,[newhwnd],SW_SHOWNORMAL invoke UpdateWindow, [newhwnd] StartLoop: invoke GetMessage,ADDR msg,NULL,0,0 cmp eax, 0 je ExitLoop invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg jmp StartLoop ExitLoop: invoke ExitProcess,eax WndProc proc uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD LOCAL hDC:HDC Cmp [wmsg], WM_DESTROY Je wmdestroy Cmp [wmsg], WM_PAINT Je WMPAINT Cmp [wmsg], WM_KEYDOWN Je wmkeydown Invoke DefWindowProcA,[hwnd],[wmsg],[wparam],[lparam] Jmp finish wmkeydown: cmp [wparam], VK_ESCAPE WMPAINT: mov hDC, rv(GetDC, [newhwnd]) push 99806040 push 380 push 437 push hDC call SetPixel ;Вот тут всё проблема je wmdestroy jmp finish wmdestroy: invoke PostQuitMessage, 0 invoke ExitProcess, 0 finish: ret WndProc endp End start 

UPD: Well, on the update crashes and everything, no way

OllyDbg screen shot with the above program

  • one
    use the debugger - Abyx
  • Why write something difficult to write just? The same code on this site will not be much more, nor much slower. - Vladimir Martyanov
  • @Abyx updated the theme - alex-rudenkiy

1 answer 1

In general, here is the solution:

 .data? ps PAINTSTRUCT <> .code invoke BeginPaint, hwnd, addr ps invoke SetPixel, eax, 15, 20, 65285 invoke EndPaint, hwnd, addr ps