Untitled

Posted on April 18, 2010, 4:17 pm UTC by Iago (about 1 year ago)

Code (highlighted for ASM)

  1. ; NASM: nasmw -f obj nasmpad.asm
  2. ; ALINK: alink -c -oPE -subsys gui nasmpad win32.lib
  3.  
  4. extern CreateWindowExA
  5. import CreateWindowExA user32.dll
  6. extern RegisterClassExA
  7. import RegisterClassExA user32.dll
  8. extern GetModuleHandleA
  9. import GetModuleHandleA kernel32.dll
  10. extern LoadIconA
  11. import LoadIconA user32.dll
  12. extern LoadCursorA
  13. import LoadCursorA user32.dll
  14. extern ShowWindow
  15. import ShowWindow user32.dll
  16. extern UpdateWindow
  17. import UpdateWindow user32.dll
  18. extern GetMessageA
  19. import GetMessageA user32.dll
  20. extern TranslateMessage
  21. import TranslateMessage user32.dll
  22. extern DispatchMessageA
  23. import DispatchMessageA user32.dll
  24. extern ExitProcess
  25. import ExitProcess kernel32.dll
  26. extern DefWindowProcA
  27. import DefWindowProcA user32.dll
  28.  
  29. struc WNDCLASSEX
  30. .cbSize        resd 1
  31. .style         resd 1
  32. .lpfnWndProc   resd 1
  33. .cbClsExtra    resd 1
  34. .cbWndExtra    resd 1
  35. .hInstance     resd 1
  36. .hIcon         resd 1
  37. .hCursor       resd 1
  38. .hbrBackground resd 1
  39. .lpszMenuName  resd 1
  40. .lpszClassName resd 1
  41. .hIconSm       resd 1
  42. endstruc
  43.  
  44. struc POINT
  45. .x resd 1
  46. .y resd 1
  47. endstruc
  48.  
  49. struc MSG
  50. .hwnd    resd 1
  51. .message resd 1
  52. .wParam  resd 1
  53. .lParam  resd 1
  54. .time    resd 1
  55. .pt      resb POINT_size
  56. endstruc
  57.  
  58. segment .data use32
  59. CS_VREDRAW equ 1h
  60. CS_HREDRAW equ 2h
  61. WinClass:
  62. istruc WNDCLASSEX
  63. at WNDCLASSEX.cbSize,        dd  WNDCLASSEX_size
  64. at WNDCLASSEX.style,         dd  CS_VREDRAW + CS_HREDRAW
  65. at WNDCLASSEX.lpfnWndProc,   dd  Windowprocedure
  66. at WNDCLASSEX.cbClsExtra,    dd  0
  67. at WNDCLASSEX.cbWndExtra,    dd  0
  68. at WNDCLASSEX.hInstance,     dd  0
  69. at WNDCLASSEX.hIcon,         dd  0
  70. at WNDCLASSEX.hCursor,       dd  0
  71. at WNDCLASSEX.hbrBackground, dd  COLOR_BACKGROUND
  72. at WNDCLASSEX.lpszMenuName,  dd  0
  73. at WNDCLASSEX.lpszClassName, dd  szClassName
  74. at WNDCLASSEX.hIconSm,       dd  0
  75. iend
  76. WinMSG:
  77. istruc MSG
  78. at MSG.hwnd,    dd 0
  79. at MSG.message, dd 0
  80. at MSG.wParam,  dd 0
  81. at MSG.lParam,  dd 0
  82. at MSG.time,    dd 0
  83. at MSG.pt,      dd 0
  84. iend
  85. Handle                 dd 0
  86. Button                 dd 0
  87. BtnClass               db "Button"
  88. BtnT                   db "Titulo"
  89. Icon                   dd 0
  90. Cursor                 dd 0
  91. szClassName            db "nasmpad_0001"
  92. szTitle                db "Nasmpad"
  93. Biba                   db "CORNO", 0
  94. IDI_APPLICATION       equ 32512
  95. IDC_ARROW             equ IDI_APPLICATION
  96. CW_USEDEFAULT         equ 80000000h
  97. WS_EX_WINDOWEDGE       equ 00000100h
  98. WS_EX_CLIENTEDGE       equ 00000200h
  99. WS_OVERLAPPED         equ 0h
  100. WS_CAPTION             equ 0C00000h
  101. WS_SYSMENU             equ 80000h
  102. WS_VISIBLE             equ 268435456d
  103. WS_CHILD               equ 1073741824d
  104. WS_CHILDWINDOW         equ WS_CHILD
  105. WS_THICKFRAME         equ 40000h
  106. WS_MINIMIZEBOX         equ 20000h
  107. WS_MAXIMIZEBOX         equ 10000h
  108. WS_EX_OVERLAPPEDWINDOW equ WS_EX_WINDOWEDGE|WS_EX_CLIENTEDGE
  109. WS_OVERLAPPEDWINDOW   equ WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
  110. SW_SHOWNORMAL         equ 1
  111. WM_DESTROY             equ 2h
  112. COLOR_BACKGROUND       equ 1
  113. segment .code use32
  114. global ..start
  115. ..start:
  116.  
  117. mov eax, dword Biba
  118.  
  119. mov [WinClass+WNDCLASSEX.lpszMenuName], eax
  120.  
  121. push dword 0
  122. call [GetModuleHandleA]
  123. mov [WinClass+WNDCLASSEX.hInstance], eax
  124.  
  125. push dword IDI_APPLICATION
  126. push dword 0
  127. call [LoadIconA]
  128.  
  129. mov [WinClass+WNDCLASSEX.hIcon],eax
  130.  
  131. push dword IDC_ARROW
  132. push dword 0
  133. call [LoadCursorA]
  134.  
  135. mov [WinClass+WNDCLASSEX.hCursor],eax
  136.  
  137. push dword WinClass
  138. call [RegisterClassExA]
  139.  
  140. push dword 0
  141. push dword [WinClass+WNDCLASSEX.hInstance]
  142. push dword 0
  143. push dword 0
  144. push dword 480
  145. push dword 640
  146. push dword CW_USEDEFAULT
  147. push dword CW_USEDEFAULT
  148. push dword WS_OVERLAPPEDWINDOW
  149. push dword szTitle
  150. push dword szClassName
  151. push dword WS_EX_OVERLAPPEDWINDOW
  152. call [CreateWindowExA]
  153.  
  154. mov [Handle], eax
  155.  
  156. push dword SW_SHOWNORMAL
  157. push dword [Handle]
  158. call [ShowWindow]
  159.  
  160. push dword 0
  161. push dword [WinClass+WNDCLASSEX.hInstance]
  162. push dword 0
  163. push dword [Handle]
  164. push dword 330
  165. push dword 220
  166. push dword 0
  167. push dword 0
  168. push dword WS_VISIBLE|WS_CHILD
  169. push dword BtnT
  170. push dword BtnClass
  171. push dword 0
  172. call [CreateWindowExA]
  173.  
  174. mov [Button], eax
  175.  
  176. MsgLoop:
  177.  
  178. push dword 0
  179. push dword 0
  180. push dword 0
  181. push dword WinMSG
  182. call [GetMessageA]
  183.  
  184. push dword WinMSG
  185. call [TranslateMessage]
  186.  
  187. push dword WinMSG
  188. call [DispatchMessageA]
  189.  
  190. jmp MsgLoop
  191.  
  192. Windowprocedure:
  193.  
  194. %define hWnd ebp+8
  195. %define Msg ebp+0ch
  196. %define wParam ebp+10h
  197. %define lParam ebp+14h
  198.  
  199. push ebp
  200. mov ebp,esp
  201.  
  202. cmp dword [Msg],WM_DESTROY
  203. je Finish
  204.  
  205. .DefMsgHandler:
  206.  
  207. push dword [lParam]
  208. push dword [wParam]
  209. push dword [Msg]
  210. push dword [hWnd]
  211. call [DefWindowProcA]
  212.  
  213. .Exit:
  214.  
  215. mov esp, ebp
  216. pop ebp
  217. ret
  218.  
  219. Finish:
  220.  
  221. push dword 0
  222. call [ExitProcess]
  223.  
  224.  
  225. jmp Windowprocedure.DefMsgHandler

Comments

WinAPI no NASM