flat assembler
Message board for the users of flat assembler.

Index > Windows > Some Winsock Functions Questions..

Goto page Previous  1, 2, 3, 4
Thread Post new topic Reply to topic

Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole 13 Nov 2010, 18:19
Of course, we can go lower level too.

Here is the same example using WriteConsoleA

This example doesn't use C at all, and it should be able to print anything. Including binary data

format PE console 4.0 

include 'WIN32AX.INC'  

entry main  

CR EQU 0x0D 
LF EQU 0x0A 

section '.data' data readable writeable 

        hSock dd ? 
  hStdout dd ?
        wsaData WSADATA  
        saddr sockaddr_in  
        sizeof.saddr = $ - saddr  
        saddrlen dd sizeof.sockaddr_in 
        szIP db "", 0      
        send_http_request db "GET / HTTP/1.1",CR,LF,"Host: www.w3.org",CR,LF,"Connection: close",CR,LF,CR,LF        
        sizeof.send_http_request = $ - send_http_request
        cbuf rb 1024                
section '.text' code readable executable  

proc main          
    invoke GetStdHandle, STD_OUTPUT_HANDLE
      mov [hStdout], eax
        invoke WSAStartup, 0202h, wsaData          
        invoke socket, AF_INET, SOCK_STREAM, 0  
        mov [hSock], eax  
        mov [saddr.sin_family], AF_INET  
        invoke inet_addr, szIP 
        mov [saddr.sin_addr], eax         
        invoke htons, 80 
        mov [saddr.sin_port], ax         
        invoke connect, [hSock], saddr, sizeof.sockaddr_in 
        invoke send, [hSock], send_http_request, sizeof.send_http_request, 0                      
        invoke recv, [hSock], cbuf, 1024, 0 
        cmp eax, 0 
        jle end_recv_loop         
   invoke WriteConsoleA, [hStdout], cbuf, eax, 0, 0
        jmp recv_loop 
        invoke closesocket, [hSock]  
 invoke CloseHandle, [hStdout] 
        invoke WSACleanup                 
        invoke ExitProcess, 0 

section '.idata' import data readable  

library kernel32,'kernel32.dll',\ 

include 'API\KERNEL32.INC'  

import ws2_32, WSAStartup, 'WSAStartup',\ 
        WSACleanup, 'WSACleanup',\ 
        socket, 'socket',\ 
        htons, 'htons',\         
        recv, 'recv',\ 
        closesocket, 'closesocket',\ 

section '.reloc' fixups data discardable
Post 13 Nov 2010, 18:19
View user's profile Send private message Reply with quote

Joined: 03 Sep 2010
Posts: 1046
Overflowz 14 Nov 2010, 10:34
Oh I know that Smile) All I wanted is here now and I'll learn them as soon as I can. 1 problem now what I've got is make simple chat but It'll be for me like exercise. Thank you all Smile

P.S drobole, can you check your PM ?
Post 14 Nov 2010, 10:34
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, 3, 4

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