flat assembler
Message board for the users of flat assembler.

Index > Windows > how to read a string from standard input aka keyboard

Author
Thread Post new topic Reply to topic
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:05
Before you get mad at me:
I don't wanna use fgets, scanf, gets, getchar or whatever there in msvcrt.dll!
Please tell me if anybody knows.

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 12 Jan 2008, 06:05
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 12 Jan 2008, 06:10
ReadConsole/ReadConsoleInput ?
Post 12 Jan 2008, 06:10
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:19
Thanks sinsi!


Last edited by 0.1 on 12 Jan 2008, 06:45; edited 1 time in total
Post 12 Jan 2008, 06:19
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:25
Still not working!
Code:

        format PE Console
        entry start

        include 'win32ax.inc'

        section '.code' code readable executable
proc start uses ebx
     local buff[1024]:BYTE
     local count:DWORD

        invoke GetStdHandle, STD_INPUT_HANDLE
        invoke ReadConsole, eax, addr buff, 1024, addr count, 0

        ret
endp

        section '.idata' import data readable
library kernel32,'kernel32.dll'

import kernel32,\
       GetStdHandle,'GetStdHandle',\
       ReadConsole,'ReadConsole'
    


Last edited by 0.1 on 12 Jan 2008, 06:45; edited 1 time in total
Post 12 Jan 2008, 06:25
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 12 Jan 2008, 06:28
Try using GetStdHandle with STD_INPUT_HANDLE and passing that to ReadConsole
Post 12 Jan 2008, 06:28
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:30
Very Happy
Ha! Ha! Ha!
Post 12 Jan 2008, 06:30
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 12 Jan 2008, 06:36
Code:
format PE Console 4.0
entry start

include 'win32ax.inc'

section '.code' code readable executable
proc start uses ebx 
     local buff[1024]:BYTE 
     local count:DWORD 
        invoke GetStdHandle,STD_INPUT_HANDLE
        mov ebx,eax
        invoke ReadConsole, ebx, addr buff, 1024, addr count, 0

        ret 
endp 

section '.idata' import data readable writeable
library kernel32,'kernel32.dll'
import kernel32,ReadConsole,'ReadConsoleA',GetStdHandle,'GetStdHandle'
    

heh heh 0 was 'standard input' in DOS days Smile

edit: using eax with invoke can be a problem when also using 'addr' in masm, dunno about fasm


Last edited by sinsi on 12 Jan 2008, 06:41; edited 1 time in total
Post 12 Jan 2008, 06:36
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:39
strange! Shocked
Why not pass eax?
Post 12 Jan 2008, 06:39
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:44
Sorry for so much trouble!
Fixed now Smile
Post 12 Jan 2008, 06:44
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 12 Jan 2008, 06:47
I shall discard my reply, since you seem to have a 'thought-interface' to your pc...you seem to reply to mine obscenely quick Laughing
Post 12 Jan 2008, 06:47
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:52
Code:
        format PE Console
        entry start

        include 'win32ax.inc'

;        section '.data' data readable writable


        section '.code' code readable executable
proc start uses ebx
     local buff[1024]:BYTE
     local count:DWORD
     local stdin:DWORD
     local stdout:DWORD

        invoke GetStdHandle, STD_INPUT_HANDLE
        mov [stdin], eax

        invoke GetStdHandle, STD_OUTPUT_HANDLE
        mov [stdout], eax

        invoke ReadConsole, [stdin], addr buff, 1024, addr count, 0

        invoke WriteConsole, [stdout], addr buff, [count], addr count, 0

        ret
endp

        section '.idata' import data readable
library kernel32,'kernel32.dll'

import kernel32,\
       GetStdHandle,'GetStdHandle',\
       ReadConsole,'ReadConsoleA',\
       WriteConsole,'WriteConsoleA'
    

One more problem!
If I input:
a b c
I get the output:
a


Why? You know how to fix?

PS: By the way, fasm uses edx for address!


Last edited by 0.1 on 12 Jan 2008, 06:56; edited 1 time in total
Post 12 Jan 2008, 06:52
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1 12 Jan 2008, 06:56
so stupid of me!
sorry! again! Shocked
fixed.
Post 12 Jan 2008, 06:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Jan 2008, 11:58
Do not read STDIN with ReadConsole. It may not be a console (it can be redirected from something else). Use ReadFile.

And after ReadConsole / ReadFile, you should check return value for error.
Post 12 Jan 2008, 11:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 12 Jan 2008, 18:24
lol your code is pretty high-level fasm, when I use readconsole i just make a pointer in memory called hStdIn and hStdOut if I ever use WriteConsole. IDK about using ReadFile with the console, but I've heard of it working. I usually just add printf from msvcrt.dll and _getch from the same library when I need to pause the screen.
Post 12 Jan 2008, 18:24
View user's profile Send private message Visit poster's website Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 192
Location: section '.code' executable
semiono 12 Oct 2010, 15:35
Is it'll enaugh ReadConsole() to get input parametres for use it CreateProcess,'\PATH\Far.exe', ebx... ?

Or i need strongly GetCommanline api?? Embarassed Crying or Very sad

_________________
Windows 9, FL Studio 19
Post 12 Oct 2010, 15:35
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Oct 2010, 17:15
semiono,

stdin is not your command line.
Post 12 Oct 2010, 17:15
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 192
Location: section '.code' executable
semiono 12 Oct 2010, 17:19
Yes! I found my bug! board.flatassembler.net/topic.php?t=12019

Code:
        invoke GetCommandLine
<THIS DO NOT NEED ANY PARSING>
        invoke CreateProcess,exec,[eax],NULL,NU....    

Well!!
Post 12 Oct 2010, 17:19
View user's profile Send private message 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.