Advertisement
webmanix

Console Library (ASM)

Apr 3rd, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include '%fasmi%\win32ax.inc'
  2.  
  3. section '.ven' code readable executable writeable
  4.  
  5.  
  6. ;Returns the size of the string
  7. strlength dd _strlength
  8. _strlength:
  9.   mov edi, [esp+4]
  10.   xor eax, eax
  11.   xor ecx, ecx
  12.   not ecx
  13.   repne scasb
  14.   not ecx
  15.   dec ecx
  16.   mov eax, ecx
  17.   retn 4
  18.  
  19.  
  20. ;Writes text to the screen - write( 'Text with null-terminator' )
  21. write dd _write
  22. _write:
  23.   push dword [esp+4]
  24.   call _strlength
  25.   push eax
  26.   invoke GetStdHandle, -11
  27.   pop ecx
  28.   invoke WriteConsole, eax, dword [esp+4*4], ecx, '    ', 0
  29.   retn 4
  30.  
  31.  
  32. ;Writes text to the screen breaking a line - writeln( 'Text with null-terminator' )
  33. writeln dd _writeln
  34. _writeln:
  35.   push dword [esp+4]
  36.   call _write
  37.   call @f
  38.   db 0x0A, 0x0D, 0x00
  39.   @@:
  40.   call _write
  41.   retn 4
  42.  
  43.  
  44. ;Set cursor position on the console - setpos( x, y )
  45. setpos dd _setpos
  46. _setpos:
  47.   shl dword [esp+8], 16
  48.   mov eax,  [esp+4]
  49.   or  [esp+8], eax
  50.   push dword [esp+8]
  51.   invoke GetStdHandle, -11
  52.   pop ecx
  53.   push ecx
  54.   push eax
  55.   call [SetConsoleCursorPosition]
  56.   retn 8
  57.  
  58.  
  59. ;Writes a chunk of data to overwrite what is on the screen - CLS()
  60. clearscr dd _clearscr
  61. _clearscr:
  62.   invoke setpos, 0, 0
  63.   call @f
  64.   rb 10240
  65.   db 0x00
  66.   @@:
  67.   pop edi
  68.   push edi
  69.   mov al, 20h
  70.   mov ecx, 10240
  71.   rep stosb
  72.   call [write]
  73.   invoke setpos, 0, 0
  74.   retn
  75.  
  76.  
  77. ;Set text color (foreground/background) pattern is described as:
  78. ;where I=Intensity, R=Red, G=Green, B=Blue. 11110000 is Background and 1111 is Foreground
  79. ;IRGBIRGB
  80. setcolor dd _setcolor
  81. _setcolor:
  82.   invoke GetStdHandle, -11
  83.   invoke SetConsoleTextAttribute, eax, dword [esp+4]
  84.   retn 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement