flat assembler
Message board for the users of flat assembler.
Index
> Windows > Console read/write |
Author |
|
JohnFound 19 Jan 2015, 20:13
It is not so simple. You need several things:
1. In order to read/write files in Windows you need to import needed functions from the Windows DLLs - You will need at least CreateFile ReadFile, WriteFile - Read the examples in FASM documentation, there is enough examples how the functions are imported. 2. In order to get the command line arguments (the filenames specified in your post) you will need the functions GetCommandLine and CommandLineToArgv 3. Read some more examples from FASM package. Download and read the help files about Win32 - there are described all Win32 functions you will need. As an alternative way - search for the function names in google - probably the first link will bring you to the description. |
|||
19 Jan 2015, 20:13 |
|
MIHIP 19 Jan 2015, 20:25
JohnFound wrote: It is not so simple. You need several things: How i can get file names from console? PROGRAM IN.txt OUT.txt ?? |
|||
19 Jan 2015, 20:25 |
|
MIHIP 19 Jan 2015, 20:30
Help me please, here is error while i launch program it crashes:
Code: format pe gui 4.0 include 'win32ax.inc' section '.code' executable start: invoke CreateFile,fi,GENERIC_READ,NULL,NULL,\ OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL mov [hFile],eax invoke GetFileSize,[hFile],NULL mov esi,eax invoke CreateFile,fo,GENERIC_WRITE,NULL,NULL,\ CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL mov [hFout],eax invoke SetFileAttributes,fi,FILE_ATTRIBUTE_NORMAL invoke SetFileAttributes,fo,FILE_ATTRIBUTE_NORMAL @@: invoke ReadFile,[hFile],lpBuffer,1,szReadByte,NULL inc [lpBuffer] pushad mov ecx,[size] mov esi,[dat] lea edi,[esi+ecx] xor eax,eax @@:lodsb mov edx,eax mov ebx,eax and eax,7 shr edx,3 and edx,7 shr ebx,6 mov ah,byte[wct+eax] mov al,byte[wct+edx] shl eax,8 mov al,byte[wct+ebx] mov [edi],eax add edi,3 loop @b size=$-dat ;$ popad invoke WriteFile,[hFout],lpBuffer,1,szFileWritten,NULL dec esi jnz @r invoke CloseHandle,[hFile] invoke CloseHandle,[hFout] exit: invoke ExitProcess,NULL .end start section '.data' readable fi db 'i.txt',NULL fo db 'o.txt',NULL dat dd ? wct db 'ABCDEFGO' section '.data' readable writable hFile dd NULL szFile dd NULL lpBuffer dd NULL hFout dd NULL szFileWritten dd NULL szReadByte dd NULL And text is reversing, why??? |
|||
19 Jan 2015, 20:30 |
|
JohnFound 19 Jan 2015, 21:32
Use OllyDbg and you will see where you code crashes.
And what is reversing? |
|||
19 Jan 2015, 21:32 |
|
l_inc 19 Jan 2015, 21:34
MIHIP
Because you don't write a single line of code yourself, but just loiter around the Internet and cadge code snippets: demotivator 1 demotivator 2 _________________ Faith is a superposition of knowledge and fallacy |
|||
19 Jan 2015, 21:34 |
|
bitshifter 19 Jan 2015, 21:35
- reads file I.TXT then writes to file: O.TXT
- opens only 1 file at a time - add own munge code... Code: format pe gui 4.0 entry start include 'win32ax.inc' section '.code' code readable executable start: invoke CreateFile,"I.TXT",GENERIC_READ,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL mov [hInputFile],eax invoke GetFileSize,[hInputFile],NULL mov [dwFileSize],eax invoke LocalAlloc,LPTR,[dwFileSize] mov [lpBuffer],eax invoke ReadFile,[hInputFile],[lpBuffer],[dwFileSize],dwBytesRead,NULL invoke CloseHandle,[hInputFile] ;munge: ... invoke CreateFile,"O.TXT",GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL mov [hOutputFile],eax invoke WriteFile,[hOutputFile],[lpBuffer],[dwFileSize],dwBytesWritten,NULL invoke CloseHandle,[hOutputFile] invoke LocalFree,[lpBuffer] invoke ExitProcess,NULL section '.data' data readable writable hInputFile dd 0 hOutputFile dd 0 dwFileSize dd 0 dwBytesRead dd 0 dwBytesWritten dd 0 lpBuffer dd 0 section '.idata' import data readable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
19 Jan 2015, 21:35 |
|
bitshifter 19 Jan 2015, 21:45
for a simple xor encryption you could munge something like so...
Code: mov ecx,[dwFileSize] mov esi,[lpBuffer] mov edi,esi munge: lodsb xor al,MAGIC stosb loop munge _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
19 Jan 2015, 21:45 |
|
l_inc 19 Jan 2015, 22:16
bitshifter
Do you realize that you've just been fooled by a mediocre beggar? _________________ Faith is a superposition of knowledge and fallacy |
|||
19 Jan 2015, 22:16 |
|
bitshifter 19 Jan 2015, 23:28
sometimes i feed the beggars when im bored...
|
|||
19 Jan 2015, 23:28 |
|
l_inc 20 Jan 2015, 00:35
bitshifter
Well, then I probably just didn't achieve your level of tolerance. I do that too, but I'm much more discriminating. Otherwise I'd feel like fostering a wrong kind of personal qualities. _________________ Faith is a superposition of knowledge and fallacy |
|||
20 Jan 2015, 00:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.