Created
May 7, 2017 09:37
-
-
Save dentmaged/0029af7cfc7e85313276a186fdb48651 to your computer and use it in GitHub Desktop.
C++ file hash changer for macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <fstream> | |
| #include <sys/stat.h> | |
| using namespace std; | |
| void gen_random(char *s, const int len) { | |
| srand(static_cast<unsigned int>(time(NULL) * time(NULL))); | |
| static const char letters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |
| for (int i = 0; i < len; ++i) { | |
| s[i] = letters[rand() % (sizeof(letters) - 1)]; | |
| } | |
| s[len] = 0; | |
| } | |
| int main(int argc, const char * argv[]) { | |
| char *new_name = new char[5]; | |
| char *extra_byte = new char[5]; | |
| gen_random(new_name, 5); | |
| gen_random(extra_byte, 1); | |
| ifstream src(argv[0], ios::binary); | |
| ofstream dst(new_name, ios::binary); | |
| chmod(new_name, S_IRWXU); | |
| dst << src.rdbuf(); | |
| dst << extra_byte; | |
| dst.close(); | |
| src.close(); | |
| remove(argv[0]); | |
| cout << "Hello, World!\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment