flat assembler
Message board for the users of flat assembler.

Index > Windows > Win Sockets - undefined symbol?

Author
Thread Post new topic Reply to topic
lukus001



Joined: 26 Jan 2013
Posts: 2
lukus001 12 Feb 2013, 14:21
Hi all,

I've been trying to get into FASM recently but am currently stuck on "undefined symbol WSAStartup" among the various other pitfalls.



Code:
format PE64 console
entry start


                ;Include list,
                include 'D:\fasm\include\win64w.inc'
                include 'D:\fasm\include\equates\WSOCK32.inc'
                include 'D:\fasm\include\api\WSOCK32.inc'
                include 'D:\fasm\include\pcount\WSOCK32.inc'
                include 'D:\fasm\include\api\user32.inc'
                ;Code section,



                section '.code' code readable executable

                start:

                invoke  WSAStartup, word 0x0202, qword [Socket_WSADATA]

                ;should test if zero, otherwise error
                invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
                mov [Socket_ID], rax


                invoke  getaddrinfoW, , [Login_server], ,[Socket_ppResult]
                mov ebx, [Socket_ppResult]
                mov ebx, [ebx+32]
                mov [Socket_sockaddr_in.sin_addr], ebx
                invoke freeaddrinfow, socket_ppResult

                invoke  connect, Socket_ID, [Socket_sock_addr], 16



                section '.data'

                Login_Server db "http://", 0

                section '.bss' data readable writeable

                Socket_ID                rq                  1
                Socket_WSADATA           WSADATA             ?
                Socket_sockaddr_in       sockaddr_in           AF_INET, 3308,
                Sock_ppResult            rq                  1
                PVP_server_IP            rd                  1








                                           

So, I am not too sure what I am supposed to be doing to make that invoke valid? (I'm sure there will be more errors to follow too) - I've had to add size references in like "word 0x0202" and tweak stuff around just to get rid of errors :S, I'm not even sure if anything in there is correct now :/

The various includes which come with Fasm is nice, but now it means I have no clue why WSAStartup is throwing an error as I can see it in the includes... plus, I had to define an extra structure with one of the fields being size_t which has no real conclusive size other than "it varies to the highest values needed".. or something a long those lines so "WSADATA" could have the wrong size slapped in the middle of it...

Any help appreciated.
Post 12 Feb 2013, 14:21
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 12 Feb 2013, 15:48
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:33; edited 1 time in total
Post 12 Feb 2013, 15:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 Feb 2013, 17:28
lukus001: You have to include the import section into your source. The APIs are only defined when they are placed into the import section.

Also, in Windows 64-bit you shouldn't push a word sized parameter onto the stack. All API parameters must be qword sized.
Post 12 Feb 2013, 17:28
View user's profile Send private message Visit poster's website Reply with quote
lukus001



Joined: 26 Jan 2013
Posts: 2
lukus001 13 Feb 2013, 09:06
Thanks for the replies guys,

Revolution - I added the import but it's gone straight back to WSAStartup being an undefined symbol :s
Post 13 Feb 2013, 09:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 13 Feb 2013, 09:27
You must define the import section into the exe, not just the definition of WSAStartup. None of your DLL linking can be done without an import section.

See the examples files in the fasm zip file for how to make a valid exe that will compile.
Post 13 Feb 2013, 09:27
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.