beta.blog

FASM: Write File

by on Feb.20, 2011, under Programming

The example code below will create and write text into a new file. In order to use WriteFile in flat assembler you either have to include ‘WIN32AX.INC’ or handle the imports from kernel32.dll manually. I’ve used the shorter version and included win32ax.in. This sample code should work on all operating systems using the Win32 API:

format pe console 4.0
include 'WIN32AX.INC'

.data
 buf db 'TEST'
 bufsize = $ - buf
 byteswritten dd ?
.code
 main:
 invoke  CreateFile, 'test.txt', GENERIC_WRITE, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0
 invoke  WriteFile, eax, buf, bufsize, byteswritten, 0
 invoke  ExitProcess, 0

.end main

If the file already exists, it won’t get deleted, but it will be simply overwritten.


4 Comments for this entry

  • Demelo2260

    hey there did you spend money for this wordpress theme you are utilizing or did you to get it at no cost somewhere and in that case might you please let me know exactly where cheers

  • Bailey Feist

    I need to make the extra effort for that work you earn on paper within these text. I’m hoping the identical finest focus on your behalf sometime soon also. I loved your look I may check out your feed please keep posting!

  • Futrell

    F*ckin’ amazing issues here. I’m very happy to peer your post. Thanks a lot and i’m looking ahead to contact you. Will you please drop me a e-mail?

  • Manire

    Good blog with some intriguing information. I will be back.

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!