Advertisement
zeraya

Untitled

Oct 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include<windows.h>
  2. unsigned char *CO_File;
  3. DWORD size;
  4. DWORD LoadFileToMem(LPCWSTR FilePath)
  5. {
  6. HANDLE hfile;
  7. DWORD dw;
  8.  
  9. hfile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  10. if (hfile == INVALID_HANDLE_VALUE)
  11. {
  12. MessageBox(NULL, L"Error when file Handling", L"ERROR", 0);
  13. CloseHandle(hfile);
  14. return 0;
  15. }
  16.  
  17. size = GetFileSize(hfile, NULL);
  18. if (size == INVALID_FILE_SIZE) { MessageBox(NULL, L"Size of file not invalid", L"ERROR", 0);
  19. CloseHandle(hfile);
  20. return 0;
  21. }
  22. if ((CO_File = (unsigned char*)VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)) == NULL)
  23. {
  24. MessageBox(NULL, L"Can't allocate a memory for the file", L"ERROR", 0);
  25. CloseHandle(hfile);
  26. return 0;
  27. }
  28. if (!ReadFile(hfile, (LPVOID)CO_File, size, &dw, NULL))
  29. {
  30. MessageBox(NULL, L"Can't reading the file", L"ERROR", 0);
  31. CloseHandle(hfile);
  32. return 0;
  33. }
  34. CloseHandle(hfile);
  35. return 0;
  36. }
  37. int Xor(LPSTR key)
  38. {
  39. int j = 0;
  40. for (int i = 0 ; i<size ; i++)
  41. {
  42. CO_File[i] = CO_File[i] ^ key[j];
  43. j++;
  44. if (j== strlen(key))
  45. {
  46. j = 0;
  47. }
  48. }
  49. return 0;
  50. }
  51. int WriteToFile()
  52. {
  53. DWORD dw;
  54. HANDLE Ofile;
  55. Ofile = CreateFile(L"C:\\Users\\zika\\Desktop\\test\\2.exe",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  56. WriteFile(Ofile,CO_File,size,&dw,NULL);
  57. CloseHandle(Ofile);
  58. return 1;
  59. }
  60. int main()
  61. {
  62. LoadFileToMem(L"C:\\Users\\zika\\Desktop\\test\\1.exe");
  63. Xor("zeraya");
  64. WriteToFile();
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement