flat assembler
Message board for the users of flat assembler.

Index > Windows > Windows 32 Program Issue (Easy)

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Hello,

Here is another small sample to experiment drewtoby.
Includes a handful of functions.

GetProcessHeap
CreateFile
GetFileSize
HeapAlloc
ReadFile
CloseHandle
HeapFree

Code:
            format pe console 4.0
            entry main

            include "win32ax.inc"

section ".idata" import data readable writeable

            library\
                kernel32, "KERNEL32.DLL",\
                user32, "USER32.DLL"

            include "\api\kernel32.inc"
            include "\api\user32.inc"


section ".code" code readable executable
main:

            stdcall loadfile, "somefile.txt"
            .if eax = 0
                ; api failed
                ; handle error
                ;
            .elseif eax = -1
                ; file not found
                ; handle error
                ;
            .else
                ; success
                ; EAX points to buffer
                ;
            .endif

            invoke ExitProcess, 0



proc loadfile uses ecx edx, path:dword

            local size dd 0
            local pfile dd 0
            local pmem dd 0
            local hheap dd 0
            local dtmp1 dd 0

            invoke GetProcessHeap
            test eax, eax
            jz .error

            mov [hheap], eax

            invoke CreateFile, [path], GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0
            cmp eax, -1
            je .notfound

            mov [pfile], eax

            invoke GetFileSize, [pfile], 0
            cmp eax, -1
            je .error

            mov [size], eax
            add eax, 100

            invoke HeapAlloc, [hheap],  HEAP_ZERO_MEMORY, eax
            test eax, eax
            jz .error

            mov [pmem], eax

            invoke ReadFile, [pfile], eax, [size], addr dtmp1, 0
            test eax, eax
            jz .error

            invoke CloseHandle, [pfile]
            test eax, eax
            jz .error

            mov eax, [pmem]
            ret

                .notfound:
            mov eax, -1
            ret

                .error:
            .if [pfile]
                invoke CloseHandle, [pfile]
            .endif

            .if [pmem]
                invoke HeapFree, [hheap], 0, [pmem]
            .endif

            xor eax, eax
            ret
endp  
    


Last edited by Picnic on 08 Mar 2012, 22:14; edited 1 time in total
Post 08 Mar 2012, 22:06
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
drewtoby, why not to simply read the manual of FASMW? I am sure, after that a lot of questions will be answered.
Post 08 Mar 2012, 22:12
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
drewtoby



Joined: 05 Mar 2012
Posts: 19
drewtoby
^ Will do to. I was looking through it, an learned about regesters there. I learned C and PHP mostly through trial and error though, so I thought I could do so with assembly =).

I'll be working with the examples and get back to the manual. thanks everyone!
Post 08 Mar 2012, 22:26
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
These functions already imported -- see the bottom of the code I posted.
There is a KERNEL32 reference there.
Post 08 Mar 2012, 23:02
View user's profile Send private message Send e-mail Reply with quote
drewtoby



Joined: 05 Mar 2012
Posts: 19
drewtoby
Okay, am working with it Smile
Post 09 Mar 2012, 02:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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.