flat assembler
Message board for the users of flat assembler.

Index > Windows > Don't understand compilation error message

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
Hi,

I can't assemble the code below and the error message isn't helping me.

The message fasm is giving is

Quote:

flat assembler version 1.71.39 (1048576 kilobytes memory)
D:\Program Files (x86)\Fasm\INCLUDE\api\Kernel32.inc [4]:
import kernel32,\
D:\Program Files (x86)\Fasm\INCLUDE\macro/import64.inc [50] import [24]:
label dq RVA _label
error: symbol already defined.


Any ideas?

Thanks

magicĀ²

Code:
format PE64 console 
entry start 

include '%fasminc%\win64ax.inc' 

macro writeAndSort
{
        ; just place holder at the minute
        xor     rax, rax
}

macro calculate
{
        xor     rdx, rdx
        mov     rax, r12
        push    rax
        mul     rax     
        mov     rcx, rax                
        pop     rax
        shl     rax, 1
        mul     r13
        add     rcx, rax                
        mov     rax, r13
        mul     rax
        sub     rcx, rax                
        mov     [r14], r12
        mov     [r15], r13
        mov     [rbp], rcx
        add     r14, 8
        add     r15, 8
        add     rbp, 8
        dec     rbp
        jnz     @f
        call    WriteFile
    @@:
}

section '.text' code readable executable 

    start: 
        sub     rsp, 08
        mov     [sort], FALSE           
        mov     r12, 9999998            
        mov     r13, 1                  
        mov     rbx, 1000000            
        mov     r14, mList
        mov     r15, nList
        mov     rbp, highList
    .n6:
        calculate
        add     r13, 2
        cmp     r13, r12
        jb      .n6
    .m1:
        cmp     [sort], TRUE
        je      @f
        mov     [sort], TRUE            
        invoke  CreateFile, sortedmFile, GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_SEQUENTIAL_SCAN, NULL
        mov     [sortedmHnd], rax
        mov     rdi, r12
        sub     rdi, mList
        invoke  WriteFile, [sortedmHnd], mList, rdi, bytesWritten, NULL
        invoke  CloseHandle, [sortedmHnd]
        invoke  CreateFile, sortednFile, GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_SEQUENTIAL_SCAN, NULL
        mov     [sortednHnd], rax
        mov     rdi, r13
        sub     rdi, nList
        invoke  WriteFile, [sortednHnd], nList, rdi, bytesWritten, NULL
        invoke  CloseHandle, [sortednHnd]
        invoke  CreateFile, sortedhighFile, GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_SEQUENTIAL_SCAN, NULL
        mov     [sortedhighHnd], rax
        mov     rdi, r12
        sub     rdi, highList
        invoke  WriteFile, [sortedhighHnd], mList, rdi, bytesWritten, NULL
        invoke  CloseHandle, [sortedhighHnd]
        mov     rbx, 1000000
        mov     r14, mList
        mov     r15, nList
        mov     rbp, highList
        jmp     .m12
    @@:
        writeAndSort
    .m12:
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 2
    .n1:
        calculate
        add     r13, 2
        cmp     r13, r12
        ja      .m2
        calculate
        add     r13, 4
        cmp     r13, r12
        jb      .n1
    .m2:
        writeAndSort
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 1
    .n2:
        calculate
        add     r13, 2
        cmp     r13, r12
        jb      .n2
    .m3:
        writeAndSort
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 2
    .n3:
        calculate
        add     r13, 2
        cmp     r13, r12
        jb      .n3
    .m4:
        writeAndSort
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 1
    .n4:
        calculate
        add     r13, 4
        cmp     r13, r12
        ja      .m5
        calculate
        add     r13, 2
        cmp     r13, r12
        jb      .n4
    .m5:
        writeAndSort
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 2
    .n5:
        calculate
        add     r13, 2
        cmp     r13, r12
        jb      .n5
    .m6:
        writeAndSort
        inc     r12
        cmp     r12, [max_m]
        ja      .finished
        mov     r13, 1
        jmp     .n6

WriteFile:
        ret


    .finished:
        invoke  ExitProcess, 0

;************************************************************************************************** 
section '.data' data readable writeable 

align 8

        mFile           db "e:\m.dat", 00
        nFile           db "e:\n.dat", 00
        highFile        db "e:\high.dat", 00
        sortedmFile     db "e:\sortedmFile.dat", 00
        sortednFile     db "e:\sortednFile.dat", 00
        sortedhighFile  db "e:\sortedhighFile.dat", 00
        tmpFile         db "e:\tmp.dat", 00
align 8
        max_m           dq 3037000499
        sort            dq ?
        mHnd            dq ?
        nHnd            dq ?
        highHnd         dq ?
        sortedmHnd      dq ?
        sortednHnd      dq ?
        sortedhighHnd   dq ?
        tmpHnd          dq ?

        mList           dq 1000000 dup ?
        nList           dq 1000000 dup ?
        highList        dq 1000000 dup ?
        
;************************************************************************************************** 
section '.idata' import data readable writeable 

    library kernel32,'KERNEL32.DLL',\ 
            user32,  'USER32.DLL',\
            msvcrt,  'msvcrt.dll'

    include '%fasminc%\api\Kernel32.inc'  
    include '%fasminc%\api\User32.inc'  

    import msvcrt,\ 
            fopen,      'fopen',\ 
            fclose,     'fclose',\ 
            fwrite,     'fwrite',\
            fread,      'fread'

    
Post 02 Oct 2015, 20:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17248
Location: In your JS exploiting you and your system
revolution
When you include win64ax you are already defining the imports. So when you place the imports again with "include '%fasminc%\api\Kernel32.inc'
" then you get an error for symbol already defined.
Post 03 Oct 2015, 08:18
View user's profile Send private message Visit poster's website Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
revolution wrote:
When you include win64ax you are already defining the imports. So when you place the imports again with "include '%fasminc%\api\Kernel32.inc'
" then you get an error for symbol already defined.


Hi revolution,

I have always used

Code:
format PE64 console 
entry start 

include '%fasminc%\win64ax.inc' 

section '.text' code readable executable 

    start: 
code in here

section '.idata' import data readable writeable 

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

    include '%fasminc%\api\Kernel32.inc'  
    include '%fasminc%\api\User32.inc'  
    

and have never had this issue?

I tried commenting out "include '%fasminc%\api\Kernel32.inc'"
but fasm rightly complains that CreateFile hasn't been defined.

I did just find the problem though. I was going to include a proc for writing to a file and stupidly called it WriteFile (already defined in win API) instead of my usual writeFile.

Thanks

magicĀ²
Post 03 Oct 2015, 09:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17248
Location: In your JS exploiting you and your system
revolution
Heh, okay that'll teach me to simply read and not test the code.
Post 03 Oct 2015, 11:56
View user's profile Send private message Visit poster's website Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
revolution wrote:
Heh, okay that'll teach me to simply read and not test the code.


Quote:
When all else fails, read the source
Laughing
Post 03 Oct 2015, 16:20
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.

Powered by rwasa.