• Welcome to Valhalla Legends Archive.
 

[FASM] Error: Symbol already defined

Started by Yegg, November 09, 2006, 05:09 PM

Previous topic - Next topic

Yegg

I started really studying x86 asm recently and decided I would use FASM. I tried writing a basic console hello world application. I'll start by showing my code:

format PE console
entry start

include 'include\win32ax.inc'

section '.code' code readable executable
  start:
        invoke AllocConsole
        invoke GetStdHandle, STD_OUTPUT_HANDLE
        mov [_outhandle], eax
        invoke GetStdHandle, STD_INPUT_HANDLE
        mov [_inhandle], eax
        invoke WriteConsole, [_outhandle], _msg, 13, _written, 0
        invoke ReadConsole, [_inhandle], _char, 1, _read, 0
  finish:
        invoke ExitProcess, 0

section '.data' data readable writeable
  _outhandle    dd   ?
  _inhandle     dd   ?
  _written      dd   ?
  _read         dd   ?
  _char         db   ?
  _msg          db   'Hello, world.'

section 'idata' import data readable writeable
  library kernel, 'KERNEL32.DLL'

  import kernel,\
         AllocConsole, 'AllocConsole',\
         GetStdHandle, 'GetStdHandle',\
         WriteConsole, 'WriteConsoleA',\
         ReadConsole, 'ReadConsoleA',\
         ExitProcess, 'ExitProcess'


What happens is when I try to assemble this code, I get the following error message:

QuoteError: symbol already defined.

It tells me that the error occured on the following instruction:

WriteConsole dd RVA _label?000067F

First off, I really don't know what the above (the last text in the code tags) means. When the error dialog shows up, the following code is highlighted:

import kernel,\
         AllocConsole, 'AllocConsole',\
         GetStdHandle, 'GetStdHandle',\
         WriteConsole, 'WriteConsoleA',\
         ReadConsole, 'ReadConsoleA',\
         ExitProcess, 'ExitProcess'


The above code is apparently the source of the error, located inside my program's source code (hello_world.asm). However, there are two sources of error. My source code (hello_world.asm) and import32.inc. The line of import32.inc which contains the source of error is line 45 which contains the following code:

label dd RVA _label

I'm not entirely sure if the above is necessary for you to know or not.

Anyways, I'm not really sure what causes this error. If I decide not to define WriteConsole, I get the same type of error message only for ReadConsole instead. If I remove the definition for ReadConsole, it tells me that WriteConsole (and eventually ReadConsole) is not defined.

I would greatly appreciate help with this issue. I'd be glad to provide more information if that is necessary.

Update: I changed a few things. The program now can be compiled into a normal executable, however it will not run so it seems. The few things I changed were:

I changed
include 'include\win32ax.inc'
to
include 'include\win32a.inc'
I don't think this had any real effect.

I noticed a small problem where I wrote
section 'idata' import data readable writeable
I left out the period (.) after the first apostrophe in 'idata'. This was changed into '.idata'.

I changed the import data section's code to:

section '.idata' import data readable writeable
  library kernel, 'KERNEL32.DLL'

  include 'include\api\kernel32.inc'


This seems to be the main cause for removing the error messages I was receiving earlier. I am still at work trying to get the application to output text to the console. I'll keep this post updated, and I'm still looking for any possible help.

Kp

Now that you have it assembled and presumably runnable, run it under a debugger to find out what happens when it calls WriteConsole.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Yegg

Quote from: Kp on November 09, 2006, 08:07 PM
Now that you have it assembled and presumably runnable, run it under a debugger to find out what happens when it calls WriteConsole.

Thanks for the help. I was getting ready to go ahead and try this, however I started to try and figure out another problem I was working on. The next day I assembled this same code and the program worked just fine. I'm still unsure of what caused it to fail the first time.