trying to tranfer a file using netcat as a reciever
but the file is never recieved..can anyone figure out what im doing wrong in the loop

IPAddress  db "localhost",0
ThePort    db "6300",0
szFile      db "winsocksend.asm",0 
wsadata        WSADATA <?>
sin            sockaddr_in <?>
sock          dd ?
dwThreadID    DWORD ?
hFileSize      DWORD ?
hFile          DWORD ?
dwPort        DWORD ?
dwRead        DWORD ?
Fileptr        DWORD ?
buffer      db 1024 dup (?)
  invoke CreateFile,addr szFile, GENERIC_READ, 0, NULL,OPEN_EXISTING, 0, NULL  ;open our file
    mov , eax
    inc eax
    jz err
  invoke GetFileSize, , NULL                                            ;get its filesize so we know how much data to send
      mov hFileSize, eax                                                          ;save size to our handle
        inc    eax                                                                ;test it to see if file fuckedup
;      jz err
  invoke WSAStartup, 101h, offset wsadata                                          ;lets start winsock bitch
          cmp eax, 0
          jne start 
  invoke socket,AF_INET,SOCK_STREAM,0                                            ;get a socket   
      mov sock,eax
      mov sin.sin_family, AF_INET
  invoke atodw, addr ThePort                                                    ;change the port string to dw
      mov dwPort, eax
  invoke htons, dwPort                                                          ;open the port
      mov sin.sin_port,ax         
  invoke gethostbyname, addr IPAddress                                          ;convert the hostname to ip addy
      mov eax,
      mov eax,
      mov eax,
  mov sin.sin_addr, eax
  invoke connect,sock,addr sin,sizeof sin                                      ;connect to ip on the port
            cmp eax, 0
            jne err
  mov Fileptr, 0
invoke SetFilePointer, hFile, Fileptr, 0, FILE_BEGIN
invoke ReadFile, hFile, addr buffer, hFileSize, addr dwRead, NULL
test eax, eax
jz @@done
invoke send, sock, addr buffer, eax, 0
add Fileptr, sizeof buffer             
jnz @@loop           
invoke CloseHandle, hFile 
  invoke  CloseHandle, hFileSize
  invoke WSACleanup 
invoke ExitProcess,0
end start
Posted on 2005-07-01 00:52:52 by illwill
Send doesn't always send what you expected.
Hint : always check api return values :)
Posted on 2005-07-01 03:53:37 by Homer
sorry for my bad english

there is a loop,
by modifying the routine of the reading the file you can transfert with nc
call lire
INVOKE    lstrlen, addr buff
INVOKE    send, hSock,addr buff, eax, NULL
    mov hFile,eax     
    invoke ReadFile,hFile ,ADDR buff,800,ADDR fwritten,0 ;; 800 you ca add routine to check lenft of string...
    invoke CloseHandle,hFile

Posted on 2005-07-16 13:25:06 by massine
massine, that won't work particularly well for binary files... lstrlen is a no-no in that case. And why use it anyway, since you get the received amount from ReadFile?
Posted on 2005-07-16 15:15:29 by f0dder