Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- unsigned char *CO_File;
- DWORD size;
- DWORD LoadFileToMem(LPCWSTR FilePath)
- {
- HANDLE hfile;
- DWORD dw;
- hfile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hfile == INVALID_HANDLE_VALUE)
- {
- MessageBox(NULL, L"Error when file Handling", L"ERROR", 0);
- CloseHandle(hfile);
- return 0;
- }
- size = GetFileSize(hfile, NULL);
- if (size == INVALID_FILE_SIZE) { MessageBox(NULL, L"Size of file not invalid", L"ERROR", 0);
- CloseHandle(hfile);
- return 0;
- }
- if ((CO_File = (unsigned char*)VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)) == NULL)
- {
- MessageBox(NULL, L"Can't allocate a memory for the file", L"ERROR", 0);
- CloseHandle(hfile);
- return 0;
- }
- if (!ReadFile(hfile, (LPVOID)CO_File, size, &dw, NULL))
- {
- MessageBox(NULL, L"Can't reading the file", L"ERROR", 0);
- CloseHandle(hfile);
- return 0;
- }
- CloseHandle(hfile);
- return 0;
- }
- int Xor(LPSTR key)
- {
- int j = 0;
- for (int i = 0 ; i<size ; i++)
- {
- CO_File[i] = CO_File[i] ^ key[j];
- j++;
- if (j== strlen(key))
- {
- j = 0;
- }
- }
- return 0;
- }
- int WriteToFile()
- {
- DWORD dw;
- HANDLE Ofile;
- Ofile = CreateFile(L"C:\\Users\\zika\\Desktop\\test\\2.exe",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
- WriteFile(Ofile,CO_File,size,&dw,NULL);
- CloseHandle(Ofile);
- return 1;
- }
- int main()
- {
- LoadFileToMem(L"C:\\Users\\zika\\Desktop\\test\\1.exe");
- Xor("zeraya");
- WriteToFile();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement