flat assembler
Message board for the users of flat assembler.

Index > Windows > Windows C Console Functions?

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 22 Jun 2007, 18:59
I'm wondering how I would be able to use the stdlib C functions in ASM for Windows. Could anyone please give me some info about it or possibly a "Hello World" program for it? I'm new to Windows Programming in ASM, and would like to get started in it for fun.

Thanks in advance!

-Rhyno
Post 22 Jun 2007, 18:59
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 843
Location: Jakarta, Indonesia
TmX 22 Jun 2007, 19:25
Post 22 Jun 2007, 19:25
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 22 Jun 2007, 19:36
Code:

format PE CONSOLE 4.0 
entry start 

Include 'win32a.inc'   

section ".code" code readable writeable executable


start:

     invoke printf, string 
     invoke getchar 
     invoke ExitProcess,0

section '.data' data readable writeable

string  db "Hello Word!",13,10,0


section '.idata' import data readable writeable   

  library kernel32,'kernel32.dll',\   
   msvcrt,'msvcrt.dll' 

  import kernel32,\   
      ExitProcess,'ExitProcess'   

  import msvcrt,\   
         getchar,'getchar',\   
   printf,'printf'
    
Post 22 Jun 2007, 19:36
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 22 Jun 2007, 21:04
Thanks for the info! I'll check it out as soon as I finish my work for a C++ class I'm taking.
Post 22 Jun 2007, 21:04
View user's profile Send private message Reply with quote
hologram



Joined: 26 Jun 2007
Posts: 4
hologram 26 Jun 2007, 20:47
Code:
format PE CONSOLE 4.0 
entry start 

Include 'win32a.inc'   

section ".code" code readable executable


start:

     cinvoke printf, string 
     cinvoke getchar 
     cinvoke exit,0

section '.data' data readable writeable

string  db "Hello Word!",13,10,0


section '.idata' import data readable writeable   

  library msvcrt,'msvcrt.dll'   

 

  import msvcrt,\   
         getchar,'getchar',\   
         printf,'printf',\
         exit,'exit'
    


Use cinvoke instead of invoke
or you need to add to esp the number of parameters called * 4
Post 26 Jun 2007, 20:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Jun 2007, 21:07
just look at Examples section on flatassembler.net, there is one example by me how to use them
Post 26 Jun 2007, 21:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 29 Jun 2007, 13:18
Quote:
Use cinvoke instead of invoke

Yeh, and you can use these in normal windows programming too, just include the dll defines like a normal windows .dll, and just remember to use 'cinvoke' instead of 'invoke'.
Post 29 Jun 2007, 13:18
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 20 Feb 2008, 19:49
Here's a small pe console script i wrote.
It prints random color pixels using gdi SetPixel function on console window.
Tested on Win xp sp2

Code:
     format pe console
     entry start

     include 'win32ax.inc'
     
section '.code' code readable writeable executable 

start:   
     invoke GetStdHandle,STD_OUTPUT_HANDLE
     mov [stdout],eax
          
     mov [rect.Left],0
     mov [rect.Top],0
     mov [rect.Right],79
     mov [rect.Bottom],39
     mov [coord.x],80
     mov [coord.y],40
     mov [cinfo.dwSize],25
     mov [cinfo.bVisible],FALSE
     
     cinvoke system,<'cls'>
     cinvoke srand,<cinvoke time,NULL>
     invoke SetConsoleTitle,<'Random Pixels'>
     invoke SetConsoleWindowInfo,[stdout],1,rect
     invoke SetConsoleScreenBufferSize,[stdout],dword[coord]   
     invoke SetConsoleCursorInfo,[stdout],cinfo
     
     invoke FindWindow,NULL,<'Random Pixels'>  
     mov [hWnd],eax
     invoke GetDC,[hWnd]
     mov [hdc],eax
                                     
@@:   
     cinvoke rand
     shl eax,9
     push eax
     cinvoke rand
     pop ecx
     add eax,ecx
     mov esi,eax
     invoke SetPixel,[hdc],<stdcall rnd,640>,<stdcall rnd,480>,esi
     cinvoke _kbhit
     test eax,eax
     jz @b
            
     invoke ExitProcess,0  

             
proc rnd max   
     cinvoke rand 
     shl eax,17
     mul [max]
     mov eax,edx            
     ret
endp


section '.data' data readable writeable

struc COORD {
     .x dw ?
     .y dw ?
    } 

struc SMALL_RECT {
     .Left dw ?
     .Top dw ?
     .Right dw ?
     .Bottom dw ?
    } 

struc LPCONSOLE_CURSOR_INFO {
     .dwSize dd ?
     .bVisible db ?
    }      
     
     cinfo LPCONSOLE_CURSOR_INFO
     rect SMALL_RECT
     coord COORD     
          
     stdout dd ?
     hWnd dd ?
     hdc dd ?

     
section '.idata' import data readable writeable

     library kernel32,'kernel32.dll',\
        msvcrt,'msvcrt.dll',\
        user32,'user32.dll',\
        gdi32,'gdi32.dll'
         
     import gdi32,\
        SetPixel,'SetPixel'
                  
     import user32,\
        GetDC,'GetDC',\
        FindWindow,'FindWindowA'
             
     import kernel32,\     
        ExitProcess,'ExitProcess',\
        GetStdHandle,'GetStdHandle',\
        SetConsoleTitle,'SetConsoleTitleA',\
        SetConsoleCursorInfo,'SetConsoleCursorInfo',\
        SetConsoleWindowInfo,'SetConsoleWindowInfo',\
        SetConsoleCursorPosition,'SetConsoleCursorPosition',\
        SetConsoleScreenBufferSize,'SetConsoleScreenBufferSize'   
            
     import msvcrt,\
        _kbhit,'_kbhit',\
        system,'system',\      
        srand,'srand',\
        rand,'rand',\
        time,'time'        
    


Last edited by Picnic on 20 Feb 2008, 21:31; edited 1 time in total
Post 20 Feb 2008, 19:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 20 Feb 2008, 19:55
I think rnd looks nicer like this:
Code:
proc rnd max   
     cinvoke rand 
     shl eax,17
     mul [max]
     mov eax,edx            
     ret
endp    
Post 20 Feb 2008, 19:55
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 20 Feb 2008, 21:33
You're right revolution. I edited my post.
Post 20 Feb 2008, 21:33
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 01 Mar 2008, 18:29
A running man animation in console, displaying icons from memory (Vortex Windows example)

Image


Description:
Download
Filename: MAN.zip
Filesize: 5.89 KB
Downloaded: 356 Time(s)



Last edited by Picnic on 21 Mar 2020, 10:11; edited 1 time in total
Post 01 Mar 2008, 18:29
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 04 Mar 2008, 16:08
re: man.zip, nifty!! And only 3.5k UPXed. Wink
Post 04 Mar 2008, 16:08
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 06 Mar 2008, 20:18
thanks rugxulo.
the animator should get the credits but i don't who is Smile
Post 06 Mar 2008, 20:18
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.