flat assembler
Message board for the users of flat assembler.

Index > Windows > Buffered Input Help.

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Hello everyone! Smile I need help about buffered input in assembly. Can anyone tell me example how to do buffered input like when I type "Hello World" then it should write Hello World and without buffer size, I need just do like function printf and scanf does. but without using library and when I'm trying with scanf, it only results me just 1 word and after "SPACE" words are ignored. Can anyone write me example of simple input in 32bit assembly ? or both 16 and 32 ? Razz Thank you.
Post 14 Sep 2010, 14:35
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello Wink
You can use printf and scanf also in 32 asm
Code:
format PE CONSOLE 4.0 
entry start 

Include 'win32a.inc' 

section ".code" code readable writeable executable

start:

 PUSH    String                  ; Offset String zero terminated
     CALL    [printf]
    ADD     ESP,4

           CALL    [getchar]

       PUSH    0
   CALL    [ExitProcess] 

section '.data' data readable writeable

String   DB 13,10,"Hello World",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'    

_________________
Nil Volentibus Arduum Razz
Post 14 Sep 2010, 16:03
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Dude, I know I can use but I need do that without any library. isn't there other way ?.. and anyway I dont need only printf, I need to input string and then output.
Post 14 Sep 2010, 16:50
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

scanf() behavior is well-defined, if you need string to-end-of-line, use gets() (but fgets() is safer).

ReadFile() from STD_INPUT_HANDLE (you may have to obtain real handle with GetStdHandle() first, to be compliant; XP accepts pseudo-handles raw) by default is buffered (i.e. ENABLE_LINE_INPUT console mode is active).
Post 14 Sep 2010, 18:00
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Mate, I dont like to be depented on msvcrt.dll cause I hate that Very Happy I'm interested about this code and you'll know what I'm asking Smile I need run 16 bit code in 32 bit program, here's code and you'll understand what I mean. Sry for my bad English. Smile Here's code.
Code:
format PE console
include 'WIN32AX.INC'
entry main
.data
buffer db ?
max db ?
.code
proc main
mov ah,0ah
mov dx,max
int 21h
mov dx,buffer
mov ah,09
int 21h
endp    
Post 14 Sep 2010, 18:53
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

My english ain't perfect too. Don't be shy about this.

DOS ints in Windows executable is a sure way to trouble. Let's do it Win32 API's way:
Code:
        format  PE console
        include "Win32AX.Inc"
        .code
start:  invoke  WriteFile, STD_OUTPUT_HANDLE, prompt, sizeof.prompt, wbytes, NULL
        invoke  ReadFile, STD_INPUT_HANDLE, input, sizeof.input, rbytes, NULL
        add     [rbytes], sizeof.prefix
        invoke  WriteFile, STD_OUTPUT_HANDLE, prefix, ptr rbytes, wbytes, NULL
        invoke  Sleep, -1
        ret

struc sized [args] {
common . args
sizeof.#. = $ - .
}
        .data
rbytes  rd      1
wbytes  rd      1
prompt sized db "Enter something: "
prefix sized db "You've entered: "
input sized rb 100

        .end    start    
Post 14 Sep 2010, 19:06
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
mate Sad I need input/output to print string, not to write in file >.< in 16bit mode in 32bit code. thanks
Post 14 Sep 2010, 20:39
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Overflowz, believe me, you SHOULD test the provided code Smile

PS: You'll have to quit the program with Ctrl+C or using the X button.
Post 14 Sep 2010, 20:49
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Oh sorry Razz this is what I need but can this done without "sized" macro ? Cause I dont understand much of macros Razz Thanks. Smile
Post 14 Sep 2010, 20:53
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

Definitely it can. This macro expands to
Code:
name definition
sizeof.name = $ - name    
I've added it just for kicks, same for occasional ptr. Wink
Post 14 Sep 2010, 20:57
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Oh, I understand now. Thank you very much! Smile Oh 1 more, what does PTR do ? Razz and also where to get list of handles ? for example that you give me was STD_OUTPUT/INPUT_HANDLE and things like that? Ty! Smile
Post 14 Sep 2010, 21:06
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

ptr operator is equivalent to square brackets, see manual.

Handles like STD_INPUT_HANDLE? MSDN, definitely.
Post 14 Sep 2010, 21:45
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Thank you. ptr rbytes = [rbytes]. I got it. Razz Thanks for helping ! Smile
Post 14 Sep 2010, 21:51
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Again me Razz Can someone write 16bit example here ? Smile Ty. without dup 24h method >.< and buffer size. Thank you.
Post 15 Sep 2010, 09:30
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

Not Win16 example, I hope?
Code:
        org     0x100
        mov     ah, 0x3F
        mov     cx, sizeof.buffer
        mov     dx, buffer
        xor     bx, bx          ; stdin
        int     0x21
        mov     cx, ax
        mov     bx, 1           ; stdout
        mov     ah, 0x40
        int     0x21
        ret
buffer  rb      100
sizeof.buffer = $-buffer    
Post 15 Sep 2010, 10:05
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Ohh, Great method ! Thank you. I have some quiestions about that code. Smile So.. I guess its that method what you wrote in 32bit code. 0x3F = Open File, 0x40 = Write File and xor bx,bx = 0 and how you know that 0 is stdin and 1 stdout ? and also mov cx,ax means it copies size of stdin into cx register for stdout ? and the last question, how to clear screen after input ? Thank you! Smile
Post 15 Sep 2010, 16:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17281
Location: In your JS exploiting you and your system
revolution
Overflowz: Use a search engine to search for the DOS interrupts list. (hint: RBIL, Ralf Brown's Interrupt List).

Google is your friend
Post 15 Sep 2010, 17:01
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Well, I searched "Google is your friend" but I cant figure out how to learn that list. It's not understandable for me.. Anyway what's difference between DB and RB ? When I'm trying to do DB code doesn't work and when DB then it works pretty nice. Whats problem ?
Post 15 Sep 2010, 17:23
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Overflowz,

RBIL is crucial resource for anybody doing 16-bit programming. There are some cute browsers for it.

db defines byte, while rb reserves them. Naturally, «rb x» is equivalent to «db x dup ?».

How db can't work?
Post 15 Sep 2010, 18:17
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
I dont know.. Just doesn't work.. Anyway thanks for reply! Smile
Post 15 Sep 2010, 18:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.