flat assembler
Message board for the users of flat assembler.
Index
> Windows > Beginnier problem with input. |
Author |
|
revolution 15 Apr 2014, 13:03
You can't use the DOS "int 21h" or change the segment registers CS or DS in a protected mode 32-bit program running in Windows.
For keyboard input you can open a handle to STD_INPUT_HANDLE and read bytes from there. BTW: The value out or range error is because dx is too small to hold a 32-bit address 0x004XXXXX. |
|||
15 Apr 2014, 13:03 |
|
mmajewski 15 Apr 2014, 13:22
@revolution
Thank you for answering. I know understand. Is it a way to create a file and write something in it in DOS mode? |
|||
15 Apr 2014, 13:22 |
|
revolution 15 Apr 2014, 13:28
You are almost there. Just get the input handle (GetStdHandle) and read the keyboard buffer (ReadFile) then write it out to the target file name (CreateFile, WriteFile, CloseHandle).
|
|||
15 Apr 2014, 13:28 |
|
mmajewski 15 Apr 2014, 13:54
@revolution
How to use ReadFile? I can not find any links that shows me how to use this functions in assembly. So far I created: Code: format pe console 4.0 include 'WIN32AX.INC' .data bufsize = 20 byteswritten dd ? buff dd ? .code main: invoke GetStdHandle, STD_INPUT_HANDLE mov [buff], eax invoke CreateFile, 'test.txt', GENERIC_WRITE, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0 invoke WriteFile, eax, buff, bufsize, byteswritten, 0 invoke ExitProcess, 0 .end main |
|||
15 Apr 2014, 13:54 |
|
mmajewski 15 Apr 2014, 13:55
But that programs is closing immediately and i have no chance to input anything.
|
|||
15 Apr 2014, 13:55 |
|
revolution 15 Apr 2014, 13:57
mmajewski wrote: How to use ReadFile? You use it in assembly in the same way as C would use it. |
|||
15 Apr 2014, 13:57 |
|
revolution 15 Apr 2014, 14:01
mmajewski wrote: But that programs is closing immediately and i have no chance to input anything. |
|||
15 Apr 2014, 14:01 |
|
mmajewski 15 Apr 2014, 14:19
@revolution
Thank you very much I finally managed to do this. Such a joy. Code: format pe console 4.0 include 'WIN32AX.INC' .data bufsize = 4 byteswritten dd ? buff dd ? .code main: invoke GetStdHandle, STD_INPUT_HANDLE invoke ReadFile, eax, buff, bufsize, 0,0 invoke CreateFile, 'test.txt', GENERIC_WRITE, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0 invoke WriteFile, eax, buff, bufsize, byteswritten, 0 invoke ExitProcess, 0 .end main |
|||
15 Apr 2014, 14:19 |
|
revolution 15 Apr 2014, 14:30
Good, but you forgot about CloseHandle.
|
|||
15 Apr 2014, 14:30 |
|
macgub 01 Sep 2014, 08:17
Just one question. How to correctly close handle? I have similar problem.
|
|||
01 Sep 2014, 08:17 |
|
revolution 01 Sep 2014, 08:28
macgub wrote: Just one question. How to correctly close handle? I have similar problem. http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211%28v=vs.85%29.aspx |
|||
01 Sep 2014, 08:28 |
|
macgub 01 Sep 2014, 09:11
So something like that will be OK ?
Code: invoke GetStdHandle, STD_OUTPUT_HANDLE mov [file_handle],eax invoke CreateFile,file_name, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 invoke WriteFile,eax,file_buffer,[file_size], byteswritten, 0 invoke CloseHandle,[file_handle] |
|||
01 Sep 2014, 09:11 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.