1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
int recvDll(SOCKET s)
{
int file_size;
char fileLength[50] = "";
FILE *fp;
int bytes_recieved, bytes_sent, bytes_written;
int recs = recv(s, fileLength, 32, 0);
fileLength[recs] = '\0';
file_size = atoi(fileLength);
fp = fopen("testrecv.dll", "wb");
printf("[+] Size of recieved DLL: %d\n", file_size);
while(file_size > 0)
{
printf("filesize: %d\n", file_size);
char buf[512];
if(file_size >= 512)
{
bytes_recieved = recv(s, buf, 512, 0);
fwrite(buf, 512, 1, fp);
} else {
printf("x: %d\n", file_size);
bytes_recieved = recv(s, buf, file_size, 0);
buf[file_size] = '\0';
fwrite(buf, file_size, 1, fp);
}
file_size -= bytes_recieved;
}
fclose(fp);
return 0;
}
|