Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; HELLO.EXE - SAY WELCOME - SAY HELLO - TAKE 2 INT'S - RETURN SUM
  2. ; Link With -lkernel32
  3.  
  4. section .data                                    ;Constants
  5.   output_handle     db   0                           ;Define byte 0
  6.   bytes_written     db   0                           ;Define byte 0
  7.   bytes_written_2   db   0                           ;Define byte 0
  8.   STD_OUTPUT_HANDLE dd  -11                          ;Define dword -11
  9.   welcome_msg       db   "Welcome",10                ;Define byte "welcome" + newline
  10.   hello_msg         db   10,"Hello World",10        ;Define byte newline + "Hello" + newline
  11.  
  12. section .text                                    ;Code
  13.   global  _WinMain@16                                ;Define where to start
  14.   extern  _ExitProcess@4                             ;Get ExitProcess Function, 4 bytes of args
  15.   extern  _GetStdHandle@4                            ;Get GetStdHandle Function, 4 bytes of args
  16.   extern  _WriteConsoleA@20                          ;Get WriteConsoleA Function, 20 bytes of args
  17.   extern  _Sleep@4                                   ;Get Sleep Function, 4 bytes of args
  18.   extern  _GetLastError@0                            ;Get GetLastError Function, 0 byter of args
  19.  
  20. _WinMain@16:                                     ;Where to start
  21.   call GetHandle                                     ;Goto section GetHandle
  22.   call WelcomeToConsole                              ;Goto section WriteConsole
  23.   call GetHandle                                     ;Goto section GetHandle
  24.   call HelloToConsole                                ;Goto section HelloToConsole
  25.   call ExitProgram                                    ;Goto section ExitProgram
  26.  
  27. GetHandle:                                       ;Get Output Handle ($CONOUT)
  28.   push dword [STD_OUTPUT_HANDLE]                     ;Arg of GetStdHandle, DWORD nStdHandle, (-11)
  29.   call _GetStdHandle@4                               ;Call GetStdHandle
  30.   mov [output_handle], eax                           ;Move contents of CPU register eAx to mem addr of output_handle
  31.  
  32. WelcomeToConsole:                                ;Write Welcome Message To Console
  33.   push dword 0                                       ;Last arg of WriteConsole must be 0, LPVOID lpReserved, (0)
  34.   push bytes_written                                 ;Penultimate arg of WriteConsole, LPDWORD lpNumberOfCharsWritten, (mem addr of bytes_written)
  35.   push dword 8                                       ;Third arg of WriteConsole, DWORD nNumberOfCharsToWrite, (9)
  36.   push welcome_msg                                   ;Second arg of WriteConsole, VOID *lpBuffer, (welcome_msg)
  37.   push dword [output_handle]                         ;First arg of WriteConsole, HANDLE hConsoleOutput, (mem addr of output_handle, converted to dword
  38.   call _WriteConsoleA@20                             ;Call WriteConsoleA
  39.  
  40. HelloToConsole:                                  ;Write Hello Message To Console
  41.   push dword 0                                       ;Last arg of WriteConsole must be 0, LPVOID lpReserved, (0)
  42.   push bytes_written_2                               ;Penultimate arg of WriteConsole, LPDWORD lpNumberOfCharsWritten, (mem addr of bytes_written_2)
  43.   push dword 13                                      ;Third arg of WriteConsole, DWORD nNumberOfCharsToWrite, (14)
  44.   push hello_msg                                     ;Second arg of WriteConsole, VOID *lpBuffer, (hello_msg)
  45.   push dword [output_handle]                         ;First arg of WriteConsole, HANDLE hConsoleOutput, (mem addr of output_handle, converted to dword
  46.   call _WriteConsoleA@20                             ;Call WriteConsoleA
  47.  
  48. ExitProgram:                                     ;Exit Program
  49.   push dword 3000                                    ;Arg of Sleep, DWORD dwMilliseconds, (3000)
  50.   call _Sleep@4                                      ;Call Sleep
  51.   push dword 0                                       ;Arg of ExitProcess, UINT uExitCode, (0, ERROR_SUCESS)
  52.   call _ExitProcess@4                                ;Call ExitProcess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement