Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     section .text
  2.     global _start
  3. _start:
  4.     push ebp
  5.     mov ebp, esp
  6.     sub esp, MSG_size + 16
  7.     %define msg ebp - MSG_size
  8.     %define rect ebp - MSG_size - 16
  9.     mov dword [rect], 0
  10.     mov dword [rect + 4], 0
  11.     mov dword [rect + 8], MAXX
  12.     mov dword [rect + 12], MAXY
  13.    
  14.     push 0
  15.     call GetModuleHandleA
  16.     mov [hInstance], eax
  17.    
  18.     call register_class
  19.    
  20.     push 0
  21.     push 0
  22.     push MAIN_WND_STYLE
  23.     lea eax, [rect]
  24.     push eax
  25.     call AdjustWindowRectEx
  26.    
  27.     push 0
  28.     push dword [hInstance]
  29.     push 0
  30.     push 0
  31.        
  32.     mov eax, [rect + 12]
  33.     sub eax, [rect + 4]
  34.     push eax
  35.    
  36.     mov eax, [rect + 8]
  37.     sub eax, [rect]
  38.     push eax
  39.    
  40.     push 100 ; top
  41.     push 200 ; left
  42.     push MAIN_WND_STYLE
  43.     push szTitle
  44.     push szClassName
  45.     push 0
  46.     call CreateWindowExA
  47.     mov [hMainWnd], eax
  48.    
  49.     push SW_SHOWNORMAL
  50.     push eax
  51.     call ShowWindow
  52.    
  53.     push dword [hMainWnd]
  54.     call UpdateWindow
  55.    
  56.     .process:
  57.         lea eax, [msg]
  58.        
  59.         push 0
  60.         push 0
  61.         push 0
  62.         push eax
  63.         call GetMessageA
  64.        
  65.         test eax, eax
  66.         jz .end
  67.        
  68.         lea eax, [msg]
  69.         push eax
  70.         call TranslateMessage
  71.        
  72.         lea eax, [msg]
  73.         push eax
  74.         call DispatchMessageA
  75.        
  76.         jmp .process
  77.    
  78.     .end:
  79.     mov esp, ebp
  80.     pop ebp
  81.     push 0
  82.     call ExitProcess
  83.    
  84. register_class:
  85.     push ebp
  86.     mov ebp, esp
  87.    
  88.     sub esp, WNDCLASSEX_size
  89.     %define wc ebp - WNDCLASSEX_size
  90.     mov dword [wc + WNDCLASSEX.cbSize], WNDCLASSEX_size
  91.     mov dword [wc + WNDCLASSEX.style], CS_HREDRAW | CS_VREDRAW
  92.     mov dword [wc + WNDCLASSEX.lpfnWndProc], wndproc
  93.     mov dword [wc + WNDCLASSEX.cbClsExtra], 0
  94.     mov dword [wc + WNDCLASSEX.cbWndExtra], 0
  95.     mov eax, [hInstance]
  96.     mov dword [wc + WNDCLASSEX.hInstance], eax
  97.     mov dword [wc + WNDCLASSEX.hbrBackground], COLOR_WINDOW + 1
  98.     mov dword [wc + WNDCLASSEX.lpszMenuName], 0
  99.     mov dword [wc + WNDCLASSEX.lpszClassName], szClassName
  100.    
  101.     push IDI_APPLICATION
  102.     push 0
  103.     call LoadIconA
  104.     mov dword [wc + WNDCLASSEX.hIcon], eax
  105.     mov dword [wc + WNDCLASSEX.hIconSm], eax
  106.    
  107.     push IDC_CROSS
  108.     push 0
  109.     call LoadCursorA
  110.     mov dword [wc + WNDCLASSEX.hCursor], eax
  111.     lea eax, [wc]
  112.     push eax
  113.     call RegisterClassExA
  114.    
  115.     mov esp, ebp
  116.     pop ebp
  117.     ret
  118.    
  119. wndproc:
  120.     push ebp
  121.     mov ebp, esp
  122.    
  123.     %define hWnd ebp + 8
  124.     %define uMsg ebp + 12
  125.     %define wParam ebp + 16
  126.     %define lParam ebp + 20
  127.    
  128.     sub esp, PAINTSTRUCT_size + 4
  129.     %define ps ebp - PAINTSTRUCT_size  
  130.     %define hdc ebp - PAINTSTRUCT_size - 4
  131.    
  132.     mov eax, [uMsg]
  133.     cmp eax, WM_DESTROY
  134.     jz .destroy
  135.    
  136.     cmp eax, WM_CREATE
  137.     jz .create
  138.    
  139.     jmp .default
  140.    
  141.     .create:
  142.         ; init logic
  143.         jmp .endinit
  144.    
  145.     .destroy:
  146.         push 0
  147.         call PostQuitMessage
  148.         jmp .endinit
  149.    
  150.     .default:
  151.         push dword [ebp + 20]
  152.         push dword [ebp + 16]
  153.         push dword [ebp + 12]
  154.         push dword [ebp + 8]
  155.         call DefWindowProcA
  156.         jmp .endwndproc
  157.            
  158.     .endinit:
  159.         xor eax, eax
  160.        
  161.     .endwndproc:
  162.         mov esp, ebp
  163.         pop ebp
  164.         ret 16 
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement