usrxprd

cgitest

Jul 27th, 2021
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;CGI Hello World with NASM and win32 API
  2. ;version: 1.0.0
  3.  
  4. BITS 32
  5.  
  6. STD_OUTPUT_HANDLE       equ     -11
  7.  
  8. section .data
  9. HTTPheader: db "Content-Type:text/html;charset=us-ascii", 0xa, 0xa
  10. HH_LEN equ $-HTTPheader
  11.  
  12. WebPage: db "<html><body><code>Hello World</code></body></html>"
  13. WP_LEN equ $-WebPage
  14.  
  15. section .code
  16.     extern _GetStdHandle@4
  17.     extern _WriteFile@20
  18.    
  19.     global _WinMain@16
  20. _WinMain@16:
  21.     push ebp
  22.     mov ebp,esp
  23.    
  24.     sub esp,12
  25.     ;[ebp-4]    :   stdout
  26.     ;[ebp-8]    :   &bytesWritten
  27.     ;[ebp-12]   :   bytesWritten
  28.    
  29.     ;get and store ptr to bytesWritten
  30.     mov edx,ebp
  31.     sub edx,12
  32.     mov dword[ebp-8],edx
  33.    
  34.     ;get stdout
  35.     push STD_OUTPUT_HANDLE
  36.     call _GetStdHandle@4
  37.    
  38.     mov dword[ebp-4],eax    ;store stdout handle
  39.    
  40.     ;send header
  41.     push 0
  42.     push dword[ebp-8]   ;&bytesWritten
  43.     push HH_LEN
  44.     push HTTPheader
  45.     push dword[ebp-4]   ;stdout
  46.     call _WriteFile@20
  47.    
  48.     ;send web page
  49.     push 0
  50.     push dword[ebp-8]   ;&bytesWritten
  51.     push WP_LEN
  52.     push WebPage
  53.     push dword[ebp-4]   ;stdout
  54.     call _WriteFile@20
  55. .ret:
  56.     xor eax,eax
  57.     mov esp,ebp
  58.     pop ebp
  59.     ret
  60.    
  61.    
Advertisement
Add Comment
Please, Sign In to add comment