flat assembler
Message board for the users of flat assembler.

Index > Windows > me again, file functions

Author
Thread Post new topic Reply to topic
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
hey, i hav always liked file functions like in php and stuff but in assembly im not exactly getting it or somthing.

just 4 fun im trying to make a program that creates a file and copies a file.
the final thing i'd like it to be able to be told my the user wat to name the file and wat is in it.
but i can hardly create a file, i hav looked down through posts and found some info, but not enough. and hav been looking through the kernel32.inc.
like CreateFile,\
but i just dont get the "syntax" thing, like how to use it, i picked up this code from a post and changed it a bit:

Code:

include 'win32ax.inc'

.code

  start:
          invoke  CreateFile,echo,GENERIC_WRITE,\
          FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0

invoke ExitProcess,0

.end start

echo db 'G:\Hey.txt',0 
    


could som1 explain it?
how do you define the contents of the file?
how do you copy a file?


thanks!
sry to bother again
Post 14 May 2009, 15:48
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
Dreamz wrote:
how do you define the contents of the file?
With WriteFile.
Dreamz wrote:
how do you copy a file?
Erm, with a function named CopyFile.
Post 14 May 2009, 15:52
View user's profile Send private message Visit poster's website Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
well i mean im almost a complete beginner, could you give an example, like:
Code:


include 'win32ax.inc'

.code

  start:
          invoke  CreateFile,echo,GENERIC_WRITE,\
          FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0

invoke ExitProcess,0

.end start

echo db 'G:\Hey.txt',0 
    


or

Code:
          invoke  CreateFile,echo,GENERIC_WRITE,\
          FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0  
...
...
echo db 'G:\Hey.txt',0  
    


that is if its rly big
thanks!
Post 14 May 2009, 15:59
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Open a file, get its size, allocate a buffer and read in the data.
*takes breath*
Close the file, create a new file, write the data, close the file.

For reading a file into a dynamic buffer study my texture loader.
http://board.flatassembler.net/topic.php?t=9885

_________________
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.
Post 15 May 2009, 02:14
View user's profile Send private message Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
To copy a file, you need to:
1. open the source file,
2. open the destination file
3. read the contents of source file into a buffer
4. write the contents of the buffer to the destination file

see attached exampled asm


Description:
Download
Filename: filter.asm
Filesize: 5.62 KB
Downloaded: 26 Time(s)

Post 16 Jun 2009, 10:29
View user's profile Send private message Reply with quote
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo
this is the "begginer" example:

Code:
include 'include\win32ax.inc'

.code

start:  invoke CreateFile, fname, GENERIC_WRITE, FILE_SHARE_READ,\
        0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0

        mov [fhandle], eax

        invoke WriteFile, eax, fname, 10, garbage, 0
        invoke CloseHandle, fhandle

        invoke ExitProcess, 0

.end start

fname db 'HelloWorld.txt',0
fhandle dd 0
garbage dd 0 ;necessary    
    


cya
Post 17 Jun 2009, 16:25
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.